我想使用documents4j将Excel文件转换为PDF,但有两个问题:
我怎么解决这个问题?下面是再现问题的代码:
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();
}发布于 2015-12-17 11:00:13
MS Excel不一定用于编程转换。因此,奇怪的问题可能会发生。首先:您是否试图通过直接使用MS将您的文件转换为PDF?如果问题也存在的话,documents4j是无能为力的。
除此之外,还可能有使导出成功所需的报表选项集。您可以查看documents4j为触发https://github.com/documents4j/documents4j/tree/master/documents4j-transformer-msoffice/documents4j-transformer-msoffice-excel/src/main/resources转换而运行的VBS脚本:https://github.com/documents4j/documents4j/tree/master/documents4j-transformer-msoffice/documents4j-transformer-msoffice-excel/src/main/resources。
您可以在本地保存这些文件并运行它们。首先,从Windows中的命令行运行excel_start.vbs。然后运行excel_convert.vbs input.xls output.pdf 999,这将触发给定文件的到-PDF转换。您可以通过运行excel_stop.vbs来清理。在你做完之后。
您感兴趣的两个参数是:
excelApplication.Workbooks.Open(inputFile, , True, , , , , , , , , , , , 2)和
excelDocument.ExportAsFixedFormat xlTypePDF, outputFile您可以对其进行调整以使您的转换运行。我只使用在单元测试中工作良好的标准Excel文件进行测试。如果您找到了一个适合您的解决方案,我很乐意合并您的更改。方法(ExportAsFixedFormat和Open)记录在MSDN上。
https://stackoverflow.com/questions/34314838
复制相似问题