I am working on an Excel generated file with Apache POI. The file must be xlsx and not xls.
I need to draw some arrows, but I can't draw an upward arrow.
I use XSSFClientAnchor
to create my arrow and specify row/col 1 and row/col 2.
XSSFClientAnchor(int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2)
It only works when col 1 > col 2 and row 1 > row 2. So I can't draw an upward arrow. If I try to change values to get an upward arrow, my file generated is not readable by Excel. Excel repairs it but then the arrows are hidden.
Here is my code:
public static void test() {
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet("linechart");
XSSFDrawing pat = sheet.createDrawingPatriarch();
XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, 10, 10, 5, 5);
XSSFSimpleShape shape = pat.createSimpleShape(anchor);
shape.setShapeType(ShapeTypes.LINE);
shape.setLineWidth(4);
shape.setLineStyle(0);
shape.setLineStyleColor(0, 0, 0);
FileOutputStream fileOut;
try {
fileOut = new FileOutputStream(
"C:\\monfichier" + new Date().toString().replace(':', '_') + ".xlsx");
wb.write(fileOut);
fileOut.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
If I try to replace:
XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, 10, 10, 5, 5);
with:
XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, 5, 5, 10, 10);
it's ok...
Could you test this and say me what do you think about this. It really difficult to find informations about POI, and I didn't found this problem...