合并分支
This commit is contained in:
@@ -23,7 +23,6 @@
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
<groupId>org.codehaus.jackson</groupId>
|
||||
<artifactId>jackson-xc</artifactId>
|
||||
<version>1.9.12</version>
|
||||
@@ -33,6 +32,17 @@
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.25</version>
|
||||
</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>
|
||||
|
||||
</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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,10 +18,10 @@ public class UUIDGenerator {
|
||||
String result="";
|
||||
UUID uuid = UUID.randomUUID();
|
||||
String temp=uuid.toString();
|
||||
StringTokenizer token=new StringTokenizer(temp,"-");
|
||||
StringTokenizer token=new StringTokenizer(temp,"-");
|
||||
while(token.hasMoreTokens()){
|
||||
result+=token.nextToken();
|
||||
}
|
||||
result+=token.nextToken();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,10 @@ public class UUIDGenerator {
|
||||
result = result.substring(16);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(UUIDGenerator.randomUUID());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user