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

时间:2013-02-18 21:29:23

标签: c# asp.net winforms excel

我正在将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();
    }

1 个答案:

答案 0 :(得分:0)

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

有关详细信息,请参阅MSDN on XlFixedFormatTypeMSDN on ExportAsFixedFormat

示例:

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