【发布时间】:2014-07-04 03:20:00
【问题描述】:
由于某种原因,Coldfusion 在访问它创建的对象之一的父方法时遇到问题。
考虑这段代码:
<cfscript>
variables.sHTML = '<html><head><title></title></head><body><p>Hello <strong>World</strong></p></body></html>';
try{
variables.sAltChunkID = "altChunk1";
variables.sExportDirectory = application.sSecureExportPath&'int'&'\word\';
variables.sDLLPath = 'C:\Program Files (x86)\Open XML SDK\V2.0\lib\DocumentFormat.OpenXml.dll';
variables.sFileName = "testI.docx";
variables.sFileToWrite = variables.sExportDirectory&'#variables.sFileName#';
variables.enumWordProcessingDocumentType = createObject("dotnet","DocumentFormat.OpenXml.WordprocessingDocumentType","#variables.sDLLPath#").init().Document;
variables.oDocument = createObject("dotnet","DocumentFormat.OpenXml.Packaging.WordprocessingDocument","#variables.sDLLPath#").Create(variables.sFileToWrite,variables.enumWordProcessingDocumentType);
variables.oMainDocument = variables.oDocument.AddMainDocumentPart();
variables.oEncoding = createObject("dotnet","System.Text.UTF8Encoding").init();
//variables.oMemoryStream = createObject("dotnet","System.IO.MemoryStream").init(variables.oEncoding.GetBytes(variables.sHTML));
variables.enumAltChunk = createObject("dotnet","DocumentFormat.OpenXml.Packaging.AlternativeFormatImportPartType","#variables.sDLLPath#").html;
variables.oFormatImportPart = variables.oMainDocument.AddAlternativeFormatImportPart(variables.enumAltChunk,variables.sAltChunkID);
writeDump(variables.oFormatImportPart);
variables.oFormatImportPart.FeedData(createObject("dotnet","System.IO.MemoryStream").init(variables.oEncoding.GetBytes(variables.sHTML)));
} catch(Any e) {
writeDump(e);
}
</cfscript>
variables.oFormatImportPart 有一个 FeedData(System.IO.Stream) 的父方法,但是当我到达那条线时,Coldfusion 给我打了一个例外:
要么没有具有指定方法名称和参数类型的方法,要么 FeedData 方法被 ColdFusion 无法可靠破译的参数类型重载。 ColdFusion 找到 0 个与提供的参数匹配的方法。如果这是一个 Java 对象并且您验证了该方法存在,请使用 javacast 函数来减少歧义。
但正如你从我的 Dump 中看到的,FeedData 确实作为一种方法存在:
【问题讨论】:
-
(编辑)只是猜测,但可能是class loader issue。尝试将
sDLLPath路径添加到您的 createObject 调用的 all 中。特别是,用于创建流的那个传递给FeedData(...) -
@Leigh 所以我尝试在
oEncoding创建和memorystream创建上添加sDLLPath,但没有骰子。它似乎仍然找不到 FeedData 方法。 -
终于有机会试试代码了。修复了一个小语法错误后,不幸的是,我得到了与 cF10,FWIW 相同的结果。删除存根并重新启动没有效果。当然看起来它应该工作,因为两个对象都存在,并且参数是
System.IO.Stream的实例。 -
为寻找干杯。我可能只是编写一个基本上为我完成此任务的 DLL,将 HTML 和来自coldfusion 的其他参数传递给它。应该不会有太大的麻烦。
-
为了咧嘴笑,我用
System.IO.FileStream尝试了它,它似乎有效。不确定有什么区别,因为这两个类都扩展了Stream。
标签: c# .net coldfusion openxml openxml-sdk