apache poi斜边框线_如何使用Apache POI在Excel单元格内画斜线(Java)
需求背景:
在使用Apache POI進(jìn)行表格數(shù)據(jù)導(dǎo)出時(shí),某些單元格需要畫(huà)上斜線。
1.需求背景
解決方法:
國(guó)內(nèi)相關(guān)文章較少,于是在國(guó)外技術(shù)網(wǎng)站上找了一圈,最終在StackOverFlow上找到了方法,原文中的方法畫(huà)了一條斜線和箭頭。
代碼:
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet("Sheet1");
CreationHelper helper = wb.getCreationHelper();
XSSFDrawing drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = helper.createClientAnchor();
// 設(shè)置斜線的開(kāi)始位置
anchor.setCol1(2);
anchor.setRow1(2);
// 設(shè)置斜線的結(jié)束位置
anchor.setCol2(3);
anchor.setRow2(3);
XSSFSimpleShape shape = drawing.createSimpleShape((XSSFClientAnchor) anchor);
// 設(shè)置形狀類型為線型
shape.setShapeType(ShapeTypes.LINE);
// 設(shè)置線寬
shape.setLineWidth(0.5);
// 設(shè)置線的風(fēng)格
shape.setLineStyle(0);
// 設(shè)置線的顏色
shape.setLineStyleColor(0, 0, 0);
File file = new File("C:\\Users\\admin\\Desktop", "Test.xlsx");
try (FileOutputStream fis = new FileOutputStream(file);) {
wb.write(fis);
wb.close();
} catch (Exception e) {
e.printStackTrace();
}
實(shí)現(xiàn)效果:
希望對(duì)大家有所幫助!
2.實(shí)現(xiàn)效果
總結(jié)
以上是生活随笔為你收集整理的apache poi斜边框线_如何使用Apache POI在Excel单元格内画斜线(Java)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 阿里云服务器怎么屏蔽ip(怎么关闭阿里云
- 下一篇: 空心点_空心砖的新玩法,看完大开眼界