本帖最后由 Joestar.Xu 于 2023-8-16 16:55 编辑
数据和模板如附件。
代码如下:
- public class DemoCsvDatasource {
- public static void main(String[] args) throws FileNotFoundException {
- long start = System.currentTimeMillis();
- String index = "23";
- Workbook workbook = new Workbook();
- String rootPath = "";
- String templateFile = rootPath+index+"template.xlsx";
- workbook.open(templateFile);
- workbook.getNames().add("TemplateOptions.PaginationMode", "true");
- System.out.println("open template cost: "+(System.currentTimeMillis() - start)/1000.0);
- java.sql.ResultSet datasource = new GcMockResultSet(getFileStream(rootPath+index+"data.csv"));
- System.out.println("open data source cost: "+(System.currentTimeMillis() - start)/1000.0);
- workbook.addDataSource("ds", datasource);
- System.out.println("add data source cost: "+(System.currentTimeMillis() - start)/1000.0);
- workbook.processTemplate();
- System.out.println("process template cost: "+(System.currentTimeMillis() - start)/1000.0);
- workbook.save(rootPath+index+"result.xlsx");
- System.out.println("save xlsx cost: "+(System.currentTimeMillis() - start)/1000.0);
- for (IWorksheet worksheet : workbook.getWorksheets()) {
- worksheet.getPageSetup().setIsPercentScale(false);
- worksheet.getPageSetup().setFitToPagesWide(1);
- }
- workbook.save(rootPath+index+"result.pdf");
- System.out.println("save pdf cost: "+(System.currentTimeMillis() - start)/1000.0);
- System.out.println("final cost: "+(System.currentTimeMillis() - start)/1000.0);
- }
- private static InputStream getFileStream(String filePath) throws FileNotFoundException {
- return new FileInputStream(filePath);
- }
- }
复制代码
请问我哪里设置有问题吗
|
|