main
黄海 2 years ago
parent fa5060a3fc
commit 79cb311855

@ -1,58 +0,0 @@
package org.example;
import com.aspose.words.*;
import java.awt.*;
import java.lang.reflect.Modifier;
public class AsposeUtil {
public static void getLicense(){
try{
Class<?> aClass = Class.forName("com.aspose.words.zzXyu");
java.lang.reflect.Field zzYAC = aClass.getDeclaredField("zzZXG");
zzYAC.setAccessible(true);
java.lang.reflect.Field modifiersField = zzYAC.getClass().getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(zzYAC, zzYAC.getModifiers() & ~Modifier.FINAL);
zzYAC.set(null,new byte[]{76, 73, 67, 69, 78, 83, 69, 68});
}catch (Exception e){
System.out.println("apose word 破解异常");
}
}
/**
*
*
* @param startCell
* @param endCell
* @param table
*/
public static void mergeCells(Cell startCell, Cell endCell, Table table) {
Point startCellPos = new Point(startCell.getParentRow().indexOf(startCell), table.indexOf(startCell.getParentRow()));
Point endCellPos = new Point(endCell.getParentRow().indexOf(endCell), table.indexOf(endCell.getParentRow()));
Rectangle mergeRange = new Rectangle(Math.min(startCellPos.x,
endCellPos.x), Math.min(startCellPos.y, endCellPos.y),
Math.abs(endCellPos.x - startCellPos.x) + 1,
Math.abs(endCellPos.y - startCellPos.y) + 1);
for (Row row : table.getRows()) {
for (Cell cell : row.getCells()) {
Point currentPos = new Point(row.indexOf(cell), table.indexOf(row));
if (mergeRange.contains(currentPos)) {
if (currentPos.x == mergeRange.x) {
cell.getCellFormat().setHorizontalMerge(CellMerge.FIRST);
cell.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
} else {
cell.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);
}
if (currentPos.y == mergeRange.y) {
cell.getCellFormat().setVerticalMerge(CellMerge.FIRST);
} else {
cell.getCellFormat().setVerticalMerge(CellMerge.PREVIOUS);
}
}
}
}
}
}

@ -13,7 +13,6 @@ import java.awt.image.BufferedImage;
import java.io.*;
import java.util.List;
import static org.example.AsposeUtil.getLicense;
public class AsposeUtil {
public static void doc2pdf(String sourcePath, String targetPath) throws Exception {
@ -132,7 +131,7 @@ public class AsposeUtil {
style.getFont().setBold(true);// 设置字体
style.getFont().setName("宋体");
style.getFont().setSize(12);
style.setForegroundColor(UnitTest.ImportExcel.Util.AsposeUtil.getColor(colorString)); //处理背景色
style.setForegroundColor(getColor(colorString)); //处理背景色
style.setPattern(BackgroundType.SOLID);
style.setHorizontalAlignment(TextAlignmentType.CENTER); // 设置水平居中
style.setVerticalAlignment(TextAlignmentType.CENTER); // 设置垂直居中
@ -148,7 +147,7 @@ public class AsposeUtil {
cell = row.get(1);
cell.setStyle(style);
}
style.setForegroundColor(UnitTest.ImportExcel.Util.AsposeUtil.getColor("#FFFFFF")); //处理背景色
style.setForegroundColor(getColor("#FFFFFF")); //处理背景色
style.setPattern(BackgroundType.SOLID);
for (int i = headFirstRow + headTotalRows; i < dataRowCount; i++) {
Row row = sheet.getCells().getRow(i);

Loading…
Cancel
Save