Excel转化pdf 以及sheet区域截图,转化的pdf和图片文件,其中文字换行有差异

Excel转化pdf 以及sheet区域截图,转化的pdf和图片文件,其中文字换行有差异
转化前:
image.png (17.7 KB)
转化后:
image.png (87.5 KB)
Excel区域截图也存在相应问题,望帮忙看一下如何解决

@zicao,
你愿意提供你的测试文件和可运行的控制台工程吗? 收到文件和工程后,我们将尽快检查和定位问题。

demo.zip (104.0 KB)
代码和测试文件都在包里了

@zicao,
你愿意使用Aspose.Cells 23.1再次测试吗? 我们能得到正确的结果。请查看附件。java23_1.zip (114.2 KB)

文字的显示的没问题,就是文字跟excel中显示的样式是不一致的。就是原先在excel不换行的文字,在pdf中换行了。在excel中换行的,在pdf中不换行了。。就是两边不是完全一致的。
excel中(第一个换行第二行不换行)
image.png (13.8 KB)
pdf中第一行下面英文自动换行了,第二行的中文后面应该换行,结果英文没换行,
image.png (58.4 KB)
感觉pdf的中的每一个单元格的列宽和excel中的不一致导致的

@zicao
请查看打印预览的结果或者用Excel另存为Pdf, 你会发现Aspose.Cells转换的结果是一样的。
Aspose.Cells 存储pdf是遵循Excel 打印预览的结果。

那导出pdf这个我觉得这边是没有问题的。就是我还想问下,假如我想实现Excel实现区域性截图,同时希望图片上的效果和Excel中看到的保持一致,用Aspose.Cells For Java 怎么实现呢?求教

@zicao

请尝试使用ImageOrPrintOptions.OnlyArea属性。

代码:

Workbook wb = new Workbook("test.xlsx");

Worksheet sheet = wb.getWorksheets().get(0);
//set a proper print area
sheet.getPageSetup().setPrintArea("B54:O63");

ImageOrPrintOptions imgOpt = new ImageOrPrintOptions();
imgOpt.setImageType(ImageType.PNG);
//To make output be more same as you see in Excel Normal view instead of Print view. 
imgOpt.setOnlyArea(true);

SheetRender sr = new SheetRender(sheet, imgOpt);
sr.toImage(0, "output.png");

确实是可以的。但是有些列会歪,有解决的方法么?
原先的excel
image.png (15.5 KB)
导出的图片是这样的
image.png (35.4 KB)

@zicao
最好用回车来代替文件中的空格,这样能保证换行的正确性, 不会受到列宽变化影响
test.zip (15.9 KB)

@zicao

用以下代码,我们已经复现您的问题,正如你的截图所示,单元格的文字不居中。我们将为您记录问题。

Workbook wb = new Workbook("test.xlsx");

Worksheet sheet = wb.getWorksheets().get(0);
//set a proper print area
sheet.getPageSetup().setPrintArea("B47:O63");

ImageOrPrintOptions imgOpt = new ImageOrPrintOptions();
imgOpt.setImageType(ImageType.PNG);
//To make output be more same as you see in Excel Normal view instead of Print view. 
imgOpt.setOnlyArea(true);

SheetRender sr = new SheetRender(sheet, imgOpt);
sr.toImage(0, "output.png");

@zicao
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSJAVA-45159

You can obtain Paid Support services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@zicao,

我们很高兴地通知您,您的问题已经解决。 该修复程序将包含在我们即将发布的下一个版本中,即计划于 2023 年 3 月上半月发布的 Aspose.Cells for .NET v23.3。新版本发布后,您将收到通知。

The issues you have found earlier (filed as CELLSJAVA-45159) have been fixed in Aspose.Cells for Java 23.3.