java excel转pdf 的实现_Java:Excel转PDF实现方案;基于POI与Itext进行搭配.

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值