Aspose.words for java HTML转换为word 表格问题

将HTML文件转为word后,所有的表格都超出了右边距,如下图所示
image.png (72.9 KB)
请问是否在生成文档是设置表格的属性为自动调整,代码怎么实现?
html2word-table.zip (54.5 KB)
如果需要测试html文件,在html2word.txt文件里,将http://localhost:8080替换为http://8.129.166.85

@guanvo,

我们测试了这种情况,并最终设法重现了同样的问题。 为了更正,我们已将此问题记录在问题跟踪系统中。 此问题的ID为WORDSNET-20558。 我们将进一步调查该问题的详细信息,并让您及时了解更正的状态。 对于给您带来的不便,我们深表歉意。

非常谢谢您的回复,我在这附上我的代码:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getPageSetup().setPaperSize(PaperSize.A4);
builder.getPageSetup().setLeftMargin(20d);
builder.getPageSetup().setRightMargin(20d);
// builder.getPageSetup().setTopMargin(25d);
// log.info(html);
builder.insertHtml(html);
try {
appendHeaderFooter(doc);
builder.moveToDocumentStart();
// builder.insertTableOfContents("\o"1-3"\h\z\u");
builder.insertTableOfContents("\o “1-3” \h \z \u");
doc.updateFields();
} catch (Exception e) {

		}
		outputStream = new FileOutputStream(fileName);
		doc.save(outputStream, SaveFormat.DOC);// 生成doc文件
		outputStream.close();

请帮忙指正错误

@guanvo,

通过使用以下简单的Java代码,我们可以在将’html2word.html’转换为DOCX格式的过程中观察到该问题(WORDSNET-20558)。

Document doc = new Document("E:\\Temp\\213732\\html2word.html");
doc.save("E:\\Temp\\213732\\20.6.docx");

现在,关于您在上一篇文章中共享的新代码,您是否正在报告另一个新问题供我们调查? 此代码缺少某些方法,例如 缺少appendHeaderFooter方法定义。 请在此处提供完整的代码进行测试。

如果这是您要报告的新问题,则请ZIP并附加新的源HTML和Aspose.Words生成的DOC文件,此处显示了不良行为,以供测试。

请同时提供比较屏幕截图,突出显示上述DOC文件中与您的HTML文件有关的确切问题区域,并将其附加在此处以供我们参考。

image.png (46.7 KB)
export.zip (322.6 KB)
表格也右边综述超出页边距,请问能不能在导出时设置表格自动调整
appendHeaderFooter(doc);可以从程序中去除

@guanvo,

我们已在错误跟踪系统中记录了此问题。 此问题的ID为WORDSNET-20569。 您的主题也已与此问题相关联,以后将尽快通知您。 抱歉给你带来不便。

1 Like

希望您能尽快帮忙解决此问题,我们需要解决这个table问题交付,非常谢谢

@guanvo,

恐怕,您的两个问题目前都在等待分析,并且正在排队。 这些问题将来得到解决后,我们会尽快通过此线程通知您。 很抱歉给您带来不便。

希望能加快速度,非常感谢!除了表格问题,另外我这边给的zip文件word文档,在第一页中出现 No table of contents entries found.,builder.moveToDocumentStart();
builder.insertTableOfContents("\o “1-3” \h \z \u");
doc.updateFields();
调用的代码不成功,导致导出错误,而且是希望在第二页插入目录,因为第一是封面,请位怎样写程序代码
export2word.zip (301.8 KB)

@guanvo,

似乎出现此问题是因为Word文档中没有标题段落。 能否请ZIP并附加您期望的Word文件,在此处显示所需的输出以供我们参考? 您可以使用MS Word创建此预期文档。

因为这个word文档是从html转为word文档,我如何将生成的word文档添加目录级别?是否需要遍历文档的文字,把指定的文字在代码中设置标题级别,然后插入到目录里,另外请问有没有aspose.words的帮助文档或实例文档,我需要用aspose读取word文件的文字和表格数据。非常谢谢!
As this word document is converted from html to word document, how can I add the directory level to the document? Do I need to traverse the text of the document, set the specified text in the code to set the title level, and then insert it into the table of contents? Also, is there any help document or example document for aspose.words for java, I need to use aspose to read the text and table data of the word document. thank you very much!
![](file:///C:\Users\huangh\AppData\Roaming\Tencent\Users\6676026\QQ\WinTemp\RichOle\MHQE`@}]88U[VRNI[{H(MZE.png)
export2word.zip (597.7 KB)

@guanvo,

我们正在处理您的查询,并将尽快与您联系。

I would like to ask, when can I solve the problem I raised, and how is the progress of the solution?

@guanvo,

Regarding the question you asked here, you need to add appropriate Outline Levels to the Paragraphs that you want to make part of ‘Table of Contents’ (TOC) field. The following sample Java code will help you to get the desired TOC output:

Document doc = new Document("E:\\export2word\\exportword.doc");

for (Paragraph para : (Iterable<Paragraph>) doc.getChildNodes(NodeType.PARAGRAPH, true)) {
    if (para.getParagraphFormat().getStyleName().equals("comp-box")) {
        if (para.getParagraphFormat().getAlignment() == ParagraphAlignment.CENTER)
            para.getParagraphFormat().setOutlineLevel(OutlineLevel.LEVEL_1);
        else if (para.getParagraphFormat().getLineSpacingRule() == LineSpacingRule.AT_LEAST &&
                para.getParagraphFormat().getAlignment() == ParagraphAlignment.LEFT)
            para.getParagraphFormat().setOutlineLevel(OutlineLevel.LEVEL_2);
    }
}

doc.updateFields();
doc.save("E:\\export2word\\awjava-20.6.docx");

Regarding WORDSNET-20558 and WORDSNET-20569, these issues are currently pending for analysis and are in the queue. There are no estimates available at the moment. Once the analysis of these issues will be completed and the root causes are determined, we may then be able to calculate and share the estimates of these issues with you. We apologize for any inconvenience.

Perfect, thank you for your help, I will test the code, and then give you feedback. In addition, the problem of html table export, after we adjust the display width of the table in html to 90%, the table in the exported word file displays normally

@guanvo,

Sure, we will wait for your any further input on Table of Contents (TOC field) related problem. Also, it is good to know that you have found workaround for the linked issues.

2 posts were split to a new topic: Move cursor position to start of a particular page in Word document using Java