我喜欢使用 apache POI 在 excel 中绘制圆形。我有以下代码。运行此代码时没有错误。但是当我打开输出的 excel 文件时,它说“文件错误:数据可能已丢失”并且输出的 excel 文件中没有圆形。
// Get template file path.
FileInputStream in = new FileInputStream("C:\template.xls");
// Create work book.
Workbook wb = WorkbookFactory.create(in);
sheet = wb.getSheetAt(0);
// Draw the circle shape.
HSSFPatriarch patriarch = (HSSFPatriarch) sheet.createDrawingPatriarch();
HSSFClientAnchor a = new HSSFClientAnchor(1023, 255, 1023, 255, (short) 7, 10, (short) 7, 10);
HSSFSimpleShape shape1 = patriarch.createSimpleShape(a);
shape1.setShapeType(HSSFSimpleShape.OBJECT_TYPE_OVAL);
shape1.setNoFill(true);
FileOutputStream out = new FileOutputStream("C:\output.xls");
wb.write(out);
out.close();
PS:excel模板文件(“C:\template.xls”)已经有其他图形(形状)。
谢谢