Setting visibility of sheets, rows or columns does not work using XPropertySet::setPropertyValue(). It does not throw an exception or anything, it just does not change the property value.
I use a very similar code for PowerPoint and it works perfectly fine.
The intention is to preprocess the file and then convert it to pdf via jodconverter.
My current code:
private void processCalc(@NonNull XComponent document) throws Exception {
foreachSheet(document, sheet -> {
setProperty(sheet, "IsVisible", true);
final var cursor = sheet.createCursor();
final var usedAreaCursor = Lo.qi(XUsedAreaCursor.class, cursor);
usedAreaCursor.gotoStartOfUsedArea(false);
usedAreaCursor.gotoEndOfUsedArea(true);
final var columnRowRange = Lo.qi(XColumnRowRange.class, usedAreaCursor);
setVisible(columnRowRange.getRows());
setVisible(columnRowRange.getColumns());
});
}
private static void setVisible(XInterface x) throws IndexOutOfBoundsException, WrappedTargetException, PropertyVetoException, UnknownPropertyException {
final var indexAccess = Lo.qi(XIndexAccess.class, x);
for (int i = 0; i < indexAccess.getCount(); i++) {
final var byIndex = indexAccess.getByIndex(i);
final var range = Lo.qi(XCellRange.class, byIndex);
setProperty(range, "IsVisible", true);
}
}
public static void setProperty(XInterface object, String name, boolean value) throws PropertyVetoException, WrappedTargetException, UnknownPropertyException {
final var propertySet = Lo.qi(XPropertySet.class, object);
propertySet.setPropertyValue(name, value);
}
public static void foreachSheet(XComponent document, FailableConsumer<XSpreadsheet, Exception> consumer) throws Exception {
final var spreadsheetDocument = Lo.qiOptional(XSpreadsheetDocument.class, document);
if (spreadsheetDocument.isEmpty()) {
throw new IllegalArgumentException("Provided document was not of type CALC!");
}
foreachSheet(spreadsheetDocument.get(), consumer);
}
public static void foreachSheet(XSpreadsheetDocument spreadsheetDocument, FailableConsumer<XSpreadsheet, Exception> consumer) throws Exception {
final var sheets = spreadsheetDocument.getSheets();
final var indexedSheets = Lo.qi(XIndexAccess.class, sheets);
final var count = indexedSheets.getCount();
for (var i = 0; i < count; i++) {
final var sheet = Lo.qi(XSpreadsheet.class, indexedSheets.getByIndex(i));
consumer.accept(sheet);
}
}