Skip to main content

ExcelConverter

Version: 3.0

cete.dynamicpdf.conversion.excelconverter

ExcelConverter​

Defines methods and properties for the ExcelConverter.

public class ExcelConverter
Public Class ExcelConverter

Inheritance: Object → ExcelConverter

Licensing Info​

This class is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Examples​

This example shows how to use ExcelConverter class.

Imports ceTe.DynamicPDF.Conversion

Module Module1

Sub Main()

' create new instance of ExcelConversionOptions.
Dim conversionOptions As ExcelConversionOptions = New ExcelConversionOptions(True)

' Create new instance of Converter by providing suitable parameters.
Dim excelConversion As ExcelConverter = New ExcelConverter("C:\MyDocument.xlsx",conversionOptions)

' Call Convert method to start conversion
excelConversion.Convert("C:\MyOutput.pdf")

End Sub

End Module
using ceTe.DynamicPDF.Conversion;

class MyClass
{
static void Main()
{
// create new instance of ExcelConversionOptions.
ExcelConversionOptions conversionOptions=new ExcelConversionOptions(true);

// Create new instance of Converter by providing suitable parameters.
ExcelConverter excel = new ExcelConverter(@"C:\MyDocument.xlsx",conversionOptions);

//Call Convert method to start conversion
excel.Convert(@"C:\MyOutput.pdf");
}
}

Constructors​

ExcelConverter(Byte[], String)​

Initializes the ExcelConverter ExcelConverter class.

public ExcelConverter(Byte[] inputData, string InputFileName)
Public Sub New (inputData As Byte(), InputFileName As String)

Parameters​

byte array of Excel file as input

Input Excel file name

Licensing Info​

This constructor is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Examples​

This example shows how to use ExcelConverter class with input byte array and inputFile path as parameters.

Imports ceTe.DynamicPDF.Conversion

Module Module1

Sub Main()

'Read all file data to a byte array.
Dim inputData As Byte() = File.ReadAllBytes("C:\MyDocument.xlsx")

' Create new instance of Converter by providing suitable parameters.
Dim excelConversion As ExcelConverter = New ExcelConverter(inputData,"MyDocument.xlsx")

' Call Convert method to start conversion
excelConversion.Convert("C:\MyOutput.pdf")

End Sub

End Module
using ceTe.DynamicPDF.Conversion;

class MyClass
{
static void Main()
{
// Read all file data to a byte array.
byte [] inputData=File.ReadAllBytes("C:\MyDocument.xlsx");

// Create new instance of Converter by providing suitable parameters.
ExcelConverter excel = new ExcelConverter(inputData,"MyDocument.xlsx");

//Call Convert method to start conversion
excel.Convert(@"C:\MyOutput.pdf");
}
}

ExcelConverter(Byte[], String, ExcelConversionOptions)​

Initializes the ExcelConverter ExcelConverter class.

public ExcelConverter(Byte[] inputData, string InputFileName, ExcelConversionOptions conversionOptions)
Public Sub New (inputData As Byte(), InputFileName As String, conversionOptions As ExcelConversionOptions)

Parameters​

byte array of Excel file as input

Input Excel file name

Options to initialize the ConversionOptions property

Licensing Info​

This constructor is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Examples​

This example shows how to use ExcelConverter class with input byte array and inputFile path as parameters.

Imports ceTe.DynamicPDF.Conversion

Module Module1

Sub Main()

' create new instance of ExcelConversionOptions.
Dim conversionOptions As ExcelConversionOptions = New ExcelConversionOptions(True)

'Read all file data to a byte array.
Dim inputData As Byte() = File.ReadAllBytes("C:\MyDocument.xlsx")

' Create new instance of Converter by providing suitable parameters.
Dim excelConversion As ExcelConverter = New ExcelConverter(inputData,"MyDocument.xlsx",conversionOptions)

' Call Convert method to start conversion
excelConversion.Convert("C:\MyOutput.pdf")

