You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cells at row 1 have horizontal alignment set to RIGHT.
Cells at row 2 have horizontal alignment set to CENTER.
When I set cell values programmatically by .setStringValue or .setDisplayText, horizontal alignment is reset to LEFT and need to set alignment again.
try (final InputStream input = Main.class.getResourceAsStream("stats.odt")) {
final var doc = OdfDocument.loadDocument(input);
final var odfTable = doc.getTableByName("statsTable");
odfTable.getRowByIndex(1).getCellByIndex(1).setStringValue("test");
odfTable.getRowByIndex(1).getCellByIndex(2).setDisplayText("hello world!");
odfTable.getRowByIndex(2).getCellByIndex(1).setDisplayText("next test");
odfTable.getRowByIndex(2).getCellByIndex(2).setDisplayText("very next test");
// need to set alignment of each cell, because it is reset to LEFT
odfTable.getRowByIndex(2).getCellByIndex(2).setHorizontalAlignment("center");
...
doc.save(new File("manipulated.odt"));
}
Am I missing something? Is this expected behavior? I would expect horizontal alignment to be unchanged while setting the cell value.
Using version 0.11.0 and .odt file with table was created with LibreOffice Writer 7.4.
The text was updated successfully, but these errors were encountered:
It does not sound like any desired behavior.
Just tested a bit adding new content in LibreOffice Writer and Calc.
In Writer: all new cell content is added left - likely in writing direction (as European I write from left ro right, so it is left aligned).
In Calc: Numbers are aligned right (as the calculation direction is still from their arabian origin right to left) and Text is aligned left.
Nevertheless, if something is middle aligned it should stay this way.
Most of the doc API was a gift from IBM Beijing, which was later forked to Simple API, which already abondoned due to heavy copy/pasted duplicated code to ODFDOM.
I would be happy if you could provide a pull-request.
It usally helps to start with a test that fails and the patch makes the regression test run.
I have .odt file with table called statsTable.
Cells at row 1 have horizontal alignment set to RIGHT.
Cells at row 2 have horizontal alignment set to CENTER.
When I set cell values programmatically by
.setStringValue
or.setDisplayText
, horizontal alignment is reset to LEFT and need to set alignment again.Am I missing something? Is this expected behavior? I would expect horizontal alignment to be unchanged while setting the cell value.
Using version 0.11.0 and .odt file with table was created with LibreOffice Writer 7.4.
The text was updated successfully, but these errors were encountered: