|
@@ -0,0 +1,194 @@
|
|
|
+package com.platform.dao.test;
|
|
|
+
|
|
|
+import com.platform.common.util.IdGeneratorUtils;
|
|
|
+import com.platform.common.util.StringUtils;
|
|
|
+import com.platform.dao.util.CustomExcelImportUtil;
|
|
|
+import com.platform.dao.util.ExcelUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.poi.POIXMLDocument;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
+import org.apache.poi.openxml4j.opc.OPCPackage;
|
|
|
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
+
|
|
|
+import java.io.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+public class Util {
|
|
|
+
|
|
|
+ public static void main(String[] args) throws IOException, InvalidFormatException {
|
|
|
+ String oldFilePath = "F:\\公司\\临泉\\修改测试\\安徽省阜阳市临泉县田桥乡前王村东王组-成员表.xls";// 原始文件
|
|
|
+ String newFilePath = "F:\\公司\\临泉\\修改测试\\东王组承包方家庭成员信息.xlsx";// 修改后的文件
|
|
|
+ List<Cy> oldList = getListCy(new FileInputStream(oldFilePath));
|
|
|
+ /* for(Cy item: oldList){
|
|
|
+ if(StringUtils.isNotEmpty(item.getFBFBM())){
|
|
|
+ log.info(item.toString());
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+
|
|
|
+ List<Cy> newList = getListCy(new FileInputStream(newFilePath));
|
|
|
+ newList.forEach(item->{
|
|
|
+ if(StringUtils.isNotEmpty(item.getFBFBM())){
|
|
|
+ log.info(item.toString());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ log.info(oldList.size() + "");
|
|
|
+ log.info(newList.size() + "");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<Cy> getListCy(InputStream inputstream) throws IOException, InvalidFormatException {
|
|
|
+ if (inputstream == null) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ Workbook book = null;
|
|
|
+ if (!(inputstream.markSupported())) {
|
|
|
+ inputstream = new PushbackInputStream(inputstream, 8);
|
|
|
+ }
|
|
|
+ if (POIFSFileSystem.hasPOIFSHeader(inputstream)) {
|
|
|
+ book = new HSSFWorkbook(inputstream);
|
|
|
+ } else if (POIXMLDocument.hasOOXMLHeader(inputstream)) {
|
|
|
+ book = new XSSFWorkbook(OPCPackage.open(inputstream));
|
|
|
+ }
|
|
|
+ Sheet sheet = book.getSheetAt(0);
|
|
|
+ int rowCounts = sheet.getLastRowNum();
|
|
|
+ List<Cy> result = new ArrayList<>(rowCounts);
|
|
|
+ Cy record = null;
|
|
|
+
|
|
|
+ StringBuffer error = new StringBuffer();
|
|
|
+ for (int i = 1; i <= rowCounts; i++) {
|
|
|
+ record = new Cy();
|
|
|
+ Row row = sheet.getRow(i);
|
|
|
+ if(CustomExcelImportUtil.isRowEmpty(row)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ //i,j i:行 j:列
|
|
|
+ record.setFBFBM(CustomExcelImportUtil.getCellValue(row.getCell(0)));
|
|
|
+ record.setFBFMC(CustomExcelImportUtil.getCellValue(row.getCell(1)));
|
|
|
+ record.setCBFBM(CustomExcelImportUtil.getCellValue(row.getCell(2)));
|
|
|
+ record.setCYXM(CustomExcelImportUtil.getCellValue(row.getCell(3)));
|
|
|
+ record.setCYXB(CustomExcelImportUtil.getCellValue(row.getCell(4)));
|
|
|
+ record.setCYZJLX(CustomExcelImportUtil.getCellValue(row.getCell(5)));
|
|
|
+ record.setCYZJHM(CustomExcelImportUtil.getCellValue(row.getCell(6)));
|
|
|
+ record.setYHZGX(CustomExcelImportUtil.getCellValue(row.getCell(7)));
|
|
|
+ record.setCYBZ(CustomExcelImportUtil.getCellValue(row.getCell(8)));
|
|
|
+ record.setSFGYR(CustomExcelImportUtil.getCellValue(row.getCell(9)));
|
|
|
+ record.setCYBZSM(CustomExcelImportUtil.getCellValue(row.getCell(10)));
|
|
|
+ result.add(record);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static List<Cbf> getListCbf(InputStream inputstream) throws IOException, InvalidFormatException {
|
|
|
+ if (inputstream == null) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ Workbook book = null;
|
|
|
+ if (!(inputstream.markSupported())) {
|
|
|
+ inputstream = new PushbackInputStream(inputstream, 8);
|
|
|
+ }
|
|
|
+ if (POIFSFileSystem.hasPOIFSHeader(inputstream)) {
|
|
|
+ book = new HSSFWorkbook(inputstream);
|
|
|
+ } else if (POIXMLDocument.hasOOXMLHeader(inputstream)) {
|
|
|
+ book = new XSSFWorkbook(OPCPackage.open(inputstream));
|
|
|
+ }
|
|
|
+ Sheet sheet = book.getSheetAt(0);
|
|
|
+ int rowCounts = sheet.getLastRowNum();
|
|
|
+ List<Cbf> result = new ArrayList<>(rowCounts);
|
|
|
+ Cbf record = null;
|
|
|
+
|
|
|
+ StringBuffer error = new StringBuffer();
|
|
|
+ for (int i = 1; i <= rowCounts; i++) {
|
|
|
+ record = new Cbf();
|
|
|
+ Row row = sheet.getRow(i);
|
|
|
+ if(CustomExcelImportUtil.isRowEmpty(row)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ //i,j i:行 j:列
|
|
|
+ record.setFBFMC(CustomExcelImportUtil.getCellValue(row.getCell(0)));
|
|
|
+ record.setCBFBM(CustomExcelImportUtil.getCellValue(row.getCell(1)));
|
|
|
+ record.setCBFLX(CustomExcelImportUtil.getCellValue(row.getCell(2)));
|
|
|
+ record.setCBFMC(CustomExcelImportUtil.getCellValue(row.getCell(3)));
|
|
|
+ record.setCBFZJLX(CustomExcelImportUtil.getCellValue(row.getCell(4)));
|
|
|
+ record.setCBFZJHM(CustomExcelImportUtil.getCellValue(row.getCell(5)));
|
|
|
+ record.setCBFDZ(CustomExcelImportUtil.getCellValue(row.getCell(6)));
|
|
|
+ record.setYZBM(CustomExcelImportUtil.getCellValue(row.getCell(7)));
|
|
|
+ record.setLXDH(CustomExcelImportUtil.getCellValue(row.getCell(8)));
|
|
|
+ record.setCBFCYSL(CustomExcelImportUtil.getCellValue(row.getCell(9)));
|
|
|
+ record.setCBFDCRQ(CustomExcelImportUtil.getCellValue(row.getCell(10)));
|
|
|
+ record.setCBFDCY(CustomExcelImportUtil.getCellValue(row.getCell(11)));
|
|
|
+ record.setCBFDCJS(CustomExcelImportUtil.getCellValue(row.getCell(12)));
|
|
|
+ record.setGSJS(CustomExcelImportUtil.getCellValue(row.getCell(13)));
|
|
|
+ record.setGSJSR(CustomExcelImportUtil.getCellValue(row.getCell(14)));
|
|
|
+ record.setGSSHRQ(CustomExcelImportUtil.getCellValue(row.getCell(15)));
|
|
|
+ record.setGSSHR(CustomExcelImportUtil.getCellValue(row.getCell(16)));
|
|
|
+ record.setFBFBM(CustomExcelImportUtil.getCellValue(row.getCell(17)));
|
|
|
+ result.add(record);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<Cbdk> getListCbdk(InputStream inputstream) throws IOException, InvalidFormatException {
|
|
|
+ if (inputstream == null) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ Workbook book = null;
|
|
|
+ if (!(inputstream.markSupported())) {
|
|
|
+ inputstream = new PushbackInputStream(inputstream, 8);
|
|
|
+ }
|
|
|
+ if (POIFSFileSystem.hasPOIFSHeader(inputstream)) {
|
|
|
+ book = new HSSFWorkbook(inputstream);
|
|
|
+ } else if (POIXMLDocument.hasOOXMLHeader(inputstream)) {
|
|
|
+ book = new XSSFWorkbook(OPCPackage.open(inputstream));
|
|
|
+ }
|
|
|
+ Sheet sheet = book.getSheetAt(0);
|
|
|
+ int rowCounts = sheet.getLastRowNum();
|
|
|
+ List<Cbdk> result = new ArrayList<>(rowCounts);
|
|
|
+ Cbdk record = null;
|
|
|
+
|
|
|
+ StringBuffer error = new StringBuffer();
|
|
|
+ for (int i = 1; i <= rowCounts; i++) {
|
|
|
+ record = new Cbdk();
|
|
|
+ Row row = sheet.getRow(i);
|
|
|
+ if(CustomExcelImportUtil.isRowEmpty(row)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ //i,j i:行 j:列
|
|
|
+ record.setDKBM(CustomExcelImportUtil.getCellValue(row.getCell(0)));
|
|
|
+ record.setFBFBM(CustomExcelImportUtil.getCellValue(row.getCell(1)));
|
|
|
+ record.setCBFBM(CustomExcelImportUtil.getCellValue(row.getCell(2)));
|
|
|
+ record.setCBJYQQDFS(CustomExcelImportUtil.getCellValue(row.getCell(3)));
|
|
|
+ record.setHTMJ(CustomExcelImportUtil.getCellValue(row.getCell(4)));
|
|
|
+ record.setCBHTBM(CustomExcelImportUtil.getCellValue(row.getCell(5)));
|
|
|
+ record.setLZHTBM(CustomExcelImportUtil.getCellValue(row.getCell(6)));
|
|
|
+ record.setCBJYQZBM(CustomExcelImportUtil.getCellValue(row.getCell(7)));
|
|
|
+ record.setYHTMJ(CustomExcelImportUtil.getCellValue(row.getCell(8)));
|
|
|
+ record.setHTMJM(CustomExcelImportUtil.getCellValue(row.getCell(9)));
|
|
|
+ record.setYHTMJM(CustomExcelImportUtil.getCellValue(row.getCell(10)));
|
|
|
+ record.setSFQQQG(CustomExcelImportUtil.getCellValue(row.getCell(11)));
|
|
|
+ result.add(record);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+}
|