1 public classPdfTableExcel {2 //ExcelObject
3 protectedExcelObject excelObject;4 //excel
5 protectedExcel excel;6 //7 protected boolean setting = false;8
9 /**
10 *
Description: Constructor
11 *@paramexcel12 */13 publicPdfTableExcel(ExcelObject excelObject){14 this.excelObject =excelObject;15 this.excel =excelObject.getExcel();16 }17
18 /**
19 *
Description: 获取转换过的Excel内容Table
20 *@returnPdfPTable21 *@throwsBadElementException22 *@throwsMalformedURLException23 *@throwsIOException24 */25 public PdfPTable getTable() throwsBadElementException, MalformedURLException, IOException{26 Sheet sheet = this.excel.getSheet();27 returntoParseContent(sheet);28 }29
30 protected PdfPTable toParseContent(Sheet sheet) throwsBadElementException, MalformedURLException, IOException{31 int rowlength =sheet.getLastRowNum();32 List cells = new ArrayList();33 float[] widths = null;34 float mw = 0;35 for (int i = 0; i < rowlength; i++) {36 Row row =sheet.getRow(i);37 float[] cws = new float[row.getLastCellNum()];38 for (int j = 0; j < row.getLastCellNum(); j++) {39 Cell cell =row.getCell(j);40 float cw =getPOIColumnWidth(cell);41 cws[cell.getColumnIndex()] =cw;42 if(isUsed(cell.getColumnIndex(), row.getRowNum())){43 continue;44 }45 cell.setCellType(Cell.CELL_TYPE_STRING);46 CellRangeAddress range =getColspanRowspanByExcel(row.getRowNum(), cell.getColumnIndex());47 //48 int rowspan = 1;49 int colspan = 1;50 if (range != null) {51 rowspan = range.getLastRow() - range.