关于将办公室转换为PDF

时间:2013-04-07 10:30:27

标签: c# excel pdf

我使用“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。 非常感谢!!

0 个答案:

没有答案