apache poi绘制形状

本文概述

  • Apache POI绘制形状示例
HSSFSimpleShape类用于在电子表格中绘制形状。此类提供了一个setShapeType()方法,该方法有助于绘制各种形状,例如椭圆形,直线形,矩形等。
让我们来看一个例子。
Apache POI绘制形状示例
package poiexample; import java.io.FileOutputStream; import java.io.OutputStream; import org.apache.poi.hssf.usermodel.HSSFClientAnchor; import org.apache.poi.hssf.usermodel.HSSFPatriarch; import org.apache.poi.hssf.usermodel.HSSFSimpleShape; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; public class ShapeExample { public static void main(String[] args) {Workbook wb = new HSSFWorkbook(); try (OutputStream os = new FileOutputStream("srcmini.xls")) { Sheet sheet = wb.createSheet("Sheet"); Row row = sheet.createRow(4); // Creating a row Cell cell = row.createCell(1); // Creating a cell HSSFPatriarch patriarch = (HSSFPatriarch) sheet.createDrawingPatriarch(); HSSFClientAnchora = new HSSFClientAnchor( 0, 0, 1023, 255, (short) 1, 0, (short) 1, 0 ); HSSFSimpleShape shape = patriarch.createSimpleShape(a); shape.setShapeType(HSSFSimpleShape.OBJECT_TYPE_OVAL); wb.write(os); }catch(Exception e) { System.out.println(e.getMessage()); } } }

【apache poi绘制形状】输出:
apache poi绘制形状

文章图片

    推荐阅读