C# .NET Core can convert Excel files to PDF format using the Microsoft.Office.Interop.Excel library. Here's a simple code example:

using Microsoft.Office.Interop.Excel;
using System.IO;

public void ConvertExcelToPdf(string excelFilePath, string pdfFilePath)
{
    Application excelApplication = new Application();
    Workbook excelWorkbook = excelApplication.Workbooks.Open(excelFilePath);
    excelWorkbook.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, pdfFilePath);
    excelWorkbook.Close(false);
    excelApplication.Quit();

    // Delete the temporary Excel file
    File.Delete(excelFilePath);
}

This code creates an Excel application object, opens the Excel file, and exports it as a PDF. Finally, it closes the Excel application object and deletes the temporary Excel file.

Note that you must have Microsoft Office installed and use the Interop library to use this method. Additionally, you need Excel installed on your system.

C# .NET Core: Convert Excel to PDF with Microsoft.Office.Interop.Excel

原文地址: https://www.cveoy.top/t/topic/oodq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录