Click or drag to resize

UseOfficeCExcelOptions Class

Allows to specify some Excel options (sheet numbers, how to fit a sheet on page) for converting.
Inheritance Hierarchy
SystemObject
  SautinSoftUseOfficeCExcelOptions

Namespace: SautinSoft
Assembly: UseOffice (in UseOffice.dll) Version: 2024.12.12
Syntax
public class CExcelOptions

The UseOfficeCExcelOptions type exposes the following members.

Constructors
 NameDescription
Public methodCode exampleUseOfficeCExcelOptions Creates object of class CSheet. By default all sheets from workbook will be converted
Top
Properties
 NameDescription
Public propertyFitSheetToPage Sets or gets to fit each sheet to page size.Thus, an each Excel sheet will take an one page.
Top
Methods
 NameDescription
Public methodCode exampleAllSheets Convert all sheets from workbook
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Public methodCode exampleSheetNames Allows to specify custom sheets to convert by their names
Public methodSheetNumber Allows to set custom sheet for converting by its number
Public methodCode exampleSheetNumbers Allows to specify custom sheets to convert by their numbers
Public methodCode exampleSheetRange Allows to specify custom sheets from X to Y
Public methodToStringReturns a string that represents the current object.
(Inherited from Object)
Top
Example
How to convert custom Excel sheets to a PDF document in C#
using System;
using System.IO;
using System.Collections;

namespace Sample
{
    class Test
    {        
        static void Main(string[] args)
        {
            // Before starting, we recommend to get a free 100-day key:
            // https://sautinsoft.com/start-for-free/

            // Apply the key here:
            // UseOffice.SetLicense("...");

            // Convert custom Excel sheets to PDF.
            // If you need more information about UseOffice .Net email us at:
            // support@sautinsoft.com.            

            SautinSoft.UseOffice u = new SautinSoft.UseOffice();

            string inpFile = Path.GetFullPath(@"..\..\..\..\..\..\TestFiles\example.xlsx");            
            string outFile = Path.GetFullPath("Result.pdf");

            // Prepare UseOffice .Net, load MS Excel in memory.
            int ret = u.InitExcel();

            // Return values:
            // 0 - Loading successfully
            // 1 - Can't load MS Excel library in memory

            if (ret == 1)
            {
                Console.WriteLine("Error! Can't load MS Excel library in memory.");
                return;
            }

            // Set to convert only 1st and 3rd sheets.
            u.ExcelOptions.SheetNumbers(new int [] {1,3});

            // Perform the conversion.
            ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.XLSX_to_PDF);

            // Release MS Excel from memory
            u.CloseExcel();

            // 0 - Converting successfully
            // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
            // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
            // 3 - Converting failed, please contact with our Support Team
            // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
            if (ret == 0)
            {
                // Open the result.
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
            }
            else
                Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.");
        }
    }
}
How to convert custom Excel sheets to a PDF document in VB.Net
Imports System
Imports System.IO
Imports System.Collections

Namespace Sample
    Friend Class Test
        Shared Sub Main(ByVal args() As String)
            ' Before starting, we recommend to get a free 100-day key:
            ' https://sautinsoft.com/start-for-free/

            ' Apply the key here:
            ' UseOffice.SetLicense("...");
            ' Convert custom Excel sheets to PDF.
            ' If you need more information about UseOffice .Net email us at:
            ' support@sautinsoft.com.            

            Dim u As New SautinSoft.UseOffice()

            Dim inpFile As String = Path.GetFullPath("..\..\..\..\..\..\TestFiles\example.xlsx")
            Dim outFile As String = Path.GetFullPath("Result.pdf")

            ' Prepare UseOffice .Net, load MS Excel in memory.
            Dim ret As Integer = u.InitExcel()

            ' Return values:
            ' 0 - Loading successfully
            ' 1 - Can't load MS Excel library in memory

            If ret = 1 Then
                Console.WriteLine("Error! Can't load MS Excel library in memory.")
                Return
            End If

            ' Set to convert only 1st and 3rd sheets.
            u.ExcelOptions.SheetNumbers(New Integer() {1, 3})

            ' Perform the conversion.
            ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.XLSX_to_PDF)

            ' Release MS Excel from memory
            u.CloseExcel()

            ' 0 - Converting successfully
            ' 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
            ' 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
            ' 3 - Converting failed, please contact with our Support Team
            ' 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
            If ret = 0 Then
                ' Open the result.
                System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True})
            Else
                Console.WriteLine("Error! Please contact with SautinSoft support: support@sautinsoft.com.")
            End If
        End Sub
    End Class
End Namespace
See Also