使用aspose word 将word转成html 源文件中的表格没有边框,转出来的表格内容中存在边框

边框问题.zip (238.1 KB)

HtmlFixedSaveOptions options = new HtmlFixedSaveOptions();
options.setUseTargetMachineFonts(false);
options.setUseHighQualityRendering(true);
options.setEncoding(Charset.forName("UTF-8"));
options.setExportEmbeddedFonts(true);
options.setShowPageBorder(true);
document.acceptAllRevisions();
document.save(targetFileName, options);

使用25.12的也有问题

@xiangma

您遇到的现象可能与 Aspose.Words 在使用固定格式保存选项时会把隐藏(非可见)表格边框渲染出来 有关。已有报告指出,在使用 PdfSaveOptionsDocSaveOptions 等固定格式保存时,隐藏的表格边框会被写入输出文件【2】。HtmlFixedSaveOptions 也属于固定格式,可能会出现类似情况。

可尝试的思路

  1. 改用非固定格式的 HTML 保存选项

    HtmlSaveOptions options = new HtmlSaveOptions();
    options.setExportEmbeddedFonts(true);
    options.setEncoding(Charset.forName("UTF-8"));
    // 其它需要的设置
    document.save(targetFileName, options);
    

    HtmlSaveOptions 是非固定格式的保存方式,可能会保留源文档中表格边框的可见性,而不会把隐藏边框渲染出来。

  2. 如果必须使用 HtmlFixedSaveOptions,可以在保存前尝试手动清除表格边框

    for (Table table : (Iterable<Table>) document.getFirstSection().getBody().getTables()) {
        for (Cell cell : (Iterable<Cell>) table.getChildren(Cell.class)) {
            cell.getCellFormat().getBorders().clear();   // 或者逐个将 LineStyle 设为 None
        }
    }
    document.save(targetFileName, new HtmlFixedSaveOptions());
    

    通过遍历所有表格并将单元格的 Borders 清空(或将 LineStyle 设为 None),有时可以避免在固定格式输出时出现不期望的边框。

小结

  • 在使用固定格式保存(如 PdfSaveOptionsDocSaveOptions)时,已知会把隐藏的表格边框渲染出来【2】。HtmlFixedSaveOptions 可能会有类似表现。
  • 可以尝试使用 HtmlSaveOptions(非固定格式)来获得与源文档更一致的表格外观。
  • 如必须使用 HtmlFixedSaveOptions,可在保存前手动清除或隐藏表格边框。

如果上述方案仍未解决问题,建议在本帖继续提供具体的 Word 示例文件(如您已上传的 zip),以便进一步定位。

还是不行,源文件已经提供了,麻烦在看下

@xiangma 这与该帖子中报告的问题相同:
https://forum.aspose.com/t/aspose-word-word-html/323604