Aspose.Words.DocumentBuilder的InsertHtml() :将html文本字符转word报错,索引超出数组界限

Aspose.Words.DocumentBuilder的InsertHtml() :将html文本字符转word报错,索引超出数组界限
使用InsertHtml()将html文本字符串,转为word时,报索引超出数组界限
请问一下,有谁知道这个方法支持的最大长度是多?

@jason11 您能否在此处附上您的 HTML 和代码以进行测试? 我们将检查问题并为您提供更多信息。

方式一:
aspose.words.document doc=new aspose.words.document();
aspose.words.documentbuilder builder=new aspose.words.documentbuilder(doc);
builder.inserthtml(str);

方式二:
var bytes=system.text.encoding.utf8.getbytes(str);
aspose.words.document doc=new aspose.words.document(new memorystream(bytes));

字符串str的字节数大概是24万,两种方式都报“索引超出数组界限”

@jason11 你能提供HTML字符串吗? 我们将检查问题并为您提供更多信息。

邮件发你了,在附件中,下载下来用编辑器打开复制里面的内容

@jason11 我没有收到任何包含数据的电子邮件。 您可以在此处附加 HTML 文件,只需将其压缩并附加到帖子中即可。 在论坛中附加文件是安全的,只有您和 Aspose 工作人员可以访问您的附件。

方式一:
aspose.words.document doc=new aspose.words.document();
aspose.words.documentbuilder builder=new aspose.words.documentbuilder(doc);
builder.inserthtml(str);

方式二:
var bytes=system.text.encoding.utf8.getbytes(str);
aspose.words.document doc=new aspose.words.document(new memorystream(bytes));

字符串str的字节数大概是24万,两种方式都报“索引超出数组界限”

str使用的是html源码,请查看附件

(Attachment 如何将整个网站离线储存到本地? - 知乎.html is missing)

@jason11 我没有收到任何包含数据的电子邮件。 您可以在此处附加 HTML 文件,只需将其压缩并附加到帖子中即可。 在论坛中附加文件是安全的,只有您和 Aspose 工作人员可以访问您的附件。

将本html的源码作为字符串.ZIP (33.1 KB)
就是这个文件,你解压后,用编辑器打开获取里面的源码,处理特殊字符后作为字符串传入上述方法中,

@jason11 我已经使用以下代码检查了您的 HTML:

Document doc = new Document(@"C:\Temp\in.html");
doc.Save(@"C:\Temp\out.docx");
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertHtml(File.ReadAllText(@"C:\Temp\in.html"));
doc.Save(@"C:\Temp\out.docx");

这两种方法对我来说都很好。 您能否提供一个代码示例,使我们能够重现该问题? 我们将检查问题并为您提供更多信息。

你直接将html里面的源码,copy替换到str中
aspose.words.document doc=new aspose.words.document();
aspose.words.documentbuilder builder=new aspose.words.documentbuilder(doc);
builder.inserthtml(str);

@jason11 您能否创建一个简单的控制台应用程序,以便我们重现问题并将其附加到此处?

其实就是将html源码作为字符串,传入builder.inserthtml(str);这个方法中,
不是以html文件的形式读取。
稍晚点,公司电脑没环境。我晚点做个列子上传上来

@jason11 简单地将文件读取为字符串并使用 DocumentBuilder.InsertHtml 不允许重现该问题。 我将等待您的简单申请。

HomeController.zip (33.5 KB)
aspose.words版本是16.7

@jason11 感谢您提供更多信息。 我无法用最新版本的 Aspose.Words 重现该问题。 所以请尝试使用最新的 21.12 版本。

感谢!!!
我回去试试最新版的看看啥效果