Click or drag to resize

ExcelToPdf Class

Main class to export Excel spreadsheets in to PDF, Word. Allows to create an instance of converter object and call converting methods.
Inheritance Hierarchy
SystemObject
  SautinSoftExcelToPdf

Namespace:  SautinSoft
Assembly:  SautinSoft.ExcelToPdf (in SautinSoft.ExcelToPdf.dll) Version: 2023.11.22
Syntax
public class ExcelToPdf

The ExcelToPdf type exposes the following members.

Constructors
  NameDescription
Public methodCode exampleExcelToPdf
Creates a new instance of ExcelToPdf class
Top
Properties
  NameDescription
Public propertyCode exampleColumnsToConvertLimit
The number of maximum processed columns in the table.
Public propertyCode exampleCreateTraceFile
Gets or sets whether to create a trace file. Default value: false.
Public propertyOptions
Set up the info block properties for resulting documents, such as file version and a document producer.
Public propertyCode exampleOutputFormat
Specify format for output file: PDF, Word, RTF etc. Default value: Pdf.
Public propertyPageStyle
Contains page properties for output PDF document: page size, orientation, page margins and put page numbers.
Public propertyCode exampleSerial
A string which contains a serial number to activate your copy after purchasing. Use it when you got own serial number and registered version.
Public propertyCode exampleSheets
Set custom sheets for converting. By default all sheets from workbook will be converted.
Public propertyTraceFilePath
Path to create a tracing file. Allows to track issues and exceptions which appeared during the conversion cycle. Default value: "C:\trace.txt"
Public propertyUnicodeOptions
Allows to specify options to properly convert Unicode, such as "Fonts" directory etc
Top
Methods
  NameDescription
Public methodCode exampleConvertBytes
Convert Excel bytes array to PDF, Word, RTF bytes array
Public methodConvertByteToFile
Convert Excel bytes array to PDF, Word, RTF file. Output file will be created by component or overwritten if already exist
Public methodCode exampleConvertFile
Convert Excel file to PDF, Word file. PDF file will be created by component or overwritten if already exist
Public methodConvertFiletoBytes
Convert Excel file to PDF, Word bytes array
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodCode exampleGetSheetsNumber(Byte)
Returns numbers of sheets from Excel workbook
Public methodCode exampleGetSheetsNumber(String)
Returns numbers of sheets from Excel workbook
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodStatic memberCode exampleSetLicense
A string which contains a serial number to activate your copy after purchasing. Use it when you got own serial number and registered version. SetLicense("1234567890")
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Examples
ASP.Net - Export Excel to PDF in C#
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Result.Text = "";
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (FileUpload1.PostedFile.FileName.Length == 0 || FileUpload1.FileBytes.Length==0)
        {
            Result.Text = "Please select an Excel document for conversion!";
            return;
        }        

        SautinSoft.ExcelToPdf x = new SautinSoft.ExcelToPdf();        
        x.PageStyle.PageSize.Letter();


        byte[] pdfBytes = null;

        try
        {
            pdfBytes = x.ConvertBytes(FileUpload1.FileBytes);
        }
        catch { }

        //show PDF
        if (pdfBytes != null)
        {
            Response.Buffer = true;
            Response.Clear();
            Response.ContentType = "application/PDF";
            Response.AppendHeader("content-disposition", "attachment; filename=Result.pdf");
            Response.BinaryWrite(pdfBytes);
            Response.Flush();
            Response.End();
        }
        else
        {
            Result.Text = "Converting failed!";
        }
    }
}
ASP.Net - Export Excel to PDF in VB.Net
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.IO

Partial Public Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        Result.Text = ""
    End Sub
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        If FileUpload1.PostedFile.FileName.Length = 0 OrElse FileUpload1.FileBytes.Length=0 Then
            Result.Text = "Please select an Excel document for conversion!"
            Return
        End If
        Result.Text = "Converting ..."

        Dim x As New SautinSoft.ExcelToPdf()
        x.PageStyle.PageSize.Letter()


        Dim pdfBytes() As Byte = Nothing

        Try
            pdfBytes = x.ConvertBytes(FileUpload1.FileBytes)
        Catch

        End Try


        'show PDF
        If pdfBytes IsNot Nothing Then
            Response.Buffer = True
            Response.Clear()
            Response.ContentType = "application/PDF"
            Response.BinaryWrite(pdfBytes)
            Response.Flush()
            Response.End()
        Else
            Result.Text = "Converting failed!"
        End If
    End Sub
End Class
See Also