|
@@ -6,11 +6,12 @@ import com.spire.xls.FileFormat;
|
|
|
import com.spire.xls.Workbook;
|
|
|
import com.spire.xls.Worksheet;
|
|
|
import com.spire.xls.core.spreadsheet.HTMLOptions;
|
|
|
+import com.sun.javafx.tk.FontMetrics;
|
|
|
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.apache.poi.ss.usermodel.*;
|
|
|
+import org.apache.poi.ss.usermodel.Font;
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.jsoup.Jsoup;
|
|
|
import org.jsoup.nodes.Document;
|
|
|
import org.jsoup.nodes.Element;
|
|
@@ -20,8 +21,10 @@ import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
import org.springblade.core.tool.utils.FileUtil;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
|
import org.springblade.core.tool.utils.IoUtil;
|
|
|
-import org.springblade.manager.vo.DateFormat;
|
|
|
+import org.apache.poi.ss.util.CellUtil;
|
|
|
|
|
|
+import javax.swing.*;
|
|
|
+import java.awt.*;
|
|
|
import java.io.*;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
@@ -266,4 +269,106 @@ public class ExcelInfoUtils2 {
|
|
|
workbook.write(outputStream);
|
|
|
}
|
|
|
|
|
|
+ public static void main11121(String[] args) throws Exception {
|
|
|
+ FileInputStream inputStream = new FileInputStream("/Users/hongchuangyanfa/Desktop/excel/123456.xlsx");
|
|
|
+ org.apache.poi.ss.usermodel.Workbook workbook = new XSSFWorkbook(inputStream);
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ Row row = sheet.getRow(0);
|
|
|
+ Cell cell = row.getCell(0);
|
|
|
+
|
|
|
+ if (cell != null) {
|
|
|
+ Font font = workbook.getFontAt(cell.getCellStyle().getFontIndex());
|
|
|
+ // 获取字体间距,单位为1/20个字符宽度
|
|
|
+ short typeOffset = font.getTypeOffset();
|
|
|
+ System.out.println("字体间距(字间距): " + typeOffset);
|
|
|
+ String data = cell.getStringCellValue();
|
|
|
+ data = data.replaceAll("[^\\x00-\\xff]", "**");
|
|
|
+ int length = data.length();
|
|
|
+
|
|
|
+
|
|
|
+ double shij = cell.getSheet().getColumnWidth(cell.getColumnIndex());
|
|
|
+
|
|
|
+ short fontSize = font.getFontHeightInPoints();
|
|
|
+
|
|
|
+ System.out.println(checkCellReasonable(cell,fontSize));
|
|
|
+
|
|
|
+ }
|
|
|
+ workbook.close();
|
|
|
+ inputStream.close();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private static boolean checkCellReasonable(Cell cell, double fontSize) {
|
|
|
+ String data = cell.getStringCellValue();
|
|
|
+ // data = data.replaceAll("[^\\x00-\\xff]", "**");
|
|
|
+ // int sum = data.length();
|
|
|
+
|
|
|
+ double cellHeight = cell.getRow().getHeightInPoints();
|
|
|
+ double cellHeight2 = cell.getRow().getHeight();
|
|
|
+ // double rows1 = fontWidth * sum / cellWidth;
|
|
|
+ double shij = cell.getSheet().getColumnWidth(cell.getColumnIndex());
|
|
|
+
|
|
|
+ int i = data.getBytes().length * 256;
|
|
|
+ System.out.println(shij>i);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private static double getTotalWidth(Cell cell) {
|
|
|
+ int x = getColNum(cell.getSheet(), cell.getRowIndex(), cell.getColumnIndex());
|
|
|
+ double totalWidthInPixels = 0;
|
|
|
+ for (int i = 0; i < x; i++) {
|
|
|
+ totalWidthInPixels += cell.getSheet().getColumnWidthInPixels(i + cell.getColumnIndex());
|
|
|
+ }
|
|
|
+ return totalWidthInPixels;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static int getColNum(Sheet sheet, int row, int column) {
|
|
|
+ int sheetMergeCount = sheet.getNumMergedRegions();
|
|
|
+ //判断该单元格是否是合并区域的内容
|
|
|
+ for (int i = 0; i < sheetMergeCount; i++) {
|
|
|
+ CellRangeAddress ca = sheet.getMergedRegion(i);
|
|
|
+ int firstColumn = ca.getFirstColumn();
|
|
|
+ int lastColumn = ca.getLastColumn();
|
|
|
+ int firstRow = ca.getFirstRow();
|
|
|
+ int lastRow = ca.getLastRow();
|
|
|
+
|
|
|
+ if (row >= firstRow && row <= lastRow && column >= firstColumn && column <= lastColumn) {
|
|
|
+ return lastColumn - firstColumn + 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+/* 6pt 8px
|
|
|
+ 7pt 9px
|
|
|
+ 7.5pt 10px
|
|
|
+ 8pt 11px
|
|
|
+ 9pt 12px
|
|
|
+ 10pt 13px
|
|
|
+ 10.5pt 14px
|
|
|
+ 11pt 15px
|
|
|
+ 12pt 16px
|
|
|
+ 13pt 17px
|
|
|
+ 13.5pt 18px
|
|
|
+ 14pt 19px
|
|
|
+ 14.5pt 20px
|
|
|
+ 15pt 21px
|
|
|
+ 16pt 22px
|
|
|
+ 17pt 23px
|
|
|
+ 18pt 24px
|
|
|
+ 20pt 26px
|
|
|
+ 22pt 29px
|
|
|
+ 24pt 32px
|
|
|
+ 26pt 35px
|
|
|
+ 27pt 36px
|
|
|
+ 28pt 37px
|
|
|
+ 29pt 38px
|
|
|
+ 30pt 40px
|
|
|
+ 32pt 42px
|
|
|
+ 34pt 45px
|
|
|
+ 36pt 48px */
|
|
|
+
|
|
|
}
|