|
@@ -4,23 +4,29 @@ import com.aspose.cells.SaveFormat;
|
|
|
import com.itextpdf.text.Document;
|
|
|
import com.itextpdf.text.pdf.PdfCopy;
|
|
|
import com.itextpdf.text.pdf.PdfReader;
|
|
|
+import org.apache.poi.ss.usermodel.ClientAnchor;
|
|
|
import org.apache.poi.ss.usermodel.PrintSetup;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
+import org.apache.poi.util.Units;
|
|
|
import org.springblade.common.constant.CommonConstant;
|
|
|
import org.springblade.common.utils.CommonUtil;
|
|
|
import org.springblade.common.utils.SystemUtils;
|
|
|
+import org.springblade.common.vo.DataVO;
|
|
|
import org.springblade.core.tool.utils.IoUtil;
|
|
|
import org.springblade.core.tool.utils.ResourceUtil;
|
|
|
import org.springblade.system.cache.ParamCache;
|
|
|
|
|
|
import java.io.*;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.function.Predicate;
|
|
|
+import java.util.regex.Matcher;
|
|
|
|
|
|
/**
|
|
|
* @Param 集合相关工具
|
|
@@ -155,4 +161,50 @@ public class CollectionUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public static void imageOrientation(Sheet sheet, ClientAnchor anchor, DataVO dataVO) {
|
|
|
+ anchor.setDx1(Units.pixelToEMU(5));
|
|
|
+ anchor.setDy1(Units.pixelToEMU(5));
|
|
|
+ anchor.setCol2(anchor.getCol1());
|
|
|
+ anchor.setRow2(anchor.getRow1());
|
|
|
+ int k = getMergedRegionIndex(sheet, CommonUtil.join(dataVO.getX(), dataVO.getY(), dataVO.getX(), dataVO.getY(), ","));
|
|
|
+ if (k > -1) {
|
|
|
+ /*如果是合并单元格,则锚点第二坐标设置为合并区右下角单元格坐标*/
|
|
|
+ CellRangeAddress ca = sheet.getMergedRegion(k);
|
|
|
+ anchor.setCol1(ca.getFirstColumn());
|
|
|
+ anchor.setRow1(ca.getFirstRow());
|
|
|
+ anchor.setCol2(ca.getLastColumn());
|
|
|
+ anchor.setRow2(ca.getLastRow());
|
|
|
+ }
|
|
|
+ int dx = (int) (sheet.getColumnWidthInPixels(anchor.getCol2()) + 3);
|
|
|
+ int dy = Units.pointsToPixel(sheet.getRow(anchor.getRow2()).getHeightInPoints()) - 5;
|
|
|
+ anchor.setDx2(Units.pixelToEMU(dx));
|
|
|
+ anchor.setDy2(Units.pixelToEMU(dy));
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int getMergedRegionIndex(Sheet sheet, String coords) {
|
|
|
+ for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
|
|
|
+ CellRangeAddress ca = sheet.getMergedRegion(i);
|
|
|
+ int firstColumn = ca.getFirstColumn();
|
|
|
+ int lastColumn = ca.getLastColumn();
|
|
|
+ int firstRow = ca.getFirstRow();
|
|
|
+ int lastRow = ca.getLastRow();
|
|
|
+ Matcher mu = CommonUtil.matcher("(\\d{1,3}),(\\d{1,3}),(\\d{1,3}),(\\d{1,3})", coords);
|
|
|
+ /*合并单元格四个角坐标,只要任意一个在落在将要合并的区域里面意味着两者重合,就必须拆分前者*/
|
|
|
+ List<Integer[]> corners = Arrays.asList(new Integer[]{firstColumn, firstRow}, new Integer[]{lastColumn, firstRow}, new Integer[]{firstColumn, lastRow}, new Integer[]{lastColumn, lastRow});
|
|
|
+ if (mu.find()) {
|
|
|
+ int firstColumn2 = mu.group(1) == null ? 0 : Integer.parseInt(mu.group(1));
|
|
|
+ int lastColumn2 = mu.group(3) == null ? 0 : Integer.parseInt(mu.group(3));
|
|
|
+ int firstRow2 = mu.group(2) == null ? 0 : Integer.parseInt(mu.group(2));
|
|
|
+ int lastRow2 = mu.group(4) == null ? 0 : Integer.parseInt(mu.group(4));
|
|
|
+ for (Integer[] corner : corners) {
|
|
|
+ if (firstColumn2 <= corner[0] && corner[0] <= lastColumn2 && firstRow2 <= corner[1] && corner[1] <= lastRow2) {
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
}
|