java包上有红色向上箭头,Apache POI XSSF无法创建向上箭头

锚点决定了形状的大小 . 对于线形,默认情况下,线从第一个锚单元的左上边缘到左上边缘加上最后一个锚单元的 dx 和 dy . 第一锚单元是锚的左上方的单元,而最后的锚单元是锚的右下方的单元 . 因此,默认情况下,线条形状将从左上角到右下角 .

如果我们希望它从左下角到右上角,那么我们必须翻转形状 .

如果我们在 Excel 中从左下角到右上角画一条线,然后查看存储的 /xl/drawings/drawing1.xml ,我们将看到这个手动绘制的线条形状也被翻转 .

两行示例:

import org.apache.poi.xssf.usermodel.*;

import org.apache.poi.ss.usermodel.*;

import java.io.FileOutputStream;

class CreateExcelLineShapes {

public static void main(String[] args) throws Exception{

Workbook workbook = new XSSFWorkbook();

Sheet sheet = workbook.createSheet("Sheet1");

CreationHelper helper = workbook.getCreationHelper();

Drawing drawing = sheet.createDrawingPatriarch();

ClientAnchor anchor = helper.createClientAnchor();

//Anchor B2:C4

//This determines the size of the line shape to be from

//upper left edge of B2 to upper left edge of C4 plus dx and dy.

//Since dx and dy are both 0, this is the bottom right edge of B3.

anchor.setCol1(1);

anchor.setRow1(1);

anchor.setCol2(2);

anchor.setRow2(3);

//From here on XSSF only.

XSSFDrawing xssfdrawing = (XSSFDrawing)drawing;

XSSFClientAnchor xssfanchor = (XSSFClientAnchor)anchor;

//Draw a line from upper left edge of B2 to upper left edge of C4 = bottom right edge of B3.

//This is the default.

XSSFSimpleShape xssfshape = xssfdrawing.createSimpleShape(xssfanchor);

xssfshape.setShapeType(ShapeTypes.LINE);

xssfshape.setLineWidth(4);

xssfshape.setLineStyle(0);

xssfshape.setLineStyleColor(0, 0, 0);

//This sets the arrow line end type:

xssfshape.getCTShape().getSpPr().getLn().addNewTailEnd().setType(

org.openxmlformats.schemas.drawingml.x2006.main.STLineEndType.TRIANGLE);

//Again draw a line from upper left edge of B2 to upper left edge of C4 = bottom right edge of B3.

xssfshape = xssfdrawing.createSimpleShape(xssfanchor);

xssfshape.setShapeType(ShapeTypes.LINE);

xssfshape.setLineWidth(4);

xssfshape.setLineStyle(0);

xssfshape.setLineStyleColor(0, 0, 0);

//Now flip this vertically.

//So it now will to be from bottom left edge of B3 to upper left edge of B2.

xssfshape.getCTShape().getSpPr().getXfrm().setFlipV(true);

xssfshape.getCTShape().getSpPr().getLn().addNewTailEnd().setType(

org.openxmlformats.schemas.drawingml.x2006.main.STLineEndType.TRIANGLE);

workbook.write(new FileOutputStream("CreateExcelLineShapes.xlsx"));

workbook.close();

}

}

结果:

50df3ee8-1f45-4c95-a0c3-9b3f99ea7a59.png

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值