/**
* 添加倾斜线
*/
@org.junit.Test
public void main1() {
try {
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet(“XX销售对照表”);
CreationHelper helper = wb.getCreationHelper();
Drawing drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = helper.createClientAnchor();
// 设置划线位置
anchor.setCol1(0);
anchor.setRow1(0);
anchor.setCol2(1);
anchor.setRow2(1);
XSSFSimpleShape shape = ((XSSFDrawing)drawing).createSimpleShape((XSSFClientAnchor)anchor);
// 图形类型
shape.setShapeType(ShapeTypes.LINE);
// 设置宽度
shape.setLineWidth(1.5);
// 设置间距
shape.setLineStyle(0);
// 设置颜色
shape.setLineStyleColor(0,0,0);
// 设置内容
shape.setText(" 月份\n\n年度");
//apache POI sets first shape Id to 1. It should be 0.
shape.getCTShape().getNvSpPr().getCNvPr().setId(shape.getCTShape().getNvSpPr().getCNvPr().getId()-1);
CTShapeProperties shapeProperties = shape.getCTShape().getSpPr();
CTLineProperties lineProperties = shapeProperties.getLn();
CTLineEndProperties lineEndProperties = org.openxmlformats.schemas.drawingml.x2006.main.CTLineEndProperties.Factory.newInstance();
// 类型
lineEndProperties.setType(STLineEndType.NONE);
lineEndProperties.setLen(STLineEndLength.LG);
lineEndProperties.setW(STLineEndWidth.LG);
lineProperties.setHeadEnd(lineEndProperties);
/**/
Row row = sheet.createRow(0);
row.createCell(1).setCellValue("一月");
row.createCell(2).setCellValue("二月");
row.createCell(3).setCellValue("三月");
FileOutputStream fileOut = new FileOutputStream("E:/workbook.xlsx");
wb.write(fileOut);
fileOut.close();
} catch (IOException ex) {
ex.printStackTrace();
}