本文概述
- Apache POI绘制形状示例
让我们来看一个例子。
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 excel图片
- apache poi excel单元格类型
- apache poi单元多种风格
- apache poi绘制边界
- apache poi excel单元格属性
- apache poi隐藏行
- apache poi excel文档标题
- apache poi excel字体
- apache poi合并单元