C#Office PDF导出后期绑定

时间:2012-11-04 21:32:26

标签: c#-4.0 pdf office-interop late-binding

几个月前,在完成学业的过程中,我创建了一个基本的应用程序,可以将单词和Excel文档转换成PDF格式。我开发应用程序的客户端需要它能够使用任何版本的单词,所以当我发现我需要使用后期绑定。现在,应用程序可以完美地使用办公室互操作,但我无法将所有内容转换为使用后期绑定。

我有一个word文档要打开,但我遇到了以下问题。

Type wordType = Type.GetTypeFromProgID("Word.Application");
if(wordType == null)
    throw new Exception(message);

dynamic wordApplication = null;
wordApplication = Activator.CreateInstance(wordType);
if(wordApplication == null)
    throw new Exception(message);

dynamic wordDocument = null;
object paramSourceDocPath = sourceDocPath;
object paramMissing = Type.Missing;

WdExportFormat targetFormat = WdExportFormat.wdExportFormatPDF;
WdExportOptimizeFor paramExportOptimizeFor = WdExportOptimizeFor.wdExportOptimizeForOnScreen;
WdExportRange paramExportRange = WdExportRange.wdExportAllDocument;
int paramStartPage = 0;
int paramEndPage = 0;
WdExportItem paramExportItem = WdExportItem.wdExportDocumentContent;
bool paramIncludeDocProps = true;
bool paramKeepIRM = true;
WdExportCreateBookmarks paramCreateBookmarks = WdExportCreateBookmarks.wdExportCreateWordBookmarks;
bool paramDocStructureTags = true;
bool paramBitmapMissingFonts = true;
bool paramUseISO19005_1 = false;

try
{
    // Open the source document.
    wordDocument = wordApplication.Documents.Open(ref paramSourceDocPath, ref paramMissing, ref paramMissing, ref paramMissing,
        ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing,
        ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing);

    // Export it in the specified format.
    if (wordDocument != null)
        wordDocument.ExportAsFixedFormat(targetFilePath, targetFormat, openAfter, paramExportOptimizeFor,
            paramExportRange, paramStartPage, paramEndPage, paramExportItem, true, true, paramCreateBookmarks, true,
            true, false, ref paramMissing);
}

无法解析WdExportXXXXXX项目,因为我删除了对office互操作程序集的引用。我从来没有真正使用过后期绑定,我不知道如何解决这些类型。我希望一旦我得到解决了ExportAsFixedFormat函数调用就可以了。

1 个答案:

答案 0 :(得分:1)

我发现NetOffice可以完美地完成手头的任务。

相关问题