|
@@ -1,10 +1,9 @@
|
|
|
package com.jpsoft.picc.modules.common.utils;
|
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.hssf.converter.ExcelToHtmlConverter;
|
|
|
-import org.apache.poi.hssf.usermodel.HSSFRow;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
-import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
import org.w3c.dom.Document;
|
|
|
|
|
|
import javax.xml.parsers.DocumentBuilderFactory;
|
|
@@ -17,7 +16,6 @@ import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.DecimalFormat;
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -125,6 +123,10 @@ public class POIUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public POIUtils() {
|
|
|
+ wb = new HSSFWorkbook();
|
|
|
+ }
|
|
|
+
|
|
|
public Sheet getSheetAt(int sheetIndex){
|
|
|
return wb.getSheetAt(sheetIndex);
|
|
|
}
|
|
@@ -375,4 +377,51 @@ public class POIUtils {
|
|
|
System.out.println(result);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public Workbook exportErrorXls(int sheetIndex,int validateColIndex, int rowNum) {
|
|
|
+ Workbook destBook = new HSSFWorkbook();
|
|
|
+ Sheet destSheet = destBook.createSheet();
|
|
|
+
|
|
|
+ //复制列头
|
|
|
+ Sheet srcSheet = wb.getSheetAt(sheetIndex);
|
|
|
+ Row srcHeaderRow = wb.getSheetAt(sheetIndex).getRow(0);
|
|
|
+ Row destHeaderRow = destSheet.createRow(0);
|
|
|
+
|
|
|
+ for (int i=0;i<srcHeaderRow.getLastCellNum();i++){
|
|
|
+ if (srcHeaderRow.getCell(i)!=null) {
|
|
|
+ destHeaderRow.createCell(i).setCellValue(srcHeaderRow.getCell(i).getStringCellValue());
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ int srcRowIndex = 1;
|
|
|
+ int destRowIndex = 1;
|
|
|
+
|
|
|
+ while(srcRowIndex<= rowNum){
|
|
|
+ Row dataRow1 = srcSheet.getRow(srcRowIndex);
|
|
|
+
|
|
|
+ Cell cell = dataRow1.getCell(validateColIndex);
|
|
|
+
|
|
|
+ if (cell!=null && StringUtils.isNotEmpty(cell.getStringCellValue())){
|
|
|
+ Row dataRow2 = destSheet.createRow(destRowIndex);
|
|
|
+
|
|
|
+ for (int i=0;i<dataRow1.getLastCellNum();i++){
|
|
|
+ if (dataRow1.getCell(i)!=null) {
|
|
|
+ dataRow2.createCell(i).setCellValue((String)getCellValue(0,srcRowIndex,i));
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ destRowIndex++;
|
|
|
+ }
|
|
|
+
|
|
|
+ srcRowIndex++;
|
|
|
+ }
|
|
|
+
|
|
|
+ return destBook;
|
|
|
+ }
|
|
|
}
|