C#实现excel转换成pdf的三种方法
方法一:使用Excel Interop库
using Excel = Microsoft.Office.Interop.Excel;
using System.IO;
using System.Reflection;
public void ConvertExcelToPdf(string excelFilePath, string pdfFilePath)
{
// Create a new Excel application
Excel.Application excelApplication = new Excel.Application();
excelApplication.ScreenUpdating = false;
try
{
// Open the Excel file
Excel.Workbook excelWorkbook = excelApplication.Workbooks.Open(excelFilePath);
// Save the Excel file as PDF
excelWorkbook.ExportAsFixedFormat(Excel.XlFixedFormatType.xlTypePDF, pdfFilePath);
// Close the Excel file
excelWorkbook.Close(false);
// Quit the Excel application
excelApplication.Quit();
}
finally
{
// Release the COM obje