这是我用GCEXCEL导出的方法,附件是excel的ss.json文件
- @Test
- public void previewPDFTest() {
- Workbook workbook = new Workbook();
- workbook.open("d:/ss.json");
- IWorksheet worksheet0 = workbook.getWorksheets().get(0);
- // 隐藏第一个sheet
- worksheet0.setVisible(Visibility.Hidden);
- IWorksheet contentSheet = workbook.getWorksheets().get("原始记录数据页");
- if (contentSheet != null) {
- contentSheet.setVisible(Visibility.Hidden);
- }
- IWorksheet patchSheet = workbook.getWorksheets().get("原始记录批量导入模板");
- if (patchSheet != null) {
- patchSheet.setVisible(Visibility.Hidden);
- }
- // 把证书基础sheet业移到第一页
- workbook.getWorksheets().get("证书信息").moveBefore(workbook.getWorksheets().get(0));
- // 证书页sheet
- IWorksheet sheet0 = workbook.getWorksheets().get(0);
- // 设置页眉页脚首页不同
- sheet0.getPageSetup().setDifferentFirstPageHeaderFooter(true);
- String cn = "RT";
- String ct = "1234567";
- double leftMargin = 50.5;
- double rightMargin = 50.5;
- String yearCHN = "一";
- String cHeader = "";
- String cFooter = "";
- String notice = "";
- String line = "—————————————————————————————————————————————";
- //证书模板页眉
- String lHeader = "&12&"黑体"证 书 编 号 " + cn + "字 " + ct + " 号\n&11&"Times New Roman"Certificate No.\n\n\n\n&11&"黑体"";
- String rHeader = "&12&"黑体"第 &P 页 共 &N 页\nPage of &12&"Times New Roman" ";
- sheet0.getPageSetup().setLeftMargin(leftMargin);
- sheet0.getPageSetup().setRightMargin(rightMargin);
- sheet0.getPageSetup().setLeftHeader(lHeader);
- sheet0.getPageSetup().setRightHeader(rHeader);
- List<Integer> jd = Arrays.asList(0, 1, 2, 3, 4, 8, 9, 10);//检定证书类型
- List<Integer> jz = Arrays.asList(5, 6, 11);//检测证书类型
- List<Integer> jc = Arrays.asList(7, 12);//校准证书类型
- notice = "&12&"宋体"敬告:1、被检定仪器修理后,请立即进行检定。\n 2、在使用过程中,如对被检定仪器的技术指标产生怀疑,请重新检定。\n";
- cHeader = "\n\n\n &18&"黑体"&B检 定 数 据 / 结 果\n&11&"黑体"Data / Results of Verification";
- cFooter = "&11&"黑体"" + line + "\n&12&"宋体"注:未经本院书面批准,不得部分复制此检定证书(整体复制除外)。\n" +
- "&12&"Times New Roman"" +
- "Note: This certificate of verification shall not be reproduced except in full, without the written\napproval of the laboratory.";
- sheet0.getPageSetup().setLeftFooter(cFooter);
- IWorksheet resultSheet = workbook.getWorksheets().get("证书结果页");
- resultSheet.getPageSetup().setFitToPagesWide(1);
- int FirstPageNumber = 3;
- resultSheet.getPageSetup().setFirstPageNumber(FirstPageNumber);
- resultSheet.getPageSetup().setLeftMargin(leftMargin);
- resultSheet.getPageSetup().setRightMargin(rightMargin);
- resultSheet.getPageSetup().setLeftHeader(lHeader + line);
- resultSheet.getPageSetup().setTopMargin(85);
- resultSheet.getPageSetup().setCenterHeader(cHeader);
- resultSheet.getPageSetup().setRightHeader(rHeader);
- resultSheet.getPageSetup().setLeftFooter(notice + cFooter);
- workbook.save("d:/test.pdf", SaveFileFormat.Pdf);
- }
复制代码 |
|