From f2f1274c7b51671d6d3b0b503f229da4657484f2 Mon Sep 17 00:00:00 2001
From: fei <791364011@qq.com>
Date: 星期五, 19 十二月 2025 23:31:58 +0800
Subject: [PATCH] 修改了对应代码
---
/dev/null | 20 -
archiveManager/pom.xml | 20 +
archiveManager/src/main/java/com/ruoyi/service/impl/pdfGenerateService.java | 161 +++++---
ruoyi-admin/pom.xml | 22 +
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheet.java | 17
ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/archiveAllExportController.java | 568 +++++++++++++++++++++++++++++---
ruoyi-common/src/main/java/com/ruoyi/common/annotation/Excel.java | 7
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetSecond.java | 130 +++++-
archiveManager/src/main/java/com/ruoyi/domain/vo/DocumentMaterialsVoSmall.java | 14
ruoyi-admin/src/main/resources/license.xml | 12
ruoyi-common/pom.xml | 6
archiveManager/src/main/java/com/ruoyi/service/impl/BarcodeService.java | 2
12 files changed, 792 insertions(+), 187 deletions(-)
diff --git a/LICENSE b/LICENSE
deleted file mode 100644
index 8564f29..0000000
--- a/LICENSE
+++ /dev/null
@@ -1,20 +0,0 @@
-The MIT License (MIT)
-
-Copyright (c) 2018 RuoYi
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
diff --git a/archiveManager/pom.xml b/archiveManager/pom.xml
index d51a0d8..641b0f3 100644
--- a/archiveManager/pom.xml
+++ b/archiveManager/pom.xml
@@ -22,7 +22,27 @@
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-common</artifactId>
</dependency>
+
+
+
+<!-- <dependency>-->
+<!-- <groupId>com.aspose</groupId>-->
+<!-- <artifactId>aspose-cells</artifactId>-->
+<!-- <version>23.9</version>-->
+<!-- </dependency>-->
+
+ <!-- Aspose.Words锛圵ord 杞� PDF锛� -->
+<!-- <dependency>-->
+<!-- <groupId>com.aspose</groupId>-->
+<!-- <artifactId>aspose-words</artifactId>-->
+<!-- <version>18.9</version>-->
+<!-- </dependency>-->
+
+
<dependency>
+
+
+
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.5.1</version>
diff --git a/archiveManager/src/main/java/com/ruoyi/domain/vo/DocumentMaterialsVoSmall.java b/archiveManager/src/main/java/com/ruoyi/domain/vo/DocumentMaterialsVoSmall.java
index 7bb5bbc..936e316 100644
--- a/archiveManager/src/main/java/com/ruoyi/domain/vo/DocumentMaterialsVoSmall.java
+++ b/archiveManager/src/main/java/com/ruoyi/domain/vo/DocumentMaterialsVoSmall.java
@@ -11,25 +11,25 @@
public class DocumentMaterialsVoSmall {
- @Excel(name="搴忓彿",width = 5, headerColor = IndexedColors.BLACK, headerFontBold = true)
+ @Excel(name="搴忓彿",width = 5, headerFontSize=12, headerColor = IndexedColors.BLACK, headerFontBold = true)
private Long num;
- @Excel(name = "鏂囦欢缂栧彿",width = 10, headerColor = IndexedColors.BLACK, headerFontBold = true)
+ @Excel(name = "鏂囦欢缂栧彿",width = 10, headerFontSize=12,headerColor = IndexedColors.BLACK, headerFontBold = true)
private String documentNumber;
- @Excel(name = "璐d换鑰�",width = 10, headerColor = IndexedColors.BLACK, headerFontBold = true)
+ @Excel(name = "璐d换鑰�",width = 10, headerFontSize=12,headerColor = IndexedColors.BLACK, headerFontBold = true)
private String creator;
- @Excel(name = "鏂囦欢棰樺悕",width = 36, headerColor = IndexedColors.BLACK, headerFontBold = true)
+ @Excel(name = "鏂囦欢棰樺悕",width = 30, headerFontSize=12,headerColor = IndexedColors.BLACK, headerFontBold = true)
private String title;
@JsonFormat(pattern = "yyyy-MM-dd")
- @Excel(name = "鏃ユ湡", width = 12, dateFormat = "yyyy-MM-dd", headerColor = IndexedColors.BLACK, headerFontBold = true)
+ @Excel(name = "鏃ユ湡", width = 10, headerFontSize=12,dateFormat = "yyyy-MM-dd", headerColor = IndexedColors.BLACK, headerFontBold = true)
private Date date;
- @Excel(name = "椤靛彿",width = 10, headerColor = IndexedColors.BLACK, headerFontBold = true)
+ @Excel(name = "椤靛彿",width = 10, headerFontSize=12, headerColor = IndexedColors.BLACK, headerFontBold = true)
private Long pageNumber;
- @Excel(name = "澶囨敞",width = 10, headerColor = IndexedColors.BLACK, headerFontBold = true)
+ @Excel(name = "澶囨敞",width = 8, headerFontSize=12,headerColor = IndexedColors.BLACK, headerFontBold = true)
private String remarks;
public DocumentMaterialsVoSmall(Long num, String documentNumber, String creator, String title, Date date, Long pageNumber, String remarks) {
diff --git a/archiveManager/src/main/java/com/ruoyi/service/impl/BarcodeService.java b/archiveManager/src/main/java/com/ruoyi/service/impl/BarcodeService.java
index 29255b6..cf7f999 100644
--- a/archiveManager/src/main/java/com/ruoyi/service/impl/BarcodeService.java
+++ b/archiveManager/src/main/java/com/ruoyi/service/impl/BarcodeService.java
@@ -16,7 +16,7 @@
Code128Bean barcodeGenerator = new Code128Bean();
final int dpi = 160;
barcodeGenerator.setModuleWidth(0.21);
- barcodeGenerator.setBarHeight(4.0); // 璁剧疆鏉″舰鐮侀珮搴︿负64
+ barcodeGenerator.setBarHeight(8.0); // 璁剧疆鏉″舰鐮侀珮搴︿负64
barcodeGenerator.doQuietZone(false);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
diff --git a/archiveManager/src/main/java/com/ruoyi/service/impl/pdfGenerateService.java b/archiveManager/src/main/java/com/ruoyi/service/impl/pdfGenerateService.java
index d8cc7b7..1a927a9 100644
--- a/archiveManager/src/main/java/com/ruoyi/service/impl/pdfGenerateService.java
+++ b/archiveManager/src/main/java/com/ruoyi/service/impl/pdfGenerateService.java
@@ -267,62 +267,76 @@
}
- // 鑷畾涔夐〉闈簨浠剁被锛岀敤浜庡湪姣忎釜鏂伴〉闈㈡坊鍔犲嵎鍐呭皝闈㈠唴瀹�
+ // 鑷畾涔夐〉闈簨浠剁被锛岀敤浜庡湪姣忎釜鏂伴〉闈㈡坊鍔犲嵎鍐呭皝闈㈠拰鍗峰彿
private class DirectoryHeaderPageEvent extends PdfPageEventHelper {
private String volumeNumber;
- private byte[] barcodeImageBytes;
+ private BaseFont bfChinese;
+ private Font chineseFont;
+ private Font chineseFont1;
+ private Image barcodeImage;
- public DirectoryHeaderPageEvent(String volumeNumber, byte[] barcodeImageBytes) {
+ public DirectoryHeaderPageEvent(String volumeNumber, BaseFont bfChinese, Font chineseFont, Font chineseFont1, Image barcodeImage) {
this.volumeNumber = volumeNumber;
- this.barcodeImageBytes = barcodeImageBytes;
+ this.bfChinese = bfChinese;
+ this.chineseFont = chineseFont;
+ this.chineseFont1 = chineseFont1;
+ this.barcodeImage = barcodeImage;
}
@Override
public void onStartPage(PdfWriter writer, Document document) {
try {
- // 璁剧疆涓枃瀛椾綋
- BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
- Font chineseFont = new Font(bfChinese, 12);
- Font chineseFont1 = new Font(bfChinese, 16, Font.BOLD);
+ PdfContentByte cb = writer.getDirectContent();
+ float pageWidth = document.getPageSize().getWidth();
+ float pageHeight = document.getPageSize().getHeight();
- // 娣诲姞鏉″舰鐮�
- Image img = Image.getInstance(barcodeImageBytes);
- PdfPCell pdfPCell = new PdfPCell(img);
- pdfPCell.setBorder(Rectangle.NO_BORDER);
- pdfPCell.setMinimumHeight(40);
- pdfPCell.setUseAscender(true);
- pdfPCell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
- pdfPCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
- pdfPCell.setColspan(2);
- pdfPCell.setPaddingBottom(30);
+ // 1. 娣诲姞鏉″舰鐮侊紙灞呬腑鏄剧ず锛岄〉闈㈤《閮級
+ float barcodeWidth = barcodeImage.getScaledWidth();
+ float barcodeHeight = barcodeImage.getScaledHeight();
+ float barcodeX = (pageWidth - barcodeWidth) / 2;
+ float barcodeY = pageHeight - 50 - barcodeHeight; // 椤甸潰椤堕儴涓嬫柟50鐐�
+ barcodeImage.setAbsolutePosition(barcodeX, barcodeY);
+ cb.addImage(barcodeImage);
- float[] columnWidths1 = {35f, 65f};
- PdfPTable table1 = new PdfPTable(columnWidths1);
- table1.setWidthPercentage(80);
- table1.setHorizontalAlignment(Element.ALIGN_LEFT);
- table1.setSpacingBefore(30f);
- table1.addCell(pdfPCell);
+ // 2. 娣诲姞鍗峰唴鐩綍鏍囬锛堝眳涓樉绀猴紝鏉″舰鐮佷笅鏂癸級
+ String title = "鍗� 鍐� 鐩� 褰�";
+ float titleX = pageWidth / 2;
+ float titleY = pageHeight - 100; // 椤甸潰椤堕儴涓嬫柟100鐐�
+ cb.beginText();
+ // 鍒涘缓骞惰缃爣棰樹负鍔犵矖瀛椾綋
+ Font boldTitleFont = new Font(bfChinese, 16, Font.BOLD);
+ cb.setFontAndSize(boldTitleFont.getBaseFont(), boldTitleFont.getSize());
+ cb.setColorFill(BaseColor.BLACK);
+ cb.showTextAligned(PdfContentByte.ALIGN_CENTER, title, titleX, titleY, 0);
+ cb.endText();
- PdfContentByte canvas = writer.getDirectContent();
- ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(" ", chineseFont),
- document.left(), document.top() - 50, 0);
- document.add(table1);
+ // 3. 娣诲姞鍗峰彿锛堝眳鍙虫樉绀猴紝鏍囬涓嬫柟锛�
+ String label = "鍗峰彿锛�";
+ String value = volumeNumber;
+ float recordInfoX = pageWidth - 30;
+ float recordInfoY = pageHeight - 130; // 椤甸潰椤堕儴涓嬫柟130鐐�
- // 娣诲姞鏍囬
- Paragraph title = new Paragraph("鍗� 鍐� 鐩� 褰�", chineseFont1);
- title.setAlignment(Element.ALIGN_CENTER);
- document.add(title);
- Paragraph withNewLine = new Paragraph("\n");
- document.add(withNewLine);
- document.add(withNewLine);
+ // 鍏堢粯鍒舵爣绛�"鍗峰彿锛�"
+ cb.beginText();
+ // 璁剧疆鍔犵矖瀛椾綋锛岄�氳繃Font.BOLD鍙傛暟
+ Font boldFont = new Font(bfChinese, 16, Font.BOLD);
+ cb.setFontAndSize(boldFont.getBaseFont(), boldFont.getSize());
+ cb.setColorFill(BaseColor.BLACK);
+ cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, label + value, recordInfoX, recordInfoY, 0);
+ cb.endText();
- // 娣诲姞鍗峰彿
- Paragraph recordInfo = new Paragraph("鍗峰彿锛�" + volumeNumber, chineseFont);
- recordInfo.setAlignment(Element.ALIGN_RIGHT);
- document.add(recordInfo);
+ // 璁$畻鍊肩殑浣嶇疆骞剁粯鍒朵笅鍒掔嚎
+ float labelWidth = bfChinese.getWidthPoint(label, 12);
+ float valueWidth = bfChinese.getWidthPoint(value, 12);
+ float underlineStartX = recordInfoX - valueWidth;
+ float underlineEndX = recordInfoX;
+ float underlineY = recordInfoY - 2;
- document.add(withNewLine);
- document.add(withNewLine);
+ cb.setColorStroke(BaseColor.BLACK);
+ cb.setLineWidth(0.5f);
+ cb.moveTo(underlineStartX, underlineY);
+ cb.lineTo(underlineEndX, underlineY);
+ cb.stroke();
} catch (Exception e) {
e.printStackTrace();
@@ -335,27 +349,44 @@
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(pdfPath));
- // 娣诲姞椤甸潰浜嬩欢锛屽湪姣忎釜鏂伴〉闈㈣嚜鍔ㄦ坊鍔犲嵎鍐呭皝闈㈠唴瀹�
- String volumeNumber = dvss.get(0).getRecordId();
- byte[] barcodeImageBytes = barcodeService.generateBarcodeImage(volumeNumber);
- writer.setPageEvent(new DirectoryHeaderPageEvent(volumeNumber, barcodeImageBytes));
-
- document.open();
-
- // 鍒涘缓琛ㄦ牸锛�5鍒楋級
- PdfPTable table = new PdfPTable(7);
-
- // 璁剧疆琛ㄦ牸瀹藉害锛堝崰椤甸潰瀹藉害鐨�100%锛�
- table.setWidthPercentage(100);
-
- // 璁剧疆鍒楀姣斾緥锛岀4鍒楋紙鏂囦欢棰樺悕锛夎缃緱鏇村
- float[] columnWidths = {8f, 14f, 12f, 30f, 10f, 10f, 10f}; // 璋冩暣鍒楀姣斾緥锛岀4鍒楁枃浠堕鍚嶅崰40%
- table.setWidths(columnWidths);
-
// 璁剧疆涓枃瀛椾綋
BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
Font chineseFont = new Font(bfChinese, 12);
Font chineseFont1 = new Font(bfChinese, 16, Font.BOLD);
+
+ // 鑾峰彇鍗峰彿
+ String volumeNumber = dvss.get(0).getRecordId();
+
+ // 鍒涘缓鏉″舰鐮�
+ Image barcodeImage = Image.getInstance(barcodeService.generateBarcodeImage(volumeNumber));
+ barcodeImage.scaleToFit(80, 40); // 璁剧疆鏉″舰鐮佸ぇ灏�
+
+ // 娉ㄥ唽椤甸潰浜嬩欢
+ DirectoryHeaderPageEvent pageEvent = new DirectoryHeaderPageEvent(volumeNumber, bfChinese, chineseFont1, chineseFont1, barcodeImage);
+ writer.setPageEvent(pageEvent);
+
+ // 璁剧疆閫傚綋鐨勮竟璺濓紝涓哄嵎鍐呭皝闈€�佹潯褰㈢爜鍜屽嵎鍙烽鐣欑┖闂�
+ // setMargins(left, right, top, bottom) - 鍙傛暟椤哄簭锛氬乏銆佸彸銆佷笂銆佷笅
+ // 澧炲ぇ涓婅竟璺濅负160锛岀‘淇濋〉鐪夊唴瀹规湁瓒冲绌洪棿
+ document.setMargins(30, 30, 160, 30);
+ document.open();
+
+ // 杩欓噷涓嶅啀闇�瑕佸湪绗竴椤垫墜鍔ㄦ坊鍔犲嵎鍐呭皝闈㈠唴瀹癸紝椤甸潰浜嬩欢浼氬鐞�
+
+ // 娣诲姞涓�涓┖鐧芥钀斤紝纭繚琛ㄦ牸鍐呭涓嶄細涓庨《閮ㄥ厓绱犻噸鍙�
+ Paragraph blankParagraph = new Paragraph("");
+ document.add(blankParagraph);
+
+ // 鍒涘缓琛ㄦ牸锛�7鍒楋級
+ PdfPTable table = new PdfPTable(7);
+
+ // 璁剧疆琛ㄦ牸瀹藉害锛堝崰椤甸潰瀹藉害鐨�80%锛屽眳涓樉绀猴級
+ table.setWidthPercentage(90);
+ table.setHorizontalAlignment(Element.ALIGN_CENTER);
+
+ // 璁剧疆鍒楀姣斾緥锛岀4鍒楋紙鏂囦欢棰樺悕锛夊拰绗�2鍒楋紙鏂囦欢缂栧彿锛夎缃緱鏇村
+ float[] columnWidths = {10f, 16f, 14f, 30f, 10f, 10f, 10f}; // 璋冩暣鍒楀姣斾緥锛屽鍔犳枃浠剁紪鍙峰垪鐨勫搴�
+ table.setWidths(columnWidths);
// 璁剧疆琛ㄥご琛屾暟锛岃繖鏍峰垎椤垫椂姣忛〉閮戒細鑷姩閲嶅琛ㄥご
table.setHeaderRows(1);
@@ -386,9 +417,9 @@
table.addCell(cell);
- //搴忓彿
+ //鏂囦欢缂栧彿锛堟。鍙凤級
PdfPCell cell1 = new PdfPCell(new Paragraph(cellData.getDocumentNumber()==null?"":cellData.getDocumentNumber().toString(),
- chineseFont));
+ new Font(bfChinese, 12)));
cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
@@ -470,7 +501,15 @@
// 娣诲姞鍐呭
// String volumeNumber = "D3.4.1-05-2024-0002";
- Paragraph recordInfo = new Paragraph("鍗峰彿锛�" + volumeNumber, chineseFont);
+
+ // 鍒涘缓鍗峰彿娈佃惤锛屼娇鐢–hunk鏉ュ崟鐙鐞嗗嵎鍙峰�煎苟娣诲姞涓嬪垝绾�
+ Paragraph recordInfo = new Paragraph();
+ Chunk labelChunk = new Chunk("鍗峰彿锛�", chineseFont);
+ Chunk valueChunk = new Chunk(volumeNumber, chineseFont);
+ valueChunk.setUnderline(0.5f, -2f); // 娣诲姞涓嬪垝绾匡紝0.5f鏄嚎瀹斤紝-2f鏄嚎涓庢枃瀛楃殑璺濈
+
+ recordInfo.add(labelChunk);
+ recordInfo.add(valueChunk);
recordInfo.setAlignment(Element.ALIGN_RIGHT);
document.add(recordInfo);
int pcc = dmfs.size()<=1?0: dmfs.get(1).getCnt();
diff --git a/ruoyi-admin/pom.xml b/ruoyi-admin/pom.xml
index 37417c9..e6a092d 100644
--- a/ruoyi-admin/pom.xml
+++ b/ruoyi-admin/pom.xml
@@ -17,6 +17,28 @@
<dependencies>
+ <!-- Poi-tl Word 妯℃澘寮曟搸-->
+ <dependency>
+ <groupId>com.deepoove</groupId>
+ <artifactId>poi-tl</artifactId>
+ <version>1.9.1</version>
+ </dependency>
+ <dependency>
+ <groupId>com.aspose</groupId>
+ <artifactId>aspose-cells</artifactId>
+ <version>8.5.2</version>
+ <scope>system</scope>
+ <systemPath>${project.basedir}/libs/aspose-cells-8.5.2.jar</systemPath>
+ </dependency>
+ <dependency>
+ <groupId>com.aspose</groupId>
+ <artifactId>aspose-words</artifactId>
+ <version>14.9.0</version>
+ <scope>system</scope>
+ <systemPath>${project.basedir}/libs/aspose-words-14.9.0-jdk16.jar</systemPath>
+ </dependency>
+
+
<!-- spring-boot-devtools -->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/archiveAllExportController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/archiveAllExportController.java
index 039f191..33e0958 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/archiveAllExportController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/archiveAllExportController.java
@@ -1,29 +1,24 @@
package com.ruoyi.web.controller.archive;
+import com.aspose.cells.PdfCompliance;
+import com.aspose.words.License;
+import com.deepoove.poi.XWPFTemplate;
import com.itextpdf.text.*;
-import com.itextpdf.text.Font;
-import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
-import com.itextpdf.text.pdf.PdfPTable;
-import com.itextpdf.text.pdf.PdfWriter;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.common.utils.poi.*;
import com.ruoyi.domain.ArchiveRecords;
import com.ruoyi.domain.DocumentMaterials;
import com.ruoyi.domain.vo.*;
-import com.ruoyi.framework.web.domain.server.Sys;
import com.ruoyi.service.IArchiveRecordsService;
import com.ruoyi.service.IDocumentMaterialsService;
import com.ruoyi.service.impl.BarcodeService;
import com.ruoyi.service.impl.pdfGenerateService;
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;
-import org.apache.poi.hssf.usermodel.HSSFCell;
-import org.apache.poi.hssf.usermodel.HSSFDateUtil;
-import org.apache.poi.ss.usermodel.*;
-import org.apache.poi.ss.util.CellUtil;
-import org.apache.poi.xssf.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@@ -33,26 +28,18 @@
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
-import java.lang.reflect.Field;
-import java.net.URLEncoder;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
-import java.util.Date;
+import java.util.*;
import java.util.List;
-import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
-import static org.apache.poi.hssf.usermodel.HSSFCell.*;
+// 瀵煎叆ByteArrayOutputStream鐢ㄤ簬涓存椂瀛樺偍PDF鏁版嵁
+import java.io.ByteArrayOutputStream;
@RestController
@RequestMapping("/system/archiveAllExport")
@@ -85,13 +72,256 @@
}
}
+ public boolean getLicense() {
+ boolean result = false;
+ try {
+ InputStream is = null;
+
+ ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
+ org.springframework.core.io.Resource[] resources = resolver.getResources("classpath:words.xml");
+ is = resources[0].getInputStream();
+ // 锟斤拷目锟斤拷lincense.xml锟斤拷路锟斤拷
+ License aposeLic = new License();
+ aposeLic.setLicense(is);
+ result = true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return result;
+ }
+
+ public boolean getLicenseExcel() {
+ boolean result = false;
+ InputStream is = null;
+ try {
+ ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
+ org.springframework.core.io.Resource[] resources = resolver.getResources("classpath:license.xml");
+ is = resources[0].getInputStream();
+ com.aspose.cells.License aposeLic = new com.aspose.cells.License();
+ aposeLic.setLicense(is);
+ result = true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * 灏咵xcel鎸囧畾瀛恠heet杞崲涓篜DF骞朵笅杞�
+ * @param response 鍝嶅簲瀵硅薄
+ * @param excelPath Excel鏂囦欢璺緞
+ * @param sheetName 瀛恠heet鍚嶇О
+ * @throws Exception 寮傚父淇℃伅
+ */
+ @PostMapping("/exportSheetToPdf")
+ public void exportSheetToPdf(HttpServletResponse response, String excelPath, String sheetName) throws Exception {
+ // 璁剧疆鍝嶅簲澶�
+ response.setContentType(MediaType.APPLICATION_PDF_VALUE);
+ response.setHeader("Content-Disposition", "attachment; filename=sheet.pdf");
+
+ try {
+ // 浣跨敤Aspose.Cells璇诲彇Excel鏂囦欢
+ com.aspose.cells.Workbook wb = new com.aspose.cells.Workbook(excelPath);
+
+ // 鑾峰彇鎸囧畾鍚嶇О鐨勫瓙sheet
+ com.aspose.cells.Worksheet sheet = wb.getWorksheets().get(sheetName);
+
+ // 濡傛灉闇�瑕佽幏鍙栫储寮曟柟寮忕殑瀛恠heet锛屽彲浠ヤ娇鐢ㄤ互涓嬩唬鐮�
+ // com.aspose.cells.Worksheet sheet = wb.getWorksheets().get(0); // 鑾峰彇绗竴涓猻heet
+
+ // 鍒涘缓涓�涓柊鐨刉orkbook锛屽彧鍖呭惈鎸囧畾鐨剆heet
+ com.aspose.cells.Workbook newWorkbook = new com.aspose.cells.Workbook();
+ newWorkbook.getWorksheets().clear();
+ newWorkbook.getWorksheets().addCopy(sheet.getName());
+
+ // 灏咵xcel杞崲涓篜DF瀛楄妭鏁扮粍
+ java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
+ newWorkbook.save(baos, com.aspose.cells.SaveFormat.PDF);
+ byte[] pdfBytes = baos.toByteArray();
+ // 灏哖DF杈撳嚭鍒板搷搴旀祦
+ try (ServletOutputStream os = response.getOutputStream()) {
+ os.write(pdfBytes);
+ os.flush();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+ /**
+ * 灏咵xcel鎵�鏈夊瓙sheet杞崲涓篜DF骞舵墦鍖呬笅杞�
+ * @param response 鍝嶅簲瀵硅薄
+ * @param excelPath Excel鏂囦欢璺緞
+ * @throws Exception 寮傚父淇℃伅
+ */
+ @PostMapping("/exportAllSheetsToPdf")
+ public void exportAllSheetsToPdf(HttpServletResponse response, String excelPath) throws Exception {
+ // 璁剧疆鍝嶅簲澶�
+ response.setContentType("application/zip");
+ response.setHeader("Content-Disposition", "attachment; filename=all_sheets.zip");
+
+ try (ServletOutputStream os = response.getOutputStream();
+ ZipOutputStream zos = new ZipOutputStream(os)) {
+
+ // 浣跨敤Aspose.Cells璇诲彇Excel鏂囦欢
+ com.aspose.cells.Workbook wb = new com.aspose.cells.Workbook(excelPath);
+
+ // 鑾峰彇鎵�鏈塻heet
+ com.aspose.cells.WorksheetCollection sheets = wb.getWorksheets();
+
+ // 閬嶅巻鎵�鏈塻heet
+ for (int i = 0; i < sheets.getCount(); i++) {
+ com.aspose.cells.Worksheet sheet = sheets.get(i);
+ String sheetName = sheet.getName();
+
+ // 鍒涘缓涓�涓柊鐨刉orkbook锛屽彧鍖呭惈褰撳墠sheet
+ com.aspose.cells.Workbook newWorkbook = new com.aspose.cells.Workbook();
+ newWorkbook.getWorksheets().clear();
+ newWorkbook.getWorksheets().addCopy(sheet.getName());
+
+ // 鍒涘缓涓存椂瀛楄妭杈撳嚭娴�
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ // 灏嗘柊鐨刉orkbook淇濆瓨涓篜DF鍒颁复鏃舵祦
+ newWorkbook.save(baos, com.aspose.cells.SaveFormat.PDF);
+ byte[] pdfBytes = baos.toByteArray();
+
+ // 鑾峰彇PDF鎬婚〉鏁�
+
+ // 灏哖DF娣诲姞鍒癦IP鏂囦欢
+ ZipEntry entry = new ZipEntry(sheetName + ".pdf");
+ zos.putNextEntry(entry);
+ zos.write(pdfBytes);
+ zos.closeEntry();
+
+ System.out.println("Excel瀛恠heet \"" + sheetName + "\" 杞崲涓篜DF鎴愬姛");
+ }
+
+ System.out.println("Excel鎵�鏈夊瓙sheet杞崲涓篜DF骞舵墦鍖呮垚鍔�");
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw e;
+ }
+ }
@PostMapping("/importTemplate")
public void importTemplate(HttpServletResponse response) throws IOException
{
+
+
+ if (!getLicense()) {
+ return;
+ }
+
+ try {
+
+ // 鑾峰彇 Word 妯℃澘鎵�鍦ㄨ矾寰�
+ String filepath = "09-澶囪�冭〃.docx";
+ // 閫氳繃 XWPFTemplate 缂栬瘧鏂囦欢骞舵覆鏌撴暟鎹埌妯℃澘涓�
+ XWPFTemplate template = XWPFTemplate.compile(filepath).render(
+ new HashMap<String, Object>(){{
+ put("pages", 67);
+
+ }});
+
+ String renderedDocPath = "rendered_output.docx";
+ File renderedFile = new File(renderedDocPath);
+
+
+
+ try {
+ // 灏嗗畬鎴愭暟鎹覆鏌撶殑鏂囨。鍐欏嚭
+ template.writeAndClose(new FileOutputStream(renderedFile));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+
+ File file = new File("test1.pdf");
+ FileOutputStream os = new FileOutputStream(file);
+ com.aspose.words.Document doc = new com.aspose.words.Document("rendered_output.docx");
+
+ doc.save(os, com.aspose.words.SaveFormat.PDF);//全锟斤拷支锟斤拷DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 锟洁互转锟斤拷
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+
+ if (!getLicenseExcel()) {
+ System.out.println("鎺堟潈澶辫触");
+ return ;
+ }
+ String inpath= "妗堝嵎灏侀潰.xls";
+ long old = System.currentTimeMillis();
+
+ // 璁剧疆鍝嶅簲澶�
+ response.setContentType("application/pdf");
+ response.setHeader("Content-Disposition", "attachment; filename=import_template.pdf");
+
+ try {
+ // 璇诲彇Excel鏂囦欢
+ com.aspose.cells.Workbook wb = new com.aspose.cells.Workbook(inpath);
+
+ // 鑾峰彇闇�瑕佸鍑虹殑sheet锛堢储寮曚粠0寮�濮嬶級
+ int targetSheetIndex = 1;
+ com.aspose.cells.Worksheet targetSheet = wb.getWorksheets().get(targetSheetIndex);
+ targetSheet.autoFitRows(true);
+ System.out.println("褰撳墠sheet鍚嶇О锛�" + targetSheet.getName());
+ System.out.println("褰撳墠sheet绱㈠紩锛�" + targetSheet.getIndex());
+
+ // 闅愯棌鎵�鏈夊叾浠栧伐浣滆〃
+ for (int i = 0; i < wb.getWorksheets().getCount(); i++) {
+ if (i != targetSheetIndex) {
+ wb.getWorksheets().get(i).setVisible(false);
+ }
+ }
+
+ // 璁剧疆娲诲姩宸ヤ綔琛ㄤ负鐩爣宸ヤ綔琛�
+ wb.getWorksheets().setActiveSheetIndex(targetSheetIndex);
+
+ // 鍒涘缓PDF淇濆瓨閫夐」
+ com.aspose.cells.PdfSaveOptions pdfSaveOptions = new com.aspose.cells.PdfSaveOptions();
+
+ // 璁剧疆椤甸潰绫诲瀷涓篈4
+
+
+ // 纭繚鎵�鏈夊垪鍦ㄤ竴椤典笂
+ pdfSaveOptions.setAllColumnsInOnePagePerSheet(true);
+
+ // 璁剧疆鎵撳嵃椤甸潰绫诲瀷涓洪粯璁�
+ pdfSaveOptions.setCompliance(PdfCompliance.PDF_A_1_B); // 璁剧疆 PDF 鍏煎鎬ф爣鍑�
+
+ // 鐩存帴灏嗗師濮嬪伐浣滅翱淇濆瓨涓篜DF锛堝彧鍖呭惈鍙鐨勫伐浣滆〃锛�
+ wb.save(response.getOutputStream(), pdfSaveOptions);
+
+ long now = System.currentTimeMillis();
+ System.out.println("pdf杞崲鎴愬姛锛屽叡鑰楁椂锛�" + ((now - old) / 1000.0) + "绉�");
+ } catch (Exception e) {
+ e.printStackTrace();
+ // 鎵撳嵃璇︾粏閿欒淇℃伅
+ System.err.println("杞崲澶辫触锛�" + e.getMessage());
+ e.printStackTrace(System.err);
+
+ // 杩斿洖閿欒淇℃伅
+ response.reset();
+ response.setContentType("text/plain;charset=utf-8");
+ response.getWriter().write("瀵煎嚭澶辫触锛�" + e.getMessage());
+ response.getWriter().flush();
+ }
+
//瀵煎嚭鍗烽潰灏侀潰浠g爜
ArchiveInfoVo aIV = iArchiveRecordsService.selectByRecordId(55L);
@@ -299,6 +529,9 @@
}
//09-澶囪�冭〃.pdf
String pdf09Path = "09-澶囪�冭〃.pdf";
+
+
+
pdfGenerateService.generateFileStyleInfo(pdf09Path, aIV.getRecordId(), ids[i]);
// 2. 鍘嬬缉PDF鍒癦IP鏂囦欢
// 娣诲姞PDF鏂囦欢鍒癦IP
@@ -549,6 +782,29 @@
}
+ public com.aspose.cells.Workbook poiToAspose(org.apache.poi.ss.usermodel.Workbook poiWorkbook) throws Exception {
+ // 涓存椂鏂囦欢璺緞
+ String tempFilePath = "temp_workbook.xlsx";
+
+ try {
+ // 1. 灏咥pache POI Workbook淇濆瓨涓轰复鏃舵枃浠�
+ try (FileOutputStream fos = new FileOutputStream(tempFilePath)) {
+ poiWorkbook.write(fos);
+ }
+
+ // 2. 浣跨敤Aspose鍔犺浇涓存椂鏂囦欢
+ com.aspose.cells.Workbook asposeWorkbook = new com.aspose.cells.Workbook(tempFilePath);
+
+ return asposeWorkbook;
+
+ } finally {
+ // 娓呯悊涓存椂鏂囦欢
+ File tempFile = new File(tempFilePath);
+ if (tempFile.exists()) {
+ tempFile.delete();
+ }
+ }
+ }
@@ -597,53 +853,99 @@
//鍘嬬缉鏂囦欢
zos = new ZipOutputStream(os);
- //pdf鐩綍灏侀潰
- String pdfPathF = "07-妗堝嵎灏侀潰.pdf";
- pdfGenerateService.generatePdf(pdfPathF, id);
- // 2. 鍘嬬缉PDF鍒癦IP鏂囦欢
- // 娣诲姞PDF鏂囦欢鍒癦IP
- ZipEntry zipEntry = new ZipEntry(pdfPathF);
- zos.putNextEntry(zipEntry);
- // 璇诲彇PDF鏂囦欢鍐呭骞跺啓鍏IP
- try (FileInputStream fis = new FileInputStream(pdfPathF)) {
- byte[] buffer = new byte[1024];
- int len;
- while ((len = fis.read(buffer)) > 0) {
- zos.write(buffer, 0, len);
- }
- }
- //08-鍗峰唴鍗峰唴鐩綍鐨刾df
- String pdf08Path= "08-鍗峰唴鐩綍.pdf";
- List<DocumentMaterialsVo> list3 = dsvs;
- pdfGenerateService.generateFileDirectoryPdf(pdf08Path, list3);
- ZipEntry zipEntry2 = new ZipEntry(pdf08Path);
- zos.putNextEntry(zipEntry2);
- // 璇诲彇PDF鏂囦欢鍐呭骞跺啓鍏IP
- try (FileInputStream fis = new FileInputStream(pdf08Path)) {
- byte[] buffer = new byte[1024];
- int len;
- while ((len = fis.read(buffer)) > 0) {
- zos.write(buffer, 0, len);
- }
- }
//09-澶囪�冭〃.pdf
String pdf09Path = "09-澶囪�冭〃.pdf";
- pdfGenerateService.generateFileStyleInfo(pdf09Path, aIV.getRecordId(), id);
- // 2. 鍘嬬缉PDF鍒癦IP鏂囦欢
- // 娣诲姞PDF鏂囦欢鍒癦IP
- ZipEntry zipEntry1 = new ZipEntry(pdf09Path);
- zos.putNextEntry(zipEntry1);
+ // pdfGenerateService.generateFileStyleInfo(pdf09Path, aIV.getRecordId(), id);
+ //鎷垮埌鐩稿叧鏁版嵁
+ List<DocumentMaterialFileStyle> dmfs = documentMaterialsService.findFileStyleInfo(Math.toIntExact(id));
- // 璇诲彇PDF鏂囦欢鍐呭骞跺啓鍏IP
- try (FileInputStream fis = new FileInputStream(pdf09Path)) {
- byte[] buffer = new byte[1024];
- int len;
- while ((len = fis.read(buffer)) > 0) {
- zos.write(buffer, 0, len);
- }
+ LocalDate currentDate = LocalDate.now();
+
+
+ String cdt = currentDate.getYear()+"骞�"+currentDate.getMonthValue()+"鏈�"+currentDate.getDayOfMonth()+"鏃�";
+
+ HashMap<String, Object> hs = new HashMap<String, Object>();
+ if(dmfs.isEmpty())
+ {
+ //鍏ㄩ儴鏁版嵁鍊间负0
+ hs.put("pages", 0);
+ hs.put("volumeNumber", aIV.getRecordId());
+ hs.put("time", cdt);
+
}
+ else {
+ int pcc = dmfs.size()<=1?0: dmfs.get(1).getCnt();
+ int oth = dmfs.size()<=2?0: dmfs.get(2).getCnt();
+ int allCnt = dmfs.get(0).getCnt() + pcc + oth;
+ hs.put("pages", allCnt);
+ hs.put("volumeNumber", aIV.getRecordId());
+ hs.put("time", cdt);
+
+ }
+ if (!getLicense()) {
+ System.out.println("娌℃湁鐩稿叧璇佷功锛�");
+ }
+
+
+ try {
+
+ // 鑾峰彇 Word 妯℃澘鎵�鍦ㄨ矾寰�
+ String filepath = "09-澶囪�冭〃.docx";
+ // 閫氳繃 XWPFTemplate 缂栬瘧鏂囦欢骞舵覆鏌撴暟鎹埌妯℃澘涓�
+ XWPFTemplate template = XWPFTemplate.compile(filepath).render(hs
+ );
+
+ String renderedDocPath = "rendered_output.docx";
+ File renderedFile = new File(renderedDocPath);
+ try {
+ // 灏嗗畬鎴愭暟鎹覆鏌撶殑鏂囨。鍐欏嚭
+ template.writeAndClose(new FileOutputStream(renderedFile));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ com.aspose.words.Document doc = new com.aspose.words.Document("rendered_output.docx");
+ // 鍒涘缓涓存椂瀛楄妭杈撳嚭娴�
+ ByteArrayOutputStream baobk = new ByteArrayOutputStream();
+
+ // 灏哤ord鏂囨。杞崲涓篜DF瀛楄妭鏁扮粍
+ doc.save(baobk, com.aspose.words.SaveFormat.PDF);//全锟斤拷支锟斤拷DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 锟洁互转锟斤拷
+// byte[] pdfBytes = baobk.toByteArray();
+
+ // 鑾峰彇PDF鎬婚〉鏁�
+
+
+ // 灏哖DF娣诲姞鍒癦IP鏂囦欢
+ ZipEntry entry09 = new ZipEntry(pdf09Path);
+ zos.putNextEntry(entry09);
+ baobk.writeTo(zos);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+
+
+ com.aspose.words.Document doc = new com.aspose.words.Document("09-澶囪�冭〃.docx");
+
+
+
+
+
+// // 鍘嬬缉PDF鍒癦IP鏂囦欢
+// // 娣诲姞PDF鏂囦欢鍒癦IP
+// ZipEntry zipEntry1 = new ZipEntry(pdf09Path);
+// zos.putNextEntry(zipEntry1);
+//
+// // 璇诲彇PDF鏂囦欢鍐呭骞跺啓鍏IP
+// try (FileInputStream fis = new FileInputStream(pdf09Path)) {
+// byte[] buffer = new byte[1024];
+// int len;
+// while ((len = fis.read(buffer)) > 0) {
+// zos.write(buffer, 0, len);
+// }
+// }
@@ -670,14 +972,72 @@
// System.out.println(bos2);
zos.putNextEntry(entryiv);
-// ExcelUtil<ArchiveInfoVo> utilsv = new ExcelUtil<ArchiveInfoVo>(ArchiveInfoVo.class);
-//
+ bos2.writeTo(zos);
+
+
+ //pdf鐩綍灏侀潰
+ String pdfPathF = "07-妗堝嵎灏侀潰.pdf";
+ // pdfGenerateService.generatePdf(pdfPathF, id);
+
+ try {
+ if (!getLicenseExcel()) {
+ System.out.println("鎺堟潈澶辫触");
+ // return ;
+ }
+ // 璇诲彇Excel鏂囦欢
+ com.aspose.cells.Workbook wb = poiToAspose(util3.getWb());
+
+ // 鑾峰彇闇�瑕佸鍑虹殑sheet锛堢储寮曚粠0寮�濮嬶級
+ int targetSheetIndex = 1;
+ com.aspose.cells.Worksheet targetSheet = wb.getWorksheets().get(targetSheetIndex);
+ targetSheet.autoFitRows(true);
+ System.out.println("褰撳墠sheet鍚嶇О锛�" + targetSheet.getName());
+ System.out.println("褰撳墠sheet绱㈠紩锛�" + targetSheet.getIndex());
+
+ // 闅愯棌鎵�鏈夊叾浠栧伐浣滆〃
+ for (int i = 0; i < wb.getWorksheets().getCount(); i++) {
+ if (i != targetSheetIndex) {
+ wb.getWorksheets().get(i).setVisible(false);
+ }
+ }
+
+ // 璁剧疆娲诲姩宸ヤ綔琛ㄤ负鐩爣宸ヤ綔琛�
+ wb.getWorksheets().setActiveSheetIndex(targetSheetIndex);
+ // 鍒涘缓PDF淇濆瓨閫夐」
+ com.aspose.cells.PdfSaveOptions pdfSaveOptions = new com.aspose.cells.PdfSaveOptions();
+ pdfSaveOptions.setCompliance(com.aspose.cells.PdfCompliance.PDF_A_1_B);
+ // 鍒涘缓涓存椂瀛楄妭杈撳嚭娴�
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ // 灏嗘柊鐨刉orkbook淇濆瓨涓篜DF鍒颁复鏃舵祦
+ // newWorkbook.save(baos, com.aspose.cells.SaveFormat.PDF);
+ wb.save(baos, pdfSaveOptions);
+
+ // 灏哖DF娣诲姞鍒癦IP鏂囦欢
+ ZipEntry entry = new ZipEntry(pdfPathF);
+ zos.putNextEntry(entry);
+ zos.write(baos.toByteArray());
+ // zos.closeEntry();
+ // 鐩存帴灏嗗師濮嬪伐浣滅翱淇濆瓨涓篜DF锛堝彧鍖呭惈鍙鐨勫伐浣滆〃锛�
+
+ long now = System.currentTimeMillis();
+ // System.out.println("pdf杞崲鎴愬姛锛屽叡鑰楁椂锛�" + ((now - old) / 1000.0) + "绉�");
+ } catch (Exception e) {
+ e.printStackTrace();
+ // 鎵撳嵃璇︾粏閿欒淇℃伅
+ System.err.println("杞崲澶辫触锛�" + e.getMessage());
+ e.printStackTrace(System.err);
+ }
+
+
+
+
//
// ByteOutputStream boss = new ByteOutputStream();
// List<ArchiveInfoVo> aivs = new ArrayList<>();
// aivs.add(aIV);
// utilsv.byteOutputStreamExcel(boss, aivs,"Date List", "");
- bos2.writeTo(zos);
+
//鍐欏叆鐢靛瓙鐩綍 xsxl
ZipEntry entry = new ZipEntry("鐢靛瓙鏂囦欢鐩綍" + ".xls");
@@ -695,7 +1055,7 @@
String recordId = dsvs.get(0).getRecordId();
byte[] imgr = barcodeService.generateBarcodeImage(recordId);
ExcelExp e1 = new ExcelExp("鍗峰唴鐩綍鏁版嵁",dsvs, DocumentMaterialsVo.class);
- ExcelExp e2 = new ExcelExp("鍗峰唴鏁版嵁", list2, recordId, imgr, DocumentMaterialsVoSmall.class);
+ ExcelExp e2 = new ExcelExp("鍗峰唴鐩綍", list2, recordId, imgr, DocumentMaterialsVoSmall.class);
List<ExcelExp> mysheet = new ArrayList<ExcelExp>();
mysheet.add(e1);
mysheet.add(e2);
@@ -711,6 +1071,78 @@
// util1.byteOutputStreamExcel(bos1, dsvs,"Date List", "");
bos1.writeTo(zos);
//鎶奺xcel杞负pdf
+
+ //08-鍗峰唴鍗峰唴鐩綍鐨刾df
+ String pdf08Path= "08-鍗峰唴鐩綍.pdf";
+ try {
+ if (!getLicenseExcel()) {
+ System.out.println("鎺堟潈澶辫触");
+ // return ;
+ }
+ // 璇诲彇Excel鏂囦欢
+ com.aspose.cells.Workbook wb1 = poiToAspose(util2.getWb());
+
+ // 鑾峰彇闇�瑕佸鍑虹殑sheet锛堢储寮曚粠0寮�濮嬶級
+ int targetSheetIndex = 1;
+ com.aspose.cells.Worksheet targetSheet = wb1.getWorksheets().get(targetSheetIndex);
+ targetSheet.autoFitRows(true);
+ System.out.println("褰撳墠sheet鍚嶇О锛�" + targetSheet.getName());
+ System.out.println("褰撳墠sheet绱㈠紩锛�" + targetSheet.getIndex());
+
+ // 闅愯棌鎵�鏈夊叾浠栧伐浣滆〃
+ for (int i = 0; i < wb1.getWorksheets().getCount(); i++) {
+ if (i != targetSheetIndex) {
+ wb1.getWorksheets().get(i).setVisible(false);
+ }
+ }
+
+ // 璁剧疆娲诲姩宸ヤ綔琛ㄤ负鐩爣宸ヤ綔琛�
+ wb1.getWorksheets().setActiveSheetIndex(targetSheetIndex);
+ // 鍒涘缓PDF淇濆瓨閫夐」
+ com.aspose.cells.PdfSaveOptions pdfSaveOptions = new com.aspose.cells.PdfSaveOptions();
+ pdfSaveOptions.setCompliance(com.aspose.cells.PdfCompliance.PDF_A_1_B);
+ // 鍒涘缓涓存椂瀛楄妭杈撳嚭娴�
+ ByteArrayOutputStream baosm = new ByteArrayOutputStream();
+
+ // 灏嗘柊鐨刉orkbook淇濆瓨涓篜DF鍒颁复鏃舵祦
+ // newWorkbook.save(baos, com.aspose.cells.SaveFormat.PDF);
+ wb1.save(baosm, pdfSaveOptions);
+
+ // 灏哖DF娣诲姞鍒癦IP鏂囦欢
+ ZipEntry entry2 = new ZipEntry(pdf08Path);
+ zos.putNextEntry(entry2);
+ zos.write(baosm.toByteArray());
+ // zos.closeEntry();
+ // 鐩存帴灏嗗師濮嬪伐浣滅翱淇濆瓨涓篜DF锛堝彧鍖呭惈鍙鐨勫伐浣滆〃锛�
+
+ long now = System.currentTimeMillis();
+ // System.out.println("pdf杞崲鎴愬姛锛屽叡鑰楁椂锛�" + ((now - old) / 1000.0) + "绉�");
+ } catch (Exception e) {
+ e.printStackTrace();
+ // 鎵撳嵃璇︾粏閿欒淇℃伅
+ System.err.println("杞崲澶辫触锛�" + e.getMessage());
+ e.printStackTrace(System.err);
+ }
+
+
+
+
+ //List<DocumentMaterialsVo> list3 = dsvs;
+
+
+ // pdfGenerateService.generateFileDirectoryPdf(pdf08Path, list3);
+// ZipEntry zipEntry2 = new ZipEntry(pdf08Path);
+// zos.putNextEntry(zipEntry2);
+//
+// // 璇诲彇PDF鏂囦欢鍐呭骞跺啓鍏IP
+// try (FileInputStream fis = new FileInputStream(pdf08Path)) {
+// byte[] buffer = new byte[1024];
+// int len;
+// while ((len = fis.read(buffer)) > 0) {
+// zos.write(buffer, 0, len);
+// }
+// }
+
@@ -793,3 +1225,7 @@
}
}
+
+
+
+
diff --git a/ruoyi-admin/src/main/resources/license.xml b/ruoyi-admin/src/main/resources/license.xml
new file mode 100644
index 0000000..de2680e
--- /dev/null
+++ b/ruoyi-admin/src/main/resources/license.xml
@@ -0,0 +1,12 @@
+<License>
+ <Data>
+ <Products>
+ <Product>Aspose.Total for Java</Product>
+ </Products>
+ <EditionType>Enterprise</EditionType>
+ <SubscriptionExpiry>20991231</SubscriptionExpiry>
+ <LicenseExpiry>20991231</LicenseExpiry>
+ <SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber>
+ </Data>
+ <Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature>
+</License>
\ No newline at end of file
diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml
index 1ab596b..7599128 100644
--- a/ruoyi-common/pom.xml
+++ b/ruoyi-common/pom.xml
@@ -141,6 +141,12 @@
<version>3.5.5</version>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>com.itextpdf</groupId>
+ <artifactId>itextpdf</artifactId>
+ <version>5.5.13</version>
+ <scope>compile</scope>
+ </dependency>
</dependencies>
<!-- <build>-->
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/annotation/Excel.java b/ruoyi-common/src/main/java/com/ruoyi/common/annotation/Excel.java
index 6edd6f5..6639fd5 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/annotation/Excel.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/annotation/Excel.java
@@ -149,6 +149,11 @@
public IndexedColors backgroundColor() default IndexedColors.WHITE;
/**
+ * 瀵煎嚭鍗曞厓鏍煎瓧浣撳悕绉�
+ */
+ public String fontName() default "Arial";
+
+ /**
* 瀵煎嚭鍗曞厓鏍煎瓧浣撻鑹�
*/
public IndexedColors color() default IndexedColors.BLACK;
@@ -173,6 +178,8 @@
*/
Type type() default Type.ALL;
+ public int headerFontSize() default 12;
+
public enum Type
{
ALL(0), EXPORT(1), IMPORT(2);
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheet.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheet.java
index 105f862..39c5d24 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheet.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheet.java
@@ -62,6 +62,14 @@
*/
private Excel.Type type;
+ public Workbook getWb() {
+ return wb;
+ }
+
+ public void setWb(Workbook wb) {
+ this.wb = wb;
+ }
+
/**
* 宸ヤ綔钖勫璞�
*/
@@ -353,8 +361,11 @@
String recordId = list.get(index).getRecordId();
row.createCell(5).setCellValue(recordId);
row = sheet.createRow(3);
- column = 0;
+// // 娣诲姞鎬婚〉鏁板拰褰撳墠椤电爜淇℃伅
+// row.createCell(5).setCellValue("鎬婚〉鏁�: " + list.size() + ", 褰撳墠椤�: " + (index + 1));
+// row = sheet.createRow(4);
+ column = 0;
} else {
// 鏅�歴heet澶勭悊
// recordId = (DocumentMaterialsVo)list.get(0)
@@ -530,7 +541,7 @@
style.setWrapText(true);
Font headerFont = wb.createFont();
headerFont.setFontName(excel.headerFontName());
- headerFont.setFontHeightInPoints((short) 10);
+ headerFont.setFontHeightInPoints((short) 12);
headerFont.setBold(excel.headerFontBold());
headerFont.setColor(excel.headerColor().index);
style.setFont(headerFont);
@@ -1015,4 +1026,4 @@
}
return val;
}
-}
+}
\ No newline at end of file
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetSecond.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetSecond.java
index aa097a8..65859d0 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetSecond.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetSecond.java
@@ -14,21 +14,18 @@
import com.ruoyi.common.utils.reflect.ReflectUtils;
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;
import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFDataValidation;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
-import org.apache.poi.hssf.usermodel.HSSFDataValidation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
-import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -37,6 +34,7 @@
import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.Collectors;
+
/**
* Excel鐩稿叧澶勭悊
@@ -60,6 +58,14 @@
* 瀵煎嚭绫诲瀷锛圗XPORT:瀵煎嚭鏁版嵁锛汭MPORT锛氬鍏ユā鏉匡級
*/
private Excel.Type type;
+
+ public Workbook getWb() {
+ return wb;
+ }
+
+ public void setWb(Workbook wb) {
+ this.wb = wb;
+ }
/**
* 宸ヤ綔钖勫璞�
@@ -293,7 +299,7 @@
row = sheet.createRow(0);
sheet.addMergedRegion(new CellRangeAddress(2, 3, 0, 1));
row = sheet.createRow(2);
- row.setHeightInPoints(120); // 璁剧疆琛岄珮涓�20纾�
+ row.setHeightInPoints(100); // 璁剧疆琛岄珮涓�20纾�
//鎷垮埌鍥剧墖
// 鍒涘缓鍗曞厓鏍煎苟娣诲姞鍥剧墖
@@ -308,11 +314,11 @@
// 鍒涘缓鍗曞厓鏍�
Cell qrCell = sheet.createRow(2).createCell(1);
// 璁剧疆琛岄珮瓒冲楂樹互鏄剧ず浜岀淮鐮�
- sheet.getRow(2).setHeightInPoints(120);
+ sheet.getRow(2).setHeightInPoints(100);
// 浜岀淮鐮侀渶瑕佽緝澶х殑鍒楀鏉ユ樉绀猴紝璁剧疆涔嬪墠鍏堜繚瀛樺綋鍓嶅垪瀹�
int currentColumnWidth = sheet.getColumnWidth(1);
// 璁剧疆瓒冲瀹界殑鍒楀浠ユ樉绀轰簩缁寸爜
- sheet.setColumnWidth(1, 60 * 256);
+ sheet.setColumnWidth(1, 40 * 256);
// 鍒涘缓鍥剧墖閿氱偣锛岃缃湪绗�2琛岀2鍒�
// 浜岀淮鐮佹樉绀哄湪鍙充笂瑙掍笖涓嶅~婊℃暣涓牸瀛�
@@ -330,8 +336,17 @@
- String [] tits = {"妗� 鍙�:","妗f棣�(瀹�)鍙�:","缂� 寰� 鍙�: ","鍙� 鏂� 鍙�:",
- "妗� 鍗� 棰� 鍚�:","缂� 鍒� 鏃� 鏈�:","缂� 鍒� 鍗� 浣�:","淇� 绠� 鏈� 闄�:","瀵� 绾�:"};
+ // 浠�"妗f棣� (瀹�) 鍙�:"涓哄熀鍑嗭紝缁熶竴鎵�鏈夋爣棰樼殑闀垮害鍜屾牸寮�
+ String [] tits = {
+ "妗� 鍙�:",
+ "妗f棣� (瀹�) 鍙�:",
+ "缂� 寰� 鍙�:",
+ "鍙� 鏂� 鍙�:",
+ "妗� 鍗� 棰� 鍚�:",
+ "缂� 鍒� 鏃� 鏈�:",
+ "缂� 鍒� 鍗� 浣�:",
+ "淇� 绠� 鏈� 闄�:",
+ "瀵� 绾�:"};
List tmp = list.get(index).getDataset();
Object obj = tmp.get(0);
@@ -356,23 +371,25 @@
if(i > 3)
row = sheet.createRow(i+7);
// row.setHeight((short) 30);
- row.setHeightInPoints(40); // 璁剧疆琛岄珮涓�20纾�
- // row.createCell(0)
+ // 涓嶈缃浐瀹氳楂橈紝鍚庣画浣跨敤autoSizeRow鑷姩璋冩暣
cell = row.createCell(0);
// 鏍规嵁鐢ㄦ埛闇�姹傝缃浜屽瓙琛ㄦ牸鐨勫垪瀹�
// 绗竴鍒楀搴﹁缃负27
// 绗簩鍒楀搴﹁缃负51
// 浣跨敤涓巃ddCell鏂规硶鐩稿悓鐨勮绠楀叕寮忚缃垪瀹�
- sheet.setColumnWidth(0, (int) ((27 + 0.72) * 256)); // 绗竴鍒楋細瀹藉害27
- sheet.setColumnWidth(1, (int) ((51 + 0.72) * 256)); // 绗簩鍒楋細瀹藉害51
+ sheet.setColumnWidth(0, (int) ((29 + 0.72) * 256)); // 绗竴鍒楋細瀹藉害27
+ sheet.setColumnWidth(1, (int) ((52 + 0.72) * 256)); // 绗簩鍒楋細瀹藉害51
CellStyle style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.RIGHT);
- style.setVerticalAlignment(VerticalAlignment.CENTER);
-style.setVerticalAlignment(VerticalAlignment.CENTER); // 璁剧疆鍨傜洿灞呬腑
- // style.setAlignment(VerticalAlignment.CENTER);
+ style.setVerticalAlignment(VerticalAlignment.BOTTOM); // 璁剧疆鍨傜洿涓嬪榻�
+ style.setWrapText(true); // 璁剧疆鑷姩鎹㈣
+
+ // 璁剧疆瀛椾綋涓篢imes New Roman 18鍙�
Font font = wb.createFont();
font.setBold(true);
+ font.setFontName("Times New Roman");
+ font.setFontHeightInPoints((short) 18);
style.setFont(font);
style.setWrapText(true); // 璁剧疆鑷姩鎹㈣
cell.setCellStyle(style);
@@ -381,9 +398,26 @@
CellStyle style1 = wb.createCellStyle();
style1.setBorderBottom(BorderStyle.THIN); // 娣诲姞涓嬪垝绾�
style1.setWrapText(true); // 璁剧疆鑷姩鎹㈣
- style1.setVerticalAlignment(VerticalAlignment.CENTER);
+ style1.setVerticalAlignment(VerticalAlignment.BOTTOM); // 璁剧疆鍨傜洿涓嬪榻�
+
+ // 璁剧疆鍐呭瀛椾綋涓篢imes New Roman 16鍙�
+ Font contentFont = wb.createFont();
+ contentFont.setFontName("Times New Roman");
+ contentFont.setFontHeightInPoints((short) 16);
+
+ // 褰搃==4鏃讹紝涓烘枃瀛楁坊鍔犱笅鍒掔嚎
+ if(i==4) {
+ contentFont.setUnderline(Font.U_SINGLE); // 娣诲姞鍗曚笅鍒掔嚎
+ }
+
+ style1.setFont(contentFont);
cel.setCellStyle(style1);
-
+ if(i==4)
+ {
+ // 纭繚妗� 鍗� 棰� 鍚�:杩欎竴琛岃兘鏍规嵁鍐呭闀垮害鑷姩鎹㈣
+ style1.setWrapText(true); // 鏄庣‘璁剧疆鑷姩鎹㈣
+ cel.setCellStyle(style1);
+ }
// 澶勭悊鏃ユ湡鏍煎紡鍖栵紝鐗瑰埆鏄�"缂� 鍒� 鏃� 鏈�:"杩欎竴琛�
if (i == 5 && fieldValue instanceof Date) {
// 璁剧疆鏃ユ湡鏍煎紡涓簓yyy-MM-dd
@@ -391,6 +425,21 @@
cel.setCellValue(dateStr);
} else {
cel.setCellValue(fieldValue.toString());
+ }
+
+ // 瀵逛簬i==4鐨勬儏鍐碉紝纭繚琛岄珮鑳芥牴鎹唴瀹硅嚜鍔ㄨ皟鏁�
+ if(i==4)
+ {
+ // 璁剧疆琛岄珮涓鸿嚜鍔ㄨ皟鏁达紙-1琛ㄧず鑷姩楂樺害锛�
+ row.setHeight((short) -1);
+ // 涓嶉檺鍒舵渶澶ц楂橈紝鍏佽鏍规嵁鍐呭鑷姩璋冩暣
+ } else {
+ // 浣跨敤setHeight鏂规硶璁剧疆琛岄珮涓鸿嚜鍔ㄨ皟鏁达紙-1琛ㄧず鑷姩楂樺害锛�
+ row.setHeight((short) -1);
+ // 纭繚琛岄珮鑷冲皯涓�40纾咃紝浣嗕笉闄愬埗鏈�澶ц楂�
+ if (row.getHeightInPoints() < 40) {
+ row.setHeightInPoints(40);
+ }
}
// sheet.setColumnWidth(0, 60 * 256);
i++;
@@ -400,7 +449,7 @@
// 璁剧疆琛岄珮涓鸿嚜鍔ㄨ皟鏁�
row.setHeight((short) -1);
// row.setHeight((short) 30);
- row.setHeightInPoints(40); // 璁剧疆琛岄珮涓�20纾�
+ row.setHeightInPoints(20); // 璁剧疆琛岄珮涓�20纾�
row = sheet.createRow(9);
//璁剧疆鏉″舰鐮�
// 璁剧疆鏉″舰鐮�
@@ -409,23 +458,23 @@
// 鍒涘缓鍗曞厓鏍�
Cell barcodeCell = sheet.createRow(9).createCell(0);
// 璁剧疆琛岄珮瓒冲楂樹互鏄剧ず鏉″舰鐮�
- sheet.getRow(9).setHeightInPoints(70);
+ sheet.getRow(9).setHeightInPoints(40);
// 璁剧疆鍒楀瓒冲瀹戒互鏄剧ず鏉″舰鐮侊紝鍏堜繚瀛樺綋鍓嶅垪瀹�
int currentColumnWidth0 = sheet.getColumnWidth(0);
sheet.setColumnWidth(0, 40 * 256);
-
+
// 鍒涘缓鍥剧墖閿氱偣锛岃缃湪绗�10琛岀1鍒�
// 鏉″舰鐮佸眳涓笖涓嶈秴鍑虹浜屼釜鏍煎瓙
// 璋冩暣缁撴潫鍒楃储寮曞拰浣嶇疆鍙傛暟
// 澧炲姞dx1鍊硷紝浣挎潯褰㈢爜鏁翠綋鍚戝彸绉诲姩
- ClientAnchor anchor1 = new HSSFClientAnchor(300, 50, 900, 200, (short) 0, 9, (short) 1, 10);
+ ClientAnchor anchor1 = new HSSFClientAnchor(660, 50, 900, 200, (short) 0, 9, (short) 1, 10);
// 璁剧疆鍥剧墖浣嶇疆鍜屽ぇ灏�
anchor1.setAnchorType(ClientAnchor.AnchorType.MOVE_DONT_RESIZE);
-
+
// 娣诲姞鍥剧墖鍒板伐浣滆〃
getDrawingPatriarch(sheet).createPicture(anchor1,
wb.addPicture(dat, getImageType(dat)));
-
+
// 鏉″舰鐮佹坊鍔犲畬鎴愬悗锛屾仮澶嶅師鏉ョ殑鍒楀璁剧疆
sheet.setColumnWidth(0, currentColumnWidth0);
}
@@ -611,7 +660,7 @@
for (Object[] os : fields)
{
Excel excel = (Excel) os[1];
- String key = StringUtils.format("header_{}_{}", excel.headerColor(), excel.headerBackgroundColor());
+ String key = StringUtils.format("header_{}_{}_{}_{}_{}", excel.headerColor(), excel.headerBackgroundColor(), excel.headerFontName(), excel.headerFontBold(), excel.headerFontSize());
if (!headerStyles.containsKey(key))
{
style = wb.createCellStyle();
@@ -626,8 +675,8 @@
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
}*/
Font headerFont = wb.createFont();
- headerFont.setFontName("Arial");
- headerFont.setFontHeightInPoints((short) 10);
+ headerFont.setFontName(excel.headerFontName());
+ headerFont.setFontHeightInPoints((short) excel.headerFontSize()); // 浣跨敤Excel娉ㄨВ涓殑headerFontSize灞炴��
headerFont.setBold(excel.headerFontBold());
headerFont.setColor(excel.headerColor().index);
style.setFont(headerFont);
@@ -681,7 +730,7 @@
cell.setCellValue(attr.name());
setDataValidation(attr, row, column);
// 鏍规嵁Excel娉ㄨВ鍔ㄦ�侀�夋嫨琛ㄥご鏍峰紡
- String key = StringUtils.format("header_{}_{}", attr.headerColor(), attr.headerBackgroundColor());
+ String key = StringUtils.format("header_{}_{}_{}_{}_{}", attr.headerColor(), attr.headerBackgroundColor(), attr.headerFontName(), attr.headerFontBold(), attr.headerFontSize());
cell.setCellStyle(styles.get(key));
return cell;
}
@@ -1124,4 +1173,27 @@
}
return val;
}
+
+ /**
+ * 灏咥pache POI鐨刉orkbook杞崲涓篈spose.Cells鐨刉orkbook
+ *
+ * @param poiWorkbook Apache POI鐨刉orkbook瀵硅薄
+ * @return Aspose.Cells鐨刉orkbook瀵硅薄
+ * @throws IOException IO寮傚父
+ */
+
+
+
}
+
+
+
+
+
+
+
+
+
+
+
+
--
Gitblit v1.9.1