|
|
@ -43,7 +43,6 @@ public class ExcelConvertPdf { |
|
|
|
Sheet sheet = workbook.getSheetAt(0); |
|
|
|
Sheet sheet = workbook.getSheetAt(0); |
|
|
|
int column = sheet.getRow(1).getLastCellNum(); |
|
|
|
int column = sheet.getRow(1).getLastCellNum(); |
|
|
|
int row = sheet.getPhysicalNumberOfRows(); |
|
|
|
int row = sheet.getPhysicalNumberOfRows(); |
|
|
|
System.out.println(row); |
|
|
|
|
|
|
|
//下面是找出表格中的空行和空列
|
|
|
|
//下面是找出表格中的空行和空列
|
|
|
|
List nullCol = new ArrayList<>(); |
|
|
|
List nullCol = new ArrayList<>(); |
|
|
|
List nullRow = new ArrayList<>(); |
|
|
|
List nullRow = new ArrayList<>(); |
|
|
@ -76,7 +75,6 @@ public class ExcelConvertPdf { |
|
|
|
PdfPTable table = new PdfPTable(column-sheet.getRow(1).getFirstCellNum()); |
|
|
|
PdfPTable table = new PdfPTable(column-sheet.getRow(1).getFirstCellNum()); |
|
|
|
List<CellRangeAddress> ranges = new ArrayList(); |
|
|
|
List<CellRangeAddress> ranges = new ArrayList(); |
|
|
|
int sheetMergeCount = sheet.getNumMergedRegions(); |
|
|
|
int sheetMergeCount = sheet.getNumMergedRegions(); |
|
|
|
System.out.println("sheetMergeCount"+sheetMergeCount); |
|
|
|
|
|
|
|
for (int i = 0; i < sheetMergeCount; i++) { |
|
|
|
for (int i = 0; i < sheetMergeCount; i++) { |
|
|
|
CellRangeAddress range = sheet.getMergedRegion(i); |
|
|
|
CellRangeAddress range = sheet.getMergedRegion(i); |
|
|
|
ranges.add(range); |
|
|
|
ranges.add(range); |
|
|
@ -104,10 +102,6 @@ public class ExcelConvertPdf { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
str = cell.getStringCellValue(); |
|
|
|
str = cell.getStringCellValue(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
System.out.println("i ::"+i + "j::"+j); |
|
|
|
|
|
|
|
System.out.println(str); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (CellRangeAddress range : ranges) { //合并的单元格判断和处理
|
|
|
|
for (CellRangeAddress range : ranges) { //合并的单元格判断和处理
|
|
|
|
|
|
|
|
|
|
|
|
if (j >= range.getFirstColumn() && j <= range.getLastColumn() && i >= range.getFirstRow() |
|
|
|
if (j >= range.getFirstColumn() && j <= range.getLastColumn() && i >= range.getFirstRow() |
|
|
@ -125,7 +119,6 @@ public class ExcelConvertPdf { |
|
|
|
rowNum = range.getLastRow() - range.getFirstRow() + 1; |
|
|
|
rowNum = range.getLastRow() - range.getFirstRow() + 1; |
|
|
|
colNum = range.getLastColumn() - range.getFirstColumn() + 1; |
|
|
|
colNum = range.getLastColumn() - range.getFirstColumn() + 1; |
|
|
|
cell1 = mergeCell(str, font, rowNum, colNum); |
|
|
|
cell1 = mergeCell(str, font, rowNum, colNum); |
|
|
|
System.out.println("合并"+rowNum+"、"+colNum); |
|
|
|
|
|
|
|
table.addCell(cell1); |
|
|
|
table.addCell(cell1); |
|
|
|
flag = false; |
|
|
|
flag = false; |
|
|
|
mergeFlag = ranges.size() > 1; |
|
|
|
mergeFlag = ranges.size() > 1; |
|
|
|