1

我使用“Microsoft.Office.Interop.Excel”将 Excel 转换为 PDF,但是当我的源文件大小很大(例如 10MB)时,需要很长时间...

    public static bool XLSConvertToPDF(string sourcePath, string targetPath)
    {
        bool result = false;
        XlFixedFormatType targetType = XlFixedFormatType.xlTypePDF;
        object missing = Type.Missing;
        Microsoft.Office.Interop.Excel.ApplicationClass application = null;
        Workbook workBook = null;
        try
        {
            application = new Microsoft.Office.Interop.Excel.ApplicationClass();
            object target = targetPath;
            object type = targetType;
            workBook = application.Workbooks.Open(sourcePath, missing, missing, missing, missing, missing,
                    missing, missing, missing, missing, missing, missing, missing, missing, missing);
            workBook.ExportAsFixedFormat(targetType, target, XlFixedFormatQuality.xlQualityStandard, true, false, missing, missing, missing, missing);
            result = true;
        }
        catch
        {
            result = false;
        }
        finally
        {
            if (workBook != null)
            {
                workBook.Close(false, missing, missing);
                workBook = null;
            }
            if (application != null)
            {
                application.Quit();
                application = null;
            }
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
        return result;
    }

1.有没有好的建议或替代组件可以使用?

2.我知道有Adobe API,但效率如何?

顺便说一句,我也想将docx或pptx转换为pdf。非常感谢!!

4

0 回答 0