我需要使用 POI 向 xls-document 添加形状(特别是圆形)。所以,我写了以下代码:
private void drawLabel(HSSFSheet sheet, HSSFCell cell) {
final short columnIndex = (short) cell.getColumnIndex();
final int rowIndex = cell.getRowIndex();
HSSFClientAnchor anchor = new HSSFClientAnchor(60, 60, 200, 200, columnIndex, rowIndex, columnIndex, rowIndex);
anchor.setAnchorType(ClientAnchor.MOVE_DONT_RESIZE);
HSSFSimpleShape shape = sheet.getDrawingPatriarch().createSimpleShape(anchor);
shape.setShapeType(HSSFSimpleShape.OBJECT_TYPE_OVAL);
...
}
有用。但是,如果我尝试以编程方式更改列宽(例如sheet.setColumnWidth(0, 5 * 256);
(假设已将形状添加到列索引 == 0 的单元格中)),圆形会扭曲并变成椭圆形(尽管锚的类型设置为MOVE_DONT_RESIZE
)。我的方法有什么问题,有没有办法绘制一个不会与相应单元格一起调整大小的形状?