End Sub

End Module
using ceTe.DynamicPDF.Conversion;

class MyClass
{
static void Main()
{

// create new instance of ExcelConversionOptions.
ExcelConversionOptions conversionOptions=new ExcelConversionOptions(true);

// create new instance of ExcelConversionOptions.
byte [] inputData=File.ReadAllBytes("C:\MyDocument.xlsx");

// Create new instance of Converter by providing suitable parameters.
ExcelConverter excel = new ExcelConverter(inoutDate,"MyDocument.xlsx",conversionOptions);

//Call Convert method to start conversion
excel.Convert(@"C:\MyOutput.pdf");
}
}

ExcelConverter(String)​

Initializes the ExcelConverter ExcelConverter class.

public ExcelConverter(string inputFilePath)
Public Sub New (inputFilePath As String)

Parameters​

File path of input Excel file.

Licensing Info​

This constructor is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Examples​

This example shows how to use ExcelConverter class with inputFilePath as parameter.

Imports ceTe.DynamicPDF.Conversion

Module Module1

Sub Main()

' Create new instance of Converter by providing suitable parameters.
Dim excelConversion As ExcelConverter = New ExcelConverter("C:\MyDocument.xlsx")

' Call Convert method to start conversion
excelConversion.Convert("C:\MyOutput.pdf")

End Sub

End Module
using ceTe.DynamicPDF.Conversion;

class MyClass
{
static void Main()
{

// Create new instance of Converter by providing suitable parameters.
ExcelConverter excel = new ExcelConverter(@"C:\MyDocument.xlsx");

//Call Convert method to start conversion
excel.Convert(@"C:\MyOutput.pdf");
}
}

ExcelConverter(String, ExcelConversionOptions)​

Initializes the ExcelConverter ExcelConverter class.

public ExcelConverter(string inputFilePath, ExcelConversionOptions conversionOptions)
Public Sub New (inputFilePath As String, conversionOptions As ExcelConversionOptions)

Parameters​

Input Excel file name

Options to initialize the ConversionOptions property

Licensing Info​

This constructor is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Examples​

This example shows how to use ExcelConverter class with inputFile path and conversionOptions as parameter.

Imports ceTe.DynamicPDF.Conversion

Module Module1

Sub Main()

' create new instance of ExcelConversionOptions.
Dim conversionOptions As ExcelConversionOptions = New ExcelConversionOptions(True)

' Create new instance of Converter by providing suitable parameters.
Dim excelConversion As ExcelConverter = New ExcelConverter("C:\MyDocument.xlsx",conversionOptions)

' Call Convert method to start conversion
excelConversion.Convert("C:\MyOutput.pdf")

End Sub

End Module
using ceTe.DynamicPDF.Conversion;

class MyClass
{
static void Main()
{
// create new instance of ExcelConversionOptions.
ExcelConversionOptions conversionOptions=new ExcelConversionOptions(true);

// Create new instance of Converter by providing suitable parameters.
ExcelConverter excel = new ExcelConverter(@"C:\MyDocument.xlsx",conversionOptions);

//Call Convert method to start conversion
excel.Convert(@"C:\MyOutput.pdf");
}
}

Properties​

ConversionOptions​

Gets an instance of ExcelConversionOptions class.

public ExcelConversionOptions ConversionOptions { get; }
Public Property ConversionOptions As ExcelConversionOptions

Property Value​

ExcelConversionOptions

Licensing Info​

This property is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Methods​

Convert()​

Converts Excel file to PDF.

public Byte[] Convert()
Function Convert() As Byte()

Returns​

Outputs converted PDF in a byte array format

Licensing Info​

This method is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Examples​

This example shows how to use convert method with output byte array as return type.

Imports ceTe.DynamicPDF.Conversion

Module Module1

Sub Main()

' Create new instance of Converter by providing suitable parameters.
Dim excelConversion As ExcelConverter = New ExcelConverter("C:\MyDocument.xlsx")

