|
@@ -1,135 +1,55 @@
|
|
|
package org.springblade.manager.utils;
|
|
|
|
|
|
-import cn.hutool.core.comparator.PinyinComparator;
|
|
|
-import cn.hutool.extra.pinyin.PinyinUtil;
|
|
|
-import cn.hutool.extra.pinyin.engine.pinyin4j.Pinyin4jEngine;
|
|
|
-import com.alibaba.druid.sql.repository.SchemaObjectType;
|
|
|
-import com.alibaba.excel.util.DateUtils;
|
|
|
-import com.aspose.cells.HtmlSaveOptions;
|
|
|
-import com.spire.xls.*;
|
|
|
-import com.spire.xls.collections.PicturesCollection;
|
|
|
-import com.spire.xls.core.spreadsheet.HTMLOptions;
|
|
|
-import io.swagger.models.auth.In;
|
|
|
-import org.apache.commons.lang.StringUtils;
|
|
|
-import org.jsoup.Connection;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+import com.spire.xls.CellRange;
|
|
|
+import com.spire.xls.Workbook;
|
|
|
+import com.spire.xls.Worksheet;
|
|
|
import org.jsoup.Jsoup;
|
|
|
import org.jsoup.nodes.Document;
|
|
|
import org.jsoup.nodes.Element;
|
|
|
import org.jsoup.select.Elements;
|
|
|
-import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
import org.springblade.core.tool.utils.IoUtil;
|
|
|
import org.springblade.core.tool.utils.ResourceUtil;
|
|
|
|
|
|
-import java.awt.image.BufferedImage;
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileInputStream;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.InputStream;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
+import java.io.*;
|
|
|
|
|
|
public class test {
|
|
|
|
|
|
- public static void main1231(String[] args) throws Exception {
|
|
|
-
|
|
|
- List<String> data = new ArrayList<>();
|
|
|
-
|
|
|
- data.add("12_0");
|
|
|
- data.add("13_0");
|
|
|
- data.add("14_0");
|
|
|
- data.add("15_0");
|
|
|
- data.add("16_0");
|
|
|
- data.add("10_0");
|
|
|
- data.add("11_0");
|
|
|
-
|
|
|
- int yindex;
|
|
|
- int xindex;
|
|
|
- if(false){ //纵向
|
|
|
- yindex = 1;
|
|
|
- xindex = 0;
|
|
|
- } else { //横向
|
|
|
- xindex = 1;
|
|
|
- yindex = 0;
|
|
|
- }
|
|
|
-
|
|
|
- String dw[] = data.toArray(new String[data.size()]);
|
|
|
- Map<Integer, List<String>> result = data.stream().filter(s -> s.indexOf("_")>=0).collect(Collectors.groupingBy(s -> Integer.parseInt(s.split("_")[yindex])));
|
|
|
+ public static void main1(String[] args) throws IOException {
|
|
|
+ // String excel="/Users/hongchuangyanfa/Downloads/JL1036隧道锚喷支护施工记录表.xlsx";
|
|
|
+ String excel="/Users/hongchuangyanfa/Downloads/养护表格/ZJY6.11.2植筋检验表.xlsx";
|
|
|
+ String poiPath="/Users/hongchuangyanfa/Desktop/pdf/poi.pdf";
|
|
|
+ String pdfPath22="/Users/hongchuangyanfa/Desktop/pdf/poi222.pdf";
|
|
|
+ String pdfPathhtml="/Users/hongchuangyanfa/Desktop/pdf/poi222.html";
|
|
|
+ Workbook workbook2 = new Workbook();
|
|
|
+ workbook2.loadFromFile(excel);
|
|
|
+ //设置转换后的PDF页面高宽适应工作表的内容大小
|
|
|
+ workbook2.getConverterSetting().setSheetFitToPage(true);
|
|
|
+ Worksheet sheet = workbook2.getWorksheets().get(0);
|
|
|
|
|
|
- Map<Integer, List<String>> collect = new LinkedHashMap<>();
|
|
|
- result.entrySet().stream().sorted(Map.Entry.comparingByKey()).forEachOrdered(x -> collect.put(x.getKey(), x.getValue()));
|
|
|
- int j=0;
|
|
|
- for(Integer key: collect.keySet()){
|
|
|
- List<String> datakey = collect.get(key);
|
|
|
- List<String> ordList = datakey.stream().filter(s -> s.indexOf("_")>=0).sorted(Comparator.comparing(s -> Integer.parseInt(s.split("_")[xindex]))).collect(Collectors.toList());
|
|
|
- for (String ord:ordList){
|
|
|
- dw[j]=ord;
|
|
|
- j++;
|
|
|
- }
|
|
|
- }
|
|
|
+ sheet.saveToHtml(pdfPathhtml);
|
|
|
|
|
|
- for (String da:dw){
|
|
|
- System.out.println(da);
|
|
|
- }
|
|
|
+ File file1 = ResourceUtil.getFile(pdfPathhtml);
|
|
|
+ String htmlString = IoUtil.readToString(new FileInputStream(file1));
|
|
|
+ Document doc = Jsoup.parse(htmlString);
|
|
|
+ Element table = doc.select("table").first();
|
|
|
+ Elements trs = table.select("tr");
|
|
|
+ Elements cols = table.select("Col");
|
|
|
|
|
|
+ sheet.deleteRow(trs.size(),sheet.getRows().length - trs.size());
|
|
|
+ sheet.deleteColumn(cols.size(),sheet.getColumns().length - cols.size());
|
|
|
|
|
|
- /* String file_path = FileUtils.getSysLocalFileUrl()+"/pdf/";
|
|
|
+ System.out.println(trs.size());
|
|
|
+ System.out.println(cols.size());
|
|
|
|
|
|
- String filecode = SnowFlakeUtil.getId() + "";
|
|
|
- String thmlUrl = file_path + filecode + ".html";
|
|
|
+ System.out.println(sheet.getRows().length);
|
|
|
+ System.out.println(sheet.getColumns().length);
|
|
|
|
|
|
- InputStream inputStreamByUrl = FileUtils.getInputStreamByUrl("/Users/hongchuangyanfa/Desktop/pdf/1688448159421825025.xlsx");
|
|
|
- // 解析excel
|
|
|
- Workbook wb = new Workbook();
|
|
|
- wb.loadFromMHtml(inputStreamByUrl);
|
|
|
- Worksheet sheet = wb.getWorksheets().get(0);
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- CellRange[] mergedCells = sheet.getMergedCells();
|
|
|
- for (int i=0;i<mergedCells.length;i++){
|
|
|
- CellRange mergedCell = mergedCells[i];
|
|
|
-
|
|
|
- CellRange data = sheet.getCellRange(mergedCell.getRow(),mergedCell.getColumn());
|
|
|
-
|
|
|
- System.out.println(data.getValue());
|
|
|
- System.out.println(mergedCell.getRow()+"--=--"+mergedCell.getColumn());
|
|
|
-
|
|
|
- }*/
|
|
|
-
|
|
|
- }
|
|
|
- public static Map<String, Map<String, String>> getWeather(String city, String month) {
|
|
|
- String html = "http://www.tianqihoubao.com/lishi/" + city + "/month/" + month + ".html";
|
|
|
- System.out.println(html);
|
|
|
- Map<String, Map<String, String>> map = new HashMap<>();
|
|
|
- Document document = null;
|
|
|
- try {
|
|
|
- document = Jsoup.connect(html).get();
|
|
|
- Element body = document.body();
|
|
|
- Elements table = body.getElementsByTag("table");
|
|
|
- Elements trs = table.select("tr");
|
|
|
- if (trs.get(0).select("td").text().contains("本站目前")) {
|
|
|
- System.out.println("网页错误");
|
|
|
- return null;
|
|
|
- }
|
|
|
- for (int i = 1; i < trs.size(); i++) {
|
|
|
- Element tr = trs.get(i);
|
|
|
- Elements tds = tr.select("td");
|
|
|
-
|
|
|
- Map<String, String> m = new HashMap<>();
|
|
|
- m.put("weather", tds.get(1).text().split("/")[0].trim());
|
|
|
- String[] split = tds.get(2).text().split("/");
|
|
|
- m.put("tempLow", split[0].substring(0, split[0].length() - 2));
|
|
|
- m.put("tempHigh", split[1].substring(0, split[1].length() - 1));
|
|
|
- m.put("windLevel", tds.get(3).text().substring(tds.get(3).text().length() - 2));
|
|
|
- map.put(tds.get(0).text(), m);
|
|
|
- }
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- return map;
|
|
|
+ ////16384*/
|
|
|
}
|
|
|
|
|
|
}
|