How to export data from XLS spreadsheet to PDF file in C# with Spreadsheet SDK

The sample below shows how to export data from XLS spreadsheet to PDF file in C#. Spreadsheet SDK loads table from Excel file, adds image and saves the result as PDF.

C#

using System;
using System.Collections.Generic;
using System.Text;
using Bytescout.Spreadsheet;
using System.Drawing;
using System.IO;
 
namespace XLS2PDF
{
    class Program
    {
        static void Main(string[] args)
        {
            Spreadsheet document = new Spreadsheet();
 
    // load table from existing XLS file        
    document.LoadFromFile("SimpleReport.xls");
 
    // add image
    document.Workbook.Worksheets[0].Pictures.Add(0, 5, "image1.jpg");
 
    // save as PDF
    if (File.Exists("output.pdf"))
        File.Delete("output.pdf");
    document.SaveAsPDF("Output.pdf");
 
    // save as XLS
    if (File.Exists("Output.xls"))
        File.Delete("Output.xls");
    document.SaveAsXLS("Output.xls");
 
            // close the document 
            document.Close();
 
        }
    }
}
Filed in: Spreadsheet SDK

Tutorials: