|
@@ -2646,56 +2646,53 @@ public class TaskController extends BladeController {
|
|
|
if(Func.isNotEmpty(rs.getData())){
|
|
|
PdfReader reader = null;
|
|
|
Document doc = new Document();
|
|
|
- PdfCopy pdfCopy;
|
|
|
- pdfCopy = new PdfCopy(doc, new FileOutputStream(rs.getPdfPath()));
|
|
|
+ PdfCopy pdfCopy = new PdfCopy(doc, new FileOutputStream(rs.getPdfPath()));
|
|
|
int pageCount;
|
|
|
doc.open();
|
|
|
String tile=rs.getName().contains("封面")?projectName:projectName+StringPool.DASH+rs.getName();
|
|
|
for(Map<String,Object> dataMap:rs.getData()){
|
|
|
- if (Func.isNotEmpty(dataMap)) {
|
|
|
- try {
|
|
|
- Workbook workbook = WorkbookFactory.create(new ByteArrayInputStream(excelByte));
|
|
|
- //获取工作表
|
|
|
- Sheet sheet = workbook.getSheetAt(0);
|
|
|
- sheet.setForceFormulaRecalculation(true);
|
|
|
- // 循环Key
|
|
|
+ try {
|
|
|
+ Workbook workbook = WorkbookFactory.create(new ByteArrayInputStream(excelByte));
|
|
|
+ //获取工作表
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ sheet.setForceFormulaRecalculation(true);
|
|
|
+ if(Func.isNotEmpty(dataMap)) {
|
|
|
for (String keys : dataMap.keySet()) {
|
|
|
int y1 = Func.toInt(keys.split("_")[0]);
|
|
|
int x1 = Func.toInt(keys.split("_")[1]);
|
|
|
- Row row = sheet.getRow(y1-1);
|
|
|
+ Row row = sheet.getRow(y1 - 1);
|
|
|
if (row != null) {
|
|
|
- Cell cell = row.getCell(x1-1);
|
|
|
- if(cell!=null) {
|
|
|
+ Cell cell = row.getCell(x1 - 1);
|
|
|
+ if (cell != null) {
|
|
|
cell.setCellValue(dataMap.getOrDefault(keys, StringPool.EMPTY).toString());
|
|
|
- }else{
|
|
|
- System.out.println(keys+"不存在");
|
|
|
+ } else {
|
|
|
+ System.out.println(keys + "不存在");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- /*设置表头*/
|
|
|
- setTitle(sheet,tile);
|
|
|
- /*输出到内存*/
|
|
|
- //去掉表格虚线
|
|
|
- sheet.setPrintGridlines(false);
|
|
|
- //设置 整个工作表为一页
|
|
|
- sheet.setFitToPage(true);
|
|
|
- sheet.getPrintSetup().setPaperSize(PrintSetup.A4_PAPERSIZE);
|
|
|
- ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
- workbook.write(out);
|
|
|
- workbook.write(new FileOutputStream(rs.getExcelPath()));
|
|
|
- com.aspose.cells.Workbook wb = new com.aspose.cells.Workbook( new ByteArrayInputStream(out.toByteArray()));
|
|
|
- out.reset();
|
|
|
- wb.save(out, SaveFormat.PDF);
|
|
|
- reader = new PdfReader(new ByteArrayInputStream(out.toByteArray()));
|
|
|
- pageCount = reader.getNumberOfPages();
|
|
|
- for (int i = 1; i <= pageCount; ++i) {
|
|
|
- pdfCopy.addPage(pdfCopy.getImportedPage(reader, i));
|
|
|
- }
|
|
|
- out.close();
|
|
|
- workbook.close();
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
}
|
|
|
+ /*设置表头*/
|
|
|
+ setTitle(sheet,tile);
|
|
|
+ //去掉表格虚线
|
|
|
+ sheet.setPrintGridlines(false);
|
|
|
+ //设置 整个工作表为一页
|
|
|
+ sheet.setFitToPage(true);
|
|
|
+ sheet.getPrintSetup().setPaperSize(PrintSetup.A4_PAPERSIZE);
|
|
|
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
+ workbook.write(out);
|
|
|
+ workbook.write(new FileOutputStream(rs.getExcelPath()));
|
|
|
+ com.aspose.cells.Workbook wb = new com.aspose.cells.Workbook( new ByteArrayInputStream(out.toByteArray()));
|
|
|
+ out.reset();
|
|
|
+ wb.save(out, SaveFormat.PDF);
|
|
|
+ reader = new PdfReader(new ByteArrayInputStream(out.toByteArray()));
|
|
|
+ pageCount = reader.getNumberOfPages();
|
|
|
+ for (int i = 1; i <= pageCount; ++i) {
|
|
|
+ pdfCopy.addPage(pdfCopy.getImportedPage(reader, i));
|
|
|
+ }
|
|
|
+ out.close();
|
|
|
+ workbook.close();
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
pdfCopy.flush();
|