xiaoman
February 26, 2025, 8:01am
1
测试代码如下:
public void testImage111() throws Exception {
String template = "files/template.xlsx";
Workbook book = new Workbook(template);
book.getWorksheets().get(0).getCells().get(0,2).setValue("dddddd");
book.save("files/template-result.xlsx");
}
文件:
文件.zip (124.6 KB)
模板中有两个图片 一个时嵌入到单元格 一个时悬浮式 悬浮的转出来没问题 嵌入式的有问题 帮忙看看
@xiaoman
WPS 和Excel 采用了不同的方式嵌入图片。 我们默认生成是Excel支持的模式。 如果要WPS兼容,使用以下代码:
Workbook workbook = new Workbook(dir + “Template.xlsx”);
OoxmlSaveOptions options = new OoxmlSaveOptions();
options.setWpsCompatibility( true);
workbook.save(dir + “dest.xlsx”, options);
John.He
February 26, 2025, 8:32am
3
@xiaoman
由于WPS和Excel在单元格嵌入图片功能上的差异性,请在保存带有嵌入单元格图片的文件时,调用OoxmlSaveOptions.setWpsCompatibility( true)方法。通过使用以下样例代码在最新版本v25.2上进行测试,我们可以获得正确的结果。请查看附件。out_java.zip (61.8 KB)
Workbook book = new Workbook(filePath + "template.xlsx");
book.getWorksheets().get(0).getCells().get(0,2).setValue("dddddd");
OoxmlSaveOptions options = new OoxmlSaveOptions();
options.setWpsCompatibility( true);
book.save(filePath + "out_java.xlsx", options);
John.He
February 26, 2025, 9:22am
5
@xiaoman
WPS兼容性设置功能在最新版本v25.2才开始支持。请查看以下文档。
John.He
February 26, 2025, 9:32am
7
@xiaoman
感谢你的反馈。不客气。如果你有任何疑问,请随时联系我们。
The issues you have found earlier (filed as CELLSJAVA-46283) have been fixed in Aspose.Cells for Java 25.3 .
@xiaoman
旧版本中没有保留wps中嵌入图片的位置和大小的信息。
我们在Aspose.Cells for Java 25.3 .中修复了这个bug.
SeanXie
December 19, 2025, 9:16am
10
我这边在25.3的版本试了一下,读取本地的Excel 后增加这些参数,写到新的Excel文件,内嵌单元格图片还是丢失了,这个和Excel的版本有关吗
John.He
December 19, 2025, 9:19am
11
@SeanXie
你愿意提供你的样例文件和可运行的测试代码吗?我们很快就会检查。
SeanXie
December 22, 2025, 2:27am
12
public static void main(String[] args) {
try{
String output = "/temp/销售订单打印设置copy2.xls";
Workbook workbook = new Workbook("/temp/测试2.xls");
OoxmlSaveOptions options = new OoxmlSaveOptions();
options.setWpsCompatibility(true);
workbook.save(output, options);
}catch (Exception ex){
ex.printStackTrace();
}
}
测试2.xls.zip (2.2 MB)
John.He
December 22, 2025, 2:53am
13
@SeanXie
通过使用样例文件和以下样例代码在最新版本v25.12上进行测试,我们可以复现问题。当重新保存xls文件到xls格式时,xls结果文件的嵌入图片在WPS中显示正常,但在Excel中显示异常。当重新保存xls文件到xlsx格式时,xlsx结果文件的嵌入图片在WPS和Excel中都显示异常。请查看附件。测试2.xls.zip (2.2 MB)
Workbook workbook = new Workbook(filePath + "测试2.xls");
XlsSaveOptions xlsoptions = new XlsSaveOptions();
xlsoptions.setWpsCompatibility(true);
workbook.save(filePath + "out_java.xls", xlsoptions);
OoxmlSaveOptions options = new OoxmlSaveOptions();
options.setWpsCompatibility(true);
workbook.save(filePath + "out_java.xlsx", options);
我们已经在内部问题跟踪系统中打开了以下新问题单,并将根据Free Support Policies 中提到的条款提供修复。
问题单号:
CELLSJAVA-46595:The embedded image of XLS file displays abnormally in Excel when resaving xls with WPS compatibility
CELLSJAVA-46596:The embedded image of XLSX file displays abnormally in WPS and Excel when saving xls to xlsx with WPS compatibility
@SeanXie
目前,我们还不支持读写xls文件中的嵌入图片。我们只能让WPS还能识别保存的xls中的嵌入式图片,因为excel不支持xls的嵌入式图片。
John.He
December 22, 2025, 8:19am
15
@SeanXie
经过研究我们发现,Excel的xls格式不支持嵌入图片,当包含嵌入图片的文件在excel中打开时, 单元格显示#VALUE。xlsx格式是支持嵌入图片的。WPS的xls和xlsx格式都支持嵌入图片。
另外,你的样例代码中保存的文件格式和选项不匹配。请参考以下样例代码。
Workbook workbook = new Workbook(filePath + "测试2.xls");
XlsSaveOptions xlsoptions = new XlsSaveOptions();
xlsoptions.setWpsCompatibility(true);
workbook.save(filePath + "out_java.xls", xlsoptions);
OoxmlSaveOptions options = new OoxmlSaveOptions();
options.setWpsCompatibility(true);
workbook.save(filePath + "out_java.xlsx", options);
@xiaoman , @SeanXie ,
我们很高兴地通知您,以下问题(工单编号:“CELLSJAVA-46595” 和 “CELLSJAVA-46596”)已得到解决。这些改进/修复计划将包含在即将发布的 Aspose.Cells v26.1 版本中,预计发布时间为2026年1月上半月。一旦支持的版本可用,我们将立即通知您。
@SeanXie @xiaoman
在下一个版本中
1,如果模板中有WPS特有的嵌入式图片, 会默认生成wps兼容的图片。
2,SaveOptions.setWpsCompatibility() 被过期了,请使用WorkbookSetting.SetWpsCompatibility() method 因为差异化可能不仅仅在保存的文件中。
SeanXie
December 26, 2025, 8:05am
18
我们现在升级到了25.12,但是save的时候需要增加OoxmlSaveOptions参数,saveFormat参数就无法设置了,这个可以怎么操作
John.He
December 26, 2025, 8:12am
19
@SeanXie
你可以在构建OoxmlSaveOptions 对象时设置SaveFormat, 请参考以下样例代码和API文档。
OoxmlSaveOptions options = new OoxmlSaveOptions(SaveFormat.XLSX);
The issues you have found earlier (filed as CELLSJAVA-46595,CELLSJAVA-46596) have been fixed in Aspose.Cells for Java 26.1 .