poi版本升级后设置样式报错修复

老版本有漏洞,需要升级新版本。

POI版本是3.17,之前是3.9,必须升级jar包,升级之后发现很多代码报错,需要修改调整,以下用于记录调整的代码。
颜色定义变化
旧版本 : HSSFColor.BLACK.index
新版本 : IndexedColors.BLACK.index

获取单元格格式
旧版本 : cell.getCellType 与之应对的单元格格式 HSSFCell.CELL_TYPE_BLANK
新版本 : cell.getCellTypeEnum 与之对应的单元格格式 BLANK (org.apache.poi.ss.usermodel.CellType.BLANK)

设置单元格格式
旧版本 : row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
新版本 : row.getCell(0).setCellType(CellType.STRING);

设置单元格垂直居中样式
旧版本 : XSSFCellStyle cellStyle = wb.createCellStyle();
    cellStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER); // 居中
    cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);//垂直
新版本 : XSSFCellStyle cellStyle = wb.createCellStyle();
    cellStyle.setAlignment(HorizontalAlignment.CENTER); // 居中
    cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); //垂直

设置边框
旧版本 : cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
新版本 : cellStyle.setBorderBottom(BorderStyle.THIN); //下边框

合并单元格
旧版本 : sheet.addMergedRegion(new CellRangeAddress(a, b,(short) c, (short) d));// 起始行,结束行,起始列,结束列
Region region0 = new Region(a, (short) b, c, (short) d);
新版本 : sheet.addMergedRegion(new Region(a, c, b, d));// 起始行,起始列,结束行,结束列
CellRangeAddress region0 =new CellRangeAddress(a, c, b, d);

设置字体加粗
旧版本: font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
新版本: font.setBold(true);

 

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