java基于XSSF 导出带箭头的直线

代码:

            XSSFSheet sheet = workbook.getSheetAt(0);
          XSSFDrawing patriarch = sheet.createDrawingPatriarch();   //顶级画布,只能有一个
            //设置锚点(坐标),
            //   XSSFClientAnchor的参数说明:
            //   参数   说明
            //  dx1  第1个单元格中x轴的偏移量
            //  dy1  第1个单元格中y轴的偏移量
            //  dx2  第2个单元格中x轴的偏移量
            //  dy2  第2个单元格中y轴的偏移量
            //  col1 第1个单元格的列号
            //  row1  第1个单元格的行号
            //  col2 第2个单元格的列号
            //  row2 第2个单元格的行号
            XSSFClientAnchor anchor = new XSSFClientAnchor(0,75000,0,75000,(short) 10, 5,(short)15,10);
            XSSFSimpleShape rec  = patriarch.createSimpleShape(anchor);
            rec.setShapeType( ShapeTypes.LINE );  //设置图形 形状(直线),其余参考 官方api
            // 线的类型    
            // solid=0 (实线)、dot=1( 点)、dash=2 (点划线)、lgDash=3、dashDot=4、lgDashDot=5、
            // lgDashDotDot=6、sysDash=7、sysDot=8、sysDashDot=9、sysDashDotDot=10 
            rec.setLineStyle(2); //(点划线 )
            rec.setLineStyleColor(65, 113, 156);//设置边框颜色
            rec.setLineWidth(1.5); //线宽
            /************下面代码设置箭头,不需要箭头的话 无需这些代码 **************/
            rec.getCTShape().getNvSpPr().getCNvPr().setId(rec.getCTShape().getNvSpPr().getCNvPr().getId()-1);
            CTShapeProperties shapeProperties = rec.getCTShape().getSpPr();
            CTLineEndProperties lineEndPropertiesTriangle = org.openxmlformats.schemas.drawingml.x2006.main.CTLineEndProperties.Factory.newInstance();
            lineEndPropertiesTriangle.setType(STLineEndType.TRIANGLE);  
            lineEndPropertiesTriangle.setLen(STLineEndLength.MED);
            lineEndPropertiesTriangle.setW(STLineEndWidth.MED);
            CTLineProperties lineProperties = shapeProperties.getLn();
            lineProperties.setHeadEnd(lineEndPropertiesTriangle); //头部箭头
            lineProperties.setTailEnd(lineEndPropertiesTriangle); //尾部箭头

如果要设置竖线箭头 ,设置导出时的列为 同一列

你可能感兴趣的:(java基于XSSF 导出带箭头的直线)