' Call Convert method to start conversion
Dim output As Byte() = excelConversion.Convert()

If (output IsNot Nothing) Then
'save byte array output to a file.
File.WriteAllBytes("C:\MyOutputFile.pdf", output)
End If

End Sub

End Module
using ceTe.DynamicPDF.Conversion;

class MyClass
{
static void Main()
{
// Create new instance of Converter.
ExcelConverter excel = new ExcelConverter(@"C:\MyDocument.xlsx");

//Call Convert method to start conversion
byte []output=excel.Convert();

if(output!=null)
{
//save byte array output to a file.
File.WriteAllBytes("C:\MyOutputFile.pdf",output);
}
}
}

Convert(Byte[])​

Converts Excel to PDF.

public Byte[] Convert(Byte[] pdfToAppendTo)
Function Convert(pdfToAppendTo As Byte()) As Byte()

Parameters​

Contents of PDF in byte array format, to which the current conversion needs to be appended to.

Returns​

Outputs converted PDF in a byte array format

Licensing Info​

This method is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Examples​

This example shows how to use convert method with pdf byte array as parameter and byte array as return type.

Imports ceTe.DynamicPDF.Conversion

Module Module1

Sub Main()

' Create new instance of Converter by providing suitable parameters.
Dim excelConversion As ExcelConverter = New ExcelConverter("C:\MyDocument.xlsx")

' Call Convert method to start conversion
Dim output As Byte() = excelConversion.Convert()

If (output IsNot Nothing) Then
Dim finalOutput As Byte() = excelConversion.Convert(output)
'save byte array output to a file.
File.WriteAllBytes("C:\MyOutputFile.pdf", finalOutput)
End If

End Sub

End Module
using ceTe.DynamicPDF.Conversion;

class MyClass
{
static void Main()
{
// Create new instance of Converter.
ExcelConverter excel = new ExcelConverter(@"C:\MyDocument.xlsx");

//Call Convert method to start conversion
byte []output=excel.Convert();

if(output!=null)
{
byte []finalOutputByte=excel.Convert(output);
//save byte array output to a file.
File.WriteAllBytes("C:\MyOutputFile.pdf",finalOutputByte);
}
}
}

Convert(String)​

Converts Excel file to PDF.

public void Convert(string outputFilePath)
Sub Convert(outputFilePath As String)

Parameters​

File path for output PDF file where it needs to be saved

Licensing Info​

This method is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Examples​

This example shows how to use convert method with outputFilePath as parameter.

Imports ceTe.DynamicPDF.Conversion

Module Module1

Sub Main()

' Create new instance of Converter by providing suitable parameters.
Dim excelConversion As ExcelConverter = New ExcelConverter("C:\MyDocument.xlsx")

' Call Convert method to start conversion
excelConversion.Convert("C:\MyOutput.pdf")

End Sub

End Module
using ceTe.DynamicPDF.Conversion;

class MyClass
{
static void Main()
{
// Create new instance of Converter.
ExcelConverter excel = new ExcelConverter(@"C:\MyDocument.xlsx");

//Call Convert method to start conversion
excel.Convert(@"C:\MyOutput.pdf");
}
}

ConvertAsync()​

Performs Asynchronous conversion.

public Task&ltByte[]> ConvertAsync()
Function ConvertAsync() As Task(Of Byte())

Returns​

returns a Task where the result type is byte array

Licensing Info​

This method is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Examples​

This example shows how to use convert method with byte array as return type.

Imports ceTe.DynamicPDF.Conversion

Module Module1

Async Function run() As Task

' Create new instance of Converter by providing suitable parameters.
Dim excelConversion As ExcelConverter = New ExcelConverter("C:\MyDocument.xlsx")

' Call Convert method to start conversion
Dim result= Await excelConversion.ConvertAsync()
If (result IsNot Nothing) Then
File.WriteAllBytes("C:\MyDocument.pdf",result)
End If

