|
@@ -4,18 +4,23 @@ import com.spire.xls.CellRange;
|
|
import com.spire.xls.FileFormat;
|
|
import com.spire.xls.FileFormat;
|
|
import com.spire.xls.Workbook;
|
|
import com.spire.xls.Workbook;
|
|
import com.spire.xls.Worksheet;
|
|
import com.spire.xls.Worksheet;
|
|
-import com.spire.xls.core.IXLSRange;
|
|
|
|
import com.spire.xls.core.spreadsheet.HTMLOptions;
|
|
import com.spire.xls.core.spreadsheet.HTMLOptions;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
+import org.apache.poi.ss.usermodel.WorkbookFactory;
|
|
import org.jsoup.Jsoup;
|
|
import org.jsoup.Jsoup;
|
|
import org.jsoup.nodes.Document;
|
|
import org.jsoup.nodes.Document;
|
|
import org.jsoup.nodes.Element;
|
|
import org.jsoup.nodes.Element;
|
|
import org.jsoup.select.Elements;
|
|
import org.jsoup.select.Elements;
|
|
|
|
+
|
|
|
|
+import org.springblade.common.utils.CommonUtil;
|
|
import org.springblade.common.utils.SnowFlakeUtil;
|
|
import org.springblade.common.utils.SnowFlakeUtil;
|
|
import org.springblade.core.tool.utils.FileUtil;
|
|
import org.springblade.core.tool.utils.FileUtil;
|
|
import org.springblade.core.tool.utils.Func;
|
|
import org.springblade.core.tool.utils.Func;
|
|
import org.springblade.core.tool.utils.IoUtil;
|
|
import org.springblade.core.tool.utils.IoUtil;
|
|
-import org.springblade.core.tool.utils.ResourceUtil;
|
|
|
|
|
|
+import org.springblade.manager.vo.DateFormat;
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileInputStream;
|
|
@@ -23,17 +28,44 @@ import java.io.FileNotFoundException;
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
public class ExcelInfoUtils {
|
|
public class ExcelInfoUtils {
|
|
|
|
|
|
|
|
+ public static void main1234(String[] args) throws Exception {
|
|
|
|
+ String fileUrl = "/Users/hongchuangyanfa/Downloads/29ed5438d62d301bf290b908acf3bdbb.xlsx";
|
|
|
|
+ InputStream exceInp = new FileInputStream(new File(fileUrl));
|
|
|
|
+
|
|
|
|
+ org.apache.poi.ss.usermodel.Workbook workbook = WorkbookFactory.create(exceInp);
|
|
|
|
+
|
|
|
|
+ //获取工作表
|
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
|
+ sheet.setForceFormulaRecalculation(true);
|
|
|
|
+
|
|
|
|
+ Row row = sheet.getRow(34);
|
|
|
|
+
|
|
|
|
+ Cell cell = sheet.getRow(34).getCell(1);
|
|
|
|
+
|
|
|
|
+ System.out.println(cell.getStringCellValue());
|
|
|
|
+ // 解析原始excel
|
|
|
|
+ Workbook wb = new Workbook();
|
|
|
|
+ wb.loadFromMHtml(fileUrl);
|
|
|
|
+ Worksheet sheet2 = wb.getWorksheets().get(0);
|
|
|
|
+
|
|
|
|
+ CellRange cellRange = sheet2.getCellRange(35, 2);
|
|
|
|
+ System.out.println(cellRange.getText());
|
|
|
|
+
|
|
|
|
+ //sheet.saveToHtml("/Users/hongchuangyanfa/Desktop/pdf/test.html");
|
|
|
|
+ }
|
|
|
|
+
|
|
public static void main123(String[] args) throws FileNotFoundException {
|
|
public static void main123(String[] args) throws FileNotFoundException {
|
|
String excelUrl = "/Users/hongchuangyanfa/Downloads/C10.28隧道注浆施工记录表(1).xlsx";
|
|
String excelUrl = "/Users/hongchuangyanfa/Downloads/C10.28隧道注浆施工记录表(1).xlsx";
|
|
String old_html = "/Users/hongchuangyanfa/Desktop/pdf/old_html.html";
|
|
String old_html = "/Users/hongchuangyanfa/Desktop/pdf/old_html.html";
|
|
String old_xlsx = "/Users/hongchuangyanfa/Desktop/pdf/old_html.xlsx";
|
|
String old_xlsx = "/Users/hongchuangyanfa/Desktop/pdf/old_html.xlsx";
|
|
File file = new File(excelUrl);
|
|
File file = new File(excelUrl);
|
|
InputStream fileInputStream = new FileInputStream(file);
|
|
InputStream fileInputStream = new FileInputStream(file);
|
|
- excelInfo(fileInputStream,old_xlsx,old_html,"1");
|
|
|
|
|
|
+ // excelInfo(fileInputStream,old_xlsx,old_html,"1");
|
|
|
|
|
|
|
|
|
|
// 解析原始excel
|
|
// 解析原始excel
|
|
@@ -41,19 +73,28 @@ public class ExcelInfoUtils {
|
|
wb.loadFromMHtml(excelUrl);
|
|
wb.loadFromMHtml(excelUrl);
|
|
Worksheet sheet = wb.getWorksheets().get(0);
|
|
Worksheet sheet = wb.getWorksheets().get(0);
|
|
|
|
|
|
-/* CellRange[] mergedCells = sheet.getMergedCells();
|
|
|
|
|
|
+ CellRange[] mergedCells = sheet.getCells();
|
|
for(int i=0;i<mergedCells.length;i++){
|
|
for(int i=0;i<mergedCells.length;i++){
|
|
- CellRange oldcell = mergedCells[i];
|
|
|
|
- IXLSRange ixlsRange = sheet.get(oldcell.getRow(), oldcell.getColumn(), oldcell.getLastRow(), oldcell.getLastColumn());
|
|
|
|
- System.out.println(ixlsRange.getDataValidation().getErrorMessage());
|
|
|
|
|
|
+ CellRange oldcell =mergedCells[i];
|
|
|
|
+ // sheet.get(oldcell.getRow(),oldcell.getColumn()).getDataValidation().setErrorMessage("");
|
|
|
|
+ // sheet.get(oldcell.getRow(),oldcell.getColumn(),oldcell.getLastRow(),oldcell.getLastColumn()).getDataValidation().setErrorMessage("");
|
|
|
|
+ oldcell.getDataValidation().setErrorMessage("");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ CellRange[] mergedCells1 = sheet.getMergedCells();
|
|
|
|
+ for(int i=0;i<mergedCells1.length;i++) {
|
|
|
|
+ CellRange oldcell = mergedCells1[i];
|
|
|
|
+ oldcell.getDataValidation().setErrorMessage(i+"");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- ArrayList<CellRange> cellList = sheet.getCellList();
|
|
|
|
- for(int i=0;i<cellList.size();i++){
|
|
|
|
- CellRange oldcell = cellList.get(i);
|
|
|
|
|
|
+
|
|
|
|
+ CellRange[] cells = sheet.getCells();
|
|
|
|
+ for(int i=0;i< cells.length;i++){
|
|
|
|
+ CellRange oldcell = cells[i];
|
|
System.out.println(oldcell.getRow()+"---"+oldcell.getColumn()+"---="+oldcell.getText()+"---x="+oldcell.getDataValidation().getErrorMessage());
|
|
System.out.println(oldcell.getRow()+"---"+oldcell.getColumn()+"---="+oldcell.getText()+"---x="+oldcell.getDataValidation().getErrorMessage());
|
|
- }*/
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -104,7 +145,8 @@ public class ExcelInfoUtils {
|
|
CellRange[] sheet2Cells = sheet.getCells();
|
|
CellRange[] sheet2Cells = sheet.getCells();
|
|
for (int i = 0; i < sheet2Cells.length; i++) {
|
|
for (int i = 0; i < sheet2Cells.length; i++) {
|
|
CellRange oldcell = sheet2Cells[i];
|
|
CellRange oldcell = sheet2Cells[i];
|
|
- sheet.getCellRange(oldcell.getRow(),oldcell.getColumn()).getDataValidation().setErrorMessage("");
|
|
|
|
|
|
+ oldcell.getDataValidation().setErrorMessage("");
|
|
|
|
+ sheet.get(oldcell.getRow(),oldcell.getColumn()).getDataValidation().setErrorMessage("");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -129,11 +171,10 @@ public class ExcelInfoUtils {
|
|
}else{
|
|
}else{
|
|
j = j + 1;
|
|
j = j + 1;
|
|
}
|
|
}
|
|
-
|
|
|
|
// 目标表添加备注信息
|
|
// 目标表添加备注信息
|
|
- // mergedCell.getDataValidation().setErrorMessage(j+"");
|
|
|
|
- // oldcell.getDataValidation().setErrorMessage(j+"");
|
|
|
|
- // sheet2.getMergedCells()[i].setText(j+"");
|
|
|
|
|
|
+ mergedCell.getDataValidation().setErrorMessage(j+"");
|
|
|
|
+ oldcell.getDataValidation().setErrorMessage(j+"");
|
|
|
|
+ sheet2.getMergedCells()[i].setText(j+"");
|
|
dataMap.put("y1", oldcell.getRow());
|
|
dataMap.put("y1", oldcell.getRow());
|
|
dataMap.put("y2", oldcell.getLastRow());
|
|
dataMap.put("y2", oldcell.getLastRow());
|
|
dataMap.put("x1", oldcell.getColumn());
|
|
dataMap.put("x1", oldcell.getColumn());
|
|
@@ -163,10 +204,12 @@ public class ExcelInfoUtils {
|
|
} else {
|
|
} else {
|
|
j = Func.toInt(data);
|
|
j = Func.toInt(data);
|
|
}
|
|
}
|
|
- if(StringUtils.isEmpty(data)){
|
|
|
|
|
|
+
|
|
|
|
+ /* if(StringUtils.isEmpty(data)){
|
|
oldcell.getDataValidation().setErrorMessage(j+"");
|
|
oldcell.getDataValidation().setErrorMessage(j+"");
|
|
sheet2.getCells()[i].setText(j+"");
|
|
sheet2.getCells()[i].setText(j+"");
|
|
- }
|
|
|
|
|
|
+ }*/
|
|
|
|
+
|
|
if(!xyList.containsKey(j+"")){
|
|
if(!xyList.containsKey(j+"")){
|
|
Map<String, Integer> dataMap = new HashMap<>();
|
|
Map<String, Integer> dataMap = new HashMap<>();
|
|
dataMap.put("y1", oldcell.getRow());
|
|
dataMap.put("y1", oldcell.getRow());
|
|
@@ -368,11 +411,6 @@ public class ExcelInfoUtils {
|
|
Elements td2 = trs2.get(i).select("td");
|
|
Elements td2 = trs2.get(i).select("td");
|
|
for (int x = 0; x < td1.size(); x++) {
|
|
for (int x = 0; x < td1.size(); x++) {
|
|
Element cell1 = td1.get(x);
|
|
Element cell1 = td1.get(x);
|
|
- /*if (cell1.children().size() >= 1) {
|
|
|
|
- String data = cell1.text();
|
|
|
|
- cell1.empty();
|
|
|
|
- cell1.text(data);
|
|
|
|
- }*/
|
|
|
|
Element cell2 = td2.get(x);
|
|
Element cell2 = td2.get(x);
|
|
String html = cell2.text();
|
|
String html = cell2.text();
|
|
Map<String, Integer> xyMap = xyList.get(html);
|
|
Map<String, Integer> xyMap = xyList.get(html);
|
|
@@ -398,4 +436,73 @@ public class ExcelInfoUtils {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static Map<String,String> getDateFormat(List<DateFormat> dateFormat) {
|
|
|
|
+ List<DateFormat> dateFormaty = new ArrayList<>();
|
|
|
|
+ List<DateFormat> dateFormath = new ArrayList<>();
|
|
|
|
+ Map<String,String> redata = new HashMap<>();
|
|
|
|
+ String format = ""; //YYYY年MM月DD日 HH:mm:ss
|
|
|
|
+ String sp1="文本";
|
|
|
|
+ String sp2="文本";
|
|
|
|
+ String sp3="至";
|
|
|
|
+
|
|
|
|
+ if(dateFormat!=null && dateFormat.size()>=1){
|
|
|
|
+ for (DateFormat datef : dateFormat){
|
|
|
|
+ if(datef.getName().equals("divide_y")){
|
|
|
|
+ sp1 = datef.getValue();
|
|
|
|
+ }else if(datef.getName().equals("divide_h")){
|
|
|
|
+ sp2 = datef.getValue();
|
|
|
|
+ }else if(datef.getName().equals("divide_c")){
|
|
|
|
+ sp3 = datef.getValue();
|
|
|
|
+ }else if(datef.getValue().equals("yyyy")||datef.getValue().equals("MM")||datef.getValue().equals("dd")){
|
|
|
|
+ dateFormaty.add(datef);
|
|
|
|
+ }else if(datef.getValue().equals("HH")||datef.getValue().equals("mm")||datef.getValue().equals("ss")){
|
|
|
|
+ dateFormath.add(datef);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 组合-日期
|
|
|
|
+ if(dateFormaty!=null && dateFormaty.size()>=1){
|
|
|
|
+ for (int i=0;i<dateFormaty.size();i++){
|
|
|
|
+ DateFormat datef = dateFormaty.get(i);
|
|
|
|
+ format =format+datef.getValue()+datef.getName();
|
|
|
|
+ }
|
|
|
|
+ if(!sp1.equals("文本")){
|
|
|
|
+ format = format.replace("年",sp1).replace("月",sp1).replace("日"," ");
|
|
|
|
+ if(format.indexOf("dd")<0){
|
|
|
|
+ format = format.substring(0,format.length()-1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 组合-时间
|
|
|
|
+ if(dateFormath!=null && dateFormath.size()>=1){
|
|
|
|
+ format = format+" ";
|
|
|
|
+ for (int i=0;i<dateFormath.size();i++){
|
|
|
|
+ DateFormat datef = dateFormath.get(i);
|
|
|
|
+ format =format+datef.getValue()+datef.getName();
|
|
|
|
+ }
|
|
|
|
+ if(!sp2.equals("文本")){
|
|
|
|
+ format = format.replace("时",sp2).replace("分",sp2).replace("秒","");
|
|
|
|
+ if(format.indexOf("ss")<0){
|
|
|
|
+ format = format.substring(0,format.length()-1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(StringUtils.isEmpty(format)){
|
|
|
|
+ format ="yyyy年MM月dd日";
|
|
|
|
+ }
|
|
|
|
+ if(dateFormaty.size()>=1&&dateFormath.size()>=1){
|
|
|
|
+ redata.put("type","datetime");
|
|
|
|
+ }else if(dateFormaty.size()>=1){
|
|
|
|
+ redata.put("type","date");
|
|
|
|
+ } else if (dateFormath.size()>=1) {
|
|
|
|
+ redata.put("type","time");
|
|
|
|
+ }
|
|
|
|
+ if(StringUtils.isNotEmpty(sp3)){
|
|
|
|
+ redata.put("sp3",sp3);
|
|
|
|
+ }
|
|
|
|
+ redata.put("format",format);
|
|
|
|
+ return redata;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|