[英]Convert Excel to PDF issue with documents4j
I want to use documents4j to convert Excel files to PDF but there are two issues: 我想使用documents4j将Excel文件转换为PDF,但是有两个问题:
How can I resolve this? 我该如何解决? Here is code that reproduces the issue:
这是重现此问题的代码:
private void convertExcelToPDF1() throws Exception {
InputStream excelFileIS = new BufferedInputStream(new FileInputStream("C:\\test_convert\\test.xlsx"));
File target = new File("C:\\test_convert\\sim_status_excel.pdf");
IConverter converter = RemoteConverter.builder()
.baseFolder(new File("D:\\temp"))
.workerPool(20, 25, 2, TimeUnit.SECONDS)
.requestTimeout(10, TimeUnit.SECONDS)
.baseUri("http://localhost:9998")
.build();
Future<Boolean> conversion = converter.convert(excelFileIS).as(DocumentType.XLSX)
.to(target).as(DocumentType.PDF)
.prioritizeWith(1000)
.schedule();
}
MS Excel is not necessarily intended for use of programmatic conversion. MS Excel不一定要用于程序转换。 Therefore, strange issues can occure.
因此,可能发生奇怪的问题。 First of all: Did you try to convert your file to PDF by directly using MS Excel?
首先:您是否尝试过直接使用MS Excel将文件转换为PDF? If the issues occure there, too, documents4j is powerless.
如果那里也发生问题,documents4j将无能为力。
Other than that, there might be report-options set that are required for making the export successful. 除此之外,可能还需要设置一些报告选项才能使导出成功。 You can have a look at the VBS scripts that documents4j runs for triggering Excel conversion: https://github.com/documents4j/documents4j/tree/master/documents4j-transformer-msoffice/documents4j-transformer-msoffice-excel/src/main/resources
您可以查看为触发Excel转换而运行document4j的VBS脚本: https : //github.com/documents4j/documents4j/tree/master/documents4j-transformer-msoffice/documents4j-transformer-msoffice-excel/src/main /资源
You can save these files locally and run them. 您可以在本地保存这些文件并运行它们。 First, you run
excel_start.vbs
from the command line in Windows. 首先,在Windows中从命令行运行
excel_start.vbs
。 Then you run excel_convert.vbs input.xls output.pdf 999
which triggers the to-PDF conversion for the given file. 然后,您运行
excel_convert.vbs input.xls output.pdf 999
,这将触发给定文件的PDF转换。 You can clean up by running excel_stop.vbs
. 您可以通过运行
excel_stop.vbs
进行清理。 after you are done. 完成后。
The two parameters that are interesting to you are: 您感兴趣的两个参数是:
excelApplication.Workbooks.Open(inputFile, , True, , , , , , , , , , , , 2)
and 和
excelDocument.ExportAsFixedFormat xlTypePDF, outputFile
which you can tweak to make your conversion run. 您可以对其进行调整以使转化运行。 I only tested with standard Excel files which work fine in my unit tests.
我仅使用标准Excel文件进行了测试,这些文件在我的单元测试中效果很好。 If you find out a solution that works for you, I am happy to merge your changes.
如果您找到适合您的解决方案,我很乐意合并您的更改。 The methods (
ExportAsFixedFormat
and Open
) are documented on MSDN. 方法(
ExportAsFixedFormat
和Open
)记录在MSDN上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.