Spire.Cloud.Excel provides the WorkbookApi interface to handle an entire Excel document. This article shows you how to convert Excel to PDF or XPS by using this API. In addition, it also supports converting Excel to PS, PCL, ODS, XLS, XLSX and XLSB file format.
Example 1. Convert Excel to PDF
using System;
using Spire.Cloud.Excel.Sdk.Api;
using Spire.Cloud.Excel.Sdk.Client;
using Spire.Cloud.Excel.Sdk.Model;
namespace ConvertExcelToPdf
{
class Program
{
static String appId = "App ID";
static String appKey = "App Key";
static String baseUrl = "https://api.cloudxdocs.com";
//Create a Configuration object based on App ID, App Key and base URL
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
//Create a WorkbookApi object
static WorkbookApi workbookApi = new WorkbookApi(configuration);
static void Main(string[] args)
{
//Specify the source document name
string name = "sample.xlsx";
//Specify the output document path
string outPath = "output/ToPdf.pdf";
//Specify the file format to which the source document will be converted
string format = ExportFormat.Pdf.ToString();
//Declare an ExportOptions variable and set it to null
ExportOptions options = null;
//Specify the original password, set to null if there is no password
string password = null;
//Use the default storage, set to null
string storage = null;
//Specify the folder where the source document is stored
string folder = "input";
//Call ConvertWorkbookToPath method to convert Excel to PDF
workbookApi.ConvertWorkbookToPath(name, outPath, format, options, password, storage, folder);
}
}
}
Example 2. Convert Excel to XPS
using System;
using Spire.Cloud.Excel.Sdk.Api;
using Spire.Cloud.Excel.Sdk.Client;
using Spire.Cloud.Excel.Sdk.Model;
namespace ConvertExcelToXps
{
class Program
{
static String appId = "App ID";
static String appKey = "App Key";
static String baseUrl = "https://api.cloudxdocs.com";
//Create a Configuration object based on App ID, App Key and base URL
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
//Create a WorkbookApi object
static WorkbookApi workbookApi = new WorkbookApi(configuration);
static void Main(string[] args)
{
//Specify the source document name
string name = "sample.xlsx";
//Specify the output document path
string outPath = "output/ToXps.xps";
//Specify the file format to which the source document will be converted
string format = ExportFormat.Xps.ToString();
//Declare an ExportOptions variable and set it to null
ExportOptions options = null;
//Specify the original password, set to null if there is no password
string password = null;
//Use the default storage, set to null
string storage = null;
//Specify the folder where the source document is stored
string folder = "input";
//Call ConvertWorkbookToPath method to convert Excel to XPS
workbookApi.ConvertWorkbookToPath(name, outPath, format, options, password, storage, folder);
}
}
}