|
|
@ -1,27 +1,23 @@
|
|
|
|
package com.platform.test;
|
|
|
|
package com.platform.test;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
|
|
|
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
|
|
|
|
|
|
|
|
|
import com.platform.utils.BeanCopy;
|
|
|
|
|
|
|
|
import com.platform.utils.Constant;
|
|
|
|
|
|
|
|
import com.platform.entities.PreDataInfo;
|
|
|
|
import com.platform.entities.PreDataInfo;
|
|
|
|
import com.platform.entities.PreDataInfoFull;
|
|
|
|
|
|
|
|
import com.platform.entities.RegionalismEntity;
|
|
|
|
import com.platform.entities.RegionalismEntity;
|
|
|
|
|
|
|
|
import com.platform.utils.BeanCopy;
|
|
|
|
|
|
|
|
import com.platform.utils.Constant;
|
|
|
|
import com.platform.utils.excelUtils.ExcelOperation;
|
|
|
|
import com.platform.utils.excelUtils.ExcelOperation;
|
|
|
|
|
|
|
|
|
|
|
|
public class ExcelTest {
|
|
|
|
public class ExcelTest {
|
|
|
@ -47,7 +43,7 @@ public class ExcelTest {
|
|
|
|
XSSFWorkbook result = null;
|
|
|
|
XSSFWorkbook result = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
workbook = new XSSFWorkbook(res.getInputStream());
|
|
|
|
workbook = new XSSFWorkbook(res.getInputStream());
|
|
|
|
result = ExcelOperation.writeExcelTemplate(workbook, Constant.EXCEL_TEMPLATE_INIT_ROW, 0, 25, list,"id", "workRange");
|
|
|
|
result = ExcelOperation.writeExcelTemplate(workbook, Constant.EXCEL_TEMPLATE_INIT_ROW, 0, 25, list,"id", "workRange","sysCode","updateTime");
|
|
|
|
} catch (IllegalArgumentException
|
|
|
|
} catch (IllegalArgumentException
|
|
|
|
| IllegalAccessException | IOException e) {
|
|
|
|
| IllegalAccessException | IOException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
// TODO Auto-generated catch block
|
|
|
@ -56,16 +52,23 @@ public class ExcelTest {
|
|
|
|
System.out.println("----"+result);
|
|
|
|
System.out.println("----"+result);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
File f = new File("D:/test/4.xlsx");
|
|
|
|
File f = new File("D:/test/6.xlsx");
|
|
|
|
FileOutputStream fileOut = null;
|
|
|
|
FileOutputStream fileOut = null;
|
|
|
|
if (f.exists()) {
|
|
|
|
if (f.exists()) {
|
|
|
|
|
|
|
|
f.createNewFile();
|
|
|
|
fileOut = new FileOutputStream(f);
|
|
|
|
fileOut = new FileOutputStream(f);
|
|
|
|
result.write(fileOut);
|
|
|
|
result.write(fileOut);
|
|
|
|
fileOut.close();
|
|
|
|
fileOut.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
System.out.println("no file");
|
|
|
|
f.createNewFile();
|
|
|
|
|
|
|
|
fileOut = new FileOutputStream(f);
|
|
|
|
|
|
|
|
result.write(fileOut);
|
|
|
|
|
|
|
|
fileOut.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
File f3 = new File("D:/test/3.xlsx");
|
|
|
|
|
|
|
|
f3.delete();
|
|
|
|
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
@ -84,7 +87,7 @@ public class ExcelTest {
|
|
|
|
XSSFWorkbook workbook = null;
|
|
|
|
XSSFWorkbook workbook = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
workbook = new XSSFWorkbook(f);
|
|
|
|
workbook = new XSSFWorkbook(f);
|
|
|
|
list = ExcelOperation.readExcel4Update(workbook, Constant.EXCEL_TEMPLATE_INIT_ROW, 0, PreDataInfo.class,"id");
|
|
|
|
list = ExcelOperation.readExcel4Update(workbook, Constant.EXCEL_TEMPLATE_INIT_ROW, 0, PreDataInfo.class, "workRange","id","sysCode","updateTime");
|
|
|
|
} catch (IllegalArgumentException
|
|
|
|
} catch (IllegalArgumentException
|
|
|
|
| IllegalAccessException | InstantiationException | InvalidFormatException | IOException e) {
|
|
|
|
| IllegalAccessException | InstantiationException | InvalidFormatException | IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
@ -117,9 +120,9 @@ public class ExcelTest {
|
|
|
|
info.setFunctionDetails("这是一个神奇的功能");
|
|
|
|
info.setFunctionDetails("这是一个神奇的功能");
|
|
|
|
info.setDataVersion("2");
|
|
|
|
info.setDataVersion("2");
|
|
|
|
|
|
|
|
|
|
|
|
PreDataInfoFull full = new PreDataInfoFull();
|
|
|
|
PreDataInfo full = new PreDataInfo();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
BeanCopy.copyBean(info, full);
|
|
|
|
BeanCopy.copyBean(info, full,"id");
|
|
|
|
} catch (Exception e1) {
|
|
|
|
} catch (Exception e1) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e1.printStackTrace();
|
|
|
|
e1.printStackTrace();
|
|
|
|