字符串不可分配给参数类型Excel.XIFixedFormatType

本文关键字:类型 Excel XIFixedFormatType 参数 不可分 可分配 字符串 | 更新日期: 2023-09-27 18:00:12

我正在将excel文件转换为pdf文件,但当我传入用于导出的字符串时,我会收到此错误(红色下划线convertFilePath)Argument type string is not assignable to parameter type Microsoft.Office.Interop.Excel.XIFixedFormatType

var convertFileId = Guid.NewGuid();
var convertFilePath = @"c:'temp'" + convertFileId + ".pdf";

public Microsoft.Office.Interop.Excel.Workbook excelWorkbook { get; set; }
    void ExcelToPdf(string convertFilePath)
    {
        Microsoft.Office.Interop.Excel.Application appWord = new Microsoft.Office.Interop.Excel.Application();
        excelWorkbook = appWord.Workbooks.Open(DocumentUNCPath.Text);
        excelWorkbook.ExportAsFixedFormat(convertFilePath, WdExportFormat.wdExportFormatPDF);
        excelWorkbook.Close();
        appWord.Quit();
    }

字符串不可分配给参数类型Excel.XIFixedFormatType

XlFixedFormatType是一个枚举,您应该传递一个有效值。

有关详细信息,请参阅XlFixedFormatType上的MSDN和ExportAsFixedFormat上的MSDN。

示例:

excelWorkbook.ExportAsFixedFormat(xlTypePdf, Filename:=filename);