End Function

Sub Main()
run().Wait()
End Sub

End Module
using ceTe.DynamicPDF.Conversion;
using System.IO;

class MyClass
{
static async Task run()
{

// Create new instance of Converter.
ExcelConverter excel = new ExcelConverter(@"C:\MyDocument.xlsx");

//Call Convert method to start conversion
byte[] result=await excel.ConvertAsync();
if(result!=null)
{
File.WriteAllBytes("C:\MyDocument.pdf", result);
}
}
static void Main()
{
run().Wait();
}
}

ConvertAsync(Byte[])​

Performs Asynchronous conversion.

public Task&ltByte[]> ConvertAsync(Byte[] pdfToAppendTo)
Function ConvertAsync(pdfToAppendTo As Byte()) As Task(Of Byte())

Parameters​

Contents of PDF in byte array format, to which the current conversion needs to be appended to.

Returns​

returns a Task where the result type is byte array

Licensing Info​

This method is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Examples​

This example shows how to use convert method with pdf byte array as parameter and byte array as return type.

Imports ceTe.DynamicPDF.Conversion

Module Module1

Async Function run() As Task

' Create new instance of Converter by providing suitable parameters.
Dim excelConversion As ExcelConverter = New ExcelConverter("C:\MyDocument.xlsx")

' Call Convert method to start conversion
Dim result= Await excelConversion.ConvertAsync()
If (result IsNot Nothing) Then
Dim finalResult =Await excelConversion.ConverAsync(result)
If (finalResult IsNot Nothing) Then
File.WriteAllBytes("C:\MyDocument.pdf",finalResult)

End If
End If

End Function

Sub Main()
run().Wait()
End Sub

End Module
using ceTe.DynamicPDF.Conversion;

class MyClass
{
static async Task run()
{

// Create new instance of Converter.
ExcelConverter excel = new ExcelConverter(@"C:\MyDocument.xlsx");

//Call Convert method to start conversion
byte[] result=await excel.ConvertAsync();
if(result!=null)
{
byte finalResult=await excel.ConvertAsync(result)
File.WriteAllBytes("C:\MyDocument.pdf", finalResult);
}
}
static void Main()
{
run().Wait();
}
}

ConvertAsync(String)​

Performs Asynchronous conversion.

public Task&ltbool> ConvertAsync(string outputFilePath)
Function ConvertAsync(outputFilePath As String) As Task(Of Boolean)

Parameters​

File path for output PDF file where it needs to be saved

Returns​

Licensing Info​

This method is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Examples​

This example shows how to use convert method with byte array as return type.

Imports ceTe.DynamicPDF.Conversion

Module Module1

Async Function run() As Task

' Create new instance of Converter by providing suitable parameters.
Dim excelConversion As ExcelConverter = New ExcelConverter("C:\MyDocument.xlsx")

' Call Convert method to start conversion
Dim result= Await excelConversion.ConvertAsync("C:\MyOutput.pdf")
If (result) Then
Console.WriteLine("Completed successfully);
End If

End Function

Sub Main()
run().Wait()
End Sub

End Module
using ceTe.DynamicPDF.Conversion;
using Syste.IO;

class MyClass
{
static async Task run()
{

// Create new instance of Converter.
ExcelConverter excel = new ExcelConverter(@"C:\MyDocument.xlsx");

//Call Convert method to start conversion
bool result= await excel.ConvertAsync(@"C:\MyOutput.pdf");
if(result)
{
Console.WriteLine("Completed successfully);

}
}
static void Main()
{
run().Wait();
}
}

Equals(Object)​

Determines whether the specified Object is equal to the current Object . (Inherited from Object)

public bool Equals(Object obj)
Function Equals(obj As Object) As Boolean

Parameters​

The Object to compare with the current Object .

Returns​

true if the specified Object is equal to the current Object ; otherwise, false.

Licensing Info​

This method is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

GetHashCode()​

Serves as a hash function for a particular type. (Inherited from Object)

public int GetHashCode()
Function GetHashCode() As Integer

Returns​

A hash code for the current Object .

Licensing Info​

This method is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

GetType()​

Gets the Type of the current instance. (Inherited from Object)

public Type GetType()
Function GetType() As Type

Returns​

The Type instance that represents the exact runtime type of the current instance.

Licensing Info​

This method is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

ToString()​

Returns a String that represents the current Object . (Inherited from Object)

public string ToString()
Function ToString() As String

Returns​

A String that represents the current Object .

Licensing Info​

This method is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Events​

Completed​

Occurs when a document is successfully converted.

public event ConversionCompleted ExcelConverter.Completed;
Public Event ExcelConverter.Completed As ConversionCompleted

Event Handler​

ConversionCompleted

Licensing Info​

This event is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

DocumentParsing​

Occurs when the Excel document is being analysed. At this stage various worksheet specific options can be set.

public event ExcelDocumentParsing ExcelConverter.DocumentParsing;
Public Event ExcelConverter.DocumentParsing As ExcelDocumentParsing

Event Handler​

ExcelDocumentParsing

Licensing Info​

This event is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Examples​

Example shows how to apply conversion options to specific worksheet.

Imports ceTe.DynamicPDF.Conversion

Module Module1

Sub Main()

' Create new instance of Converter by providing suitable parameters.
Dim excelConversion As ExcelConverter = New ExcelConverter("C:\MyDocument.xlsx")

' Events to know if conversion completed successfully or not
AddHandler excelConversionDocumentParsing, AddressOf xlConverter_DocumentParsing

' Call Convert method to start conversion
excelConversion.Convert("C:\MyOutput.pdf")

End Sub

Sub xlConverter_DocumentParsing(ByVal sender As Object, ByVal e As ExcelDocumentParsingEventArgs)
For Each excelWorksheet As ExcelWorksheet In e.Worksheets
Dim excelWSOptions As ExcelWorksheetConversionOptions = excelWorksheet.ConversionOptions
Dim xlPageScaling As ExcelPageScaling = excelWSOptions.PageScaling
Dim zoomxlPageScaling As ZoomExcelPageScaling = xlPageScaling.ZoomExcelPageScaling
zoomxlPageScaling.ZoomPercentage = 50
excelWorksheet.ConversionOptions.DefaultToFile = False
Next
End Sub
End Module

using ceTe.DynamicPDF.Conversion;

class MyClass
{
static void Main()
{
// Create new instance of Converter by providing suitable parameters.
ExcelConverter excelConverter = new ExcelConverter(@"C:\MyDocument.xlsx");

excelConverter.DocumentParsing += new ExcelDocumentParsing(xlConverter_DocumentParsing);

//Call Convert method to start conversion
excelConverter.Convert(@"C:\MyOutput.pdf");
}
static void xlConverter_DocumentParsing(object sender, ExcelDocumentParsingEventArgs e)
{
foreach (ExcelWorksheet excelWorksheet in e.Worksheets)
{
ExcelWorksheetConversionOptions excelWSOptions = excelWorksheet.ConversionOptions;
ExcelPageScaling xlPageScaling = excelWSOptions.PageScaling;
ZoomExcelPageScaling zoomxlPageScaling = xlPageScaling.ZoomExcelPageScaling;
zoomxlPageScaling.ZoomPercentage = 50;
excelWorksheet.ConversionOptions.DefaultToFile = false;
}
}
}

Remarks​

See Reference of ExcelDocumentParsingEventArgs for details.

ProgressChanged​

Occurs when the status of a document conversion changes.

public event ProgressChanged ExcelConverter.ProgressChanged;
Public Event ExcelConverter.ProgressChanged As ProgressChanged

Event Handler​

ProgressChanged

Licensing Info​

This event is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

See Also​

ceTe.DynamicPDF.Conversion