2

几个月前,在完成学业时,我创建了一个基本应用程序,可以将 word 和 excel 文档转换为 PDF。我开发应用程序的客户需要它能够使用任何版本的单词,所以当我发现我需要使用后期绑定时。现在,该应用程序使用 office interop 可以完美运行,但我无法将所有内容转换为使用后期绑定。

我有一个 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 项目,因为我删除了对办公室互操作程序集的引用。我从未真正使用过后期绑定,也不知道如何解决这些类型。我希望一旦我解决了 ExportAsFixedFormat 函数调用将起作用。

4

1 回答 1

1

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

于 2013-01-17T18:05:47.570 回答