合并分支
This commit is contained in:
@@ -23,7 +23,6 @@
|
|||||||
<version>1.2</version>
|
<version>1.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
||||||
<groupId>org.codehaus.jackson</groupId>
|
<groupId>org.codehaus.jackson</groupId>
|
||||||
<artifactId>jackson-xc</artifactId>
|
<artifactId>jackson-xc</artifactId>
|
||||||
<version>1.9.12</version>
|
<version>1.9.12</version>
|
||||||
@@ -33,6 +32,17 @@
|
|||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<version>1.7.25</version>
|
<version>1.7.25</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.poi</groupId>
|
||||||
|
<artifactId>poi</artifactId>
|
||||||
|
<version>4.1.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.poi</groupId>
|
||||||
|
<artifactId>poi-ooxml</artifactId>
|
||||||
|
<version>4.1.2</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
44
common/src/main/java/com/qn/utils/ExcelUtils.java
Normal file
44
common/src/main/java/com/qn/utils/ExcelUtils.java
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package com.qn.utils;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFCell;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
public class ExcelUtils {
|
||||||
|
private static final String OSS_STR = "http://smartvenue.oss-cn-beijing.aliyuncs.com/health-docs/";
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param args
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
FileInputStream fis = new FileInputStream("/Users/limqhz/home/123.xlsx");
|
||||||
|
XSSFWorkbook workBook = new XSSFWorkbook(fis);
|
||||||
|
|
||||||
|
// 进行模板的克隆(接下来的操作都是针对克隆后的sheet)
|
||||||
|
XSSFSheet sheet = workBook.getSheetAt(0);
|
||||||
|
int lastRowNum = sheet.getLastRowNum();
|
||||||
|
System.out.println("last row Num ===" + lastRowNum);
|
||||||
|
for (int i=1;i<=lastRowNum;i++){
|
||||||
|
System.out.println(i);
|
||||||
|
String s = UUIDGenerator.randomUUID();
|
||||||
|
XSSFCell c3 = sheet.getRow(i).getCell(3);
|
||||||
|
replaceCellValue(c3,OSS_STR + s + ".pdf");
|
||||||
|
XSSFCell c4 = sheet.getRow(i).getCell(4);
|
||||||
|
replaceCellValue(c4, s);
|
||||||
|
}
|
||||||
|
// 输出为一个新的Excel,也就是动态修改完之后的excel
|
||||||
|
String fileName = "output" + System.currentTimeMillis() + ".xlsx";
|
||||||
|
OutputStream out = new FileOutputStream("/Users/limqhz/home/" + fileName);
|
||||||
|
workBook.write(out);
|
||||||
|
fis.close();
|
||||||
|
out.flush();
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void replaceCellValue(XSSFCell cell, String value) {
|
||||||
|
cell.setCellValue(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -37,5 +37,9 @@ public class UUIDGenerator {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println(UUIDGenerator.randomUUID());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
6
pom.xml
6
pom.xml
@@ -48,6 +48,12 @@
|
|||||||
<version>1.18.20</version>
|
<version>1.18.20</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.pdfbox</groupId>
|
||||||
|
<artifactId>pdfbox</artifactId>
|
||||||
|
<version>2.0.20</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|||||||
@@ -46,6 +46,11 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.pdfbox</groupId>
|
||||||
|
<artifactId>pdfbox</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.qn.controller;
|
package com.qn.controller;
|
||||||
|
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@@ -8,6 +9,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class TestController {
|
public class TestController {
|
||||||
@@ -34,9 +36,10 @@ public class TestController {
|
|||||||
/**
|
/**
|
||||||
* 表白
|
* 表白
|
||||||
*/
|
*/
|
||||||
@RequestMapping(value = "/image", method = RequestMethod.GET)
|
@RequestMapping(value = "/pdf", method = RequestMethod.GET)
|
||||||
public void image() throws IOException {
|
public void image(HttpServletResponse response) throws IOException {
|
||||||
File file = new File("/home/type/job");
|
PrintWriter writer = response.getWriter();
|
||||||
|
writer.write("如需下载请先付款!");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
43
web/src/main/java/com/qn/controller/utils/PDFUtils.java
Normal file
43
web/src/main/java/com/qn/controller/utils/PDFUtils.java
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package com.qn.controller.utils;
|
||||||
|
|
||||||
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||||
|
import org.apache.pdfbox.rendering.PDFRenderer;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class PDFUtils {
|
||||||
|
|
||||||
|
private static final float DPI = 100;
|
||||||
|
|
||||||
|
private static final String IMG_TYPE = "PNG";
|
||||||
|
|
||||||
|
public static void pdfToImg(String filePath) throws IOException {
|
||||||
|
File file = new File(filePath);
|
||||||
|
if (file.exists()){
|
||||||
|
PDDocument document = PDDocument.load(file);
|
||||||
|
PDFRenderer renderer = new PDFRenderer(document);
|
||||||
|
int numberOfPages = document.getNumberOfPages();
|
||||||
|
for (int i = 0; i < numberOfPages; i++){
|
||||||
|
BufferedImage bufferedImage = renderer.renderImageWithDPI(i, DPI);
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
ImageIO.write(bufferedImage, IMG_TYPE, out);
|
||||||
|
File imgFile = new File("/Users/limqhz/home/test/pdf/img/" + i + ".png");
|
||||||
|
FileOutputStream outputStream = new FileOutputStream(imgFile);
|
||||||
|
outputStream.write(out.toByteArray());
|
||||||
|
outputStream.close();
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
PDFUtils.pdfToImg("/Users/limqhz/Downloads/1.pdf");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user