-
Notifications
You must be signed in to change notification settings - Fork 6
FAQ
final OdsFactory factory = OdsFactory.create();
final AnonymousOdsFileWriter writer = factory.createWriter();
final OdsDocument document = writer.document();
writer.saveAs(new File(...));
This will create an empty document (without any sheet). LibreOffice will create a blank sheet on opening.
Option 1: without indices
final Table table = document.addTable("table1");
final TableRow row = table.nextRow(); // could be table.getRow(10) or table.getRow("A10");
TableCellWalker cell = row.getWalker();
// do something with cell A1
cell.next()
// do something with cell A2
Option 2: with indices
final Table table = document.addTable("table1");
final TableRow row = table.getRow(0)
TableCell cell = row.getOrCreateCell(0);
// do something with cell A1
You can tell it to FastODS: this will fasten the writing.
final Table table = document.addTable("table1", rowCapacity, columnCapacity);
When you pass a name to OdsFactory.createWriter
, you get a NamedOdsFileWriter
, when you don't you get an AnonymousOdsFileWriter
. They are very different:
- with an anonymous writer, all the document will be stored in memory before writing. This is easier and faster.
- with a named writer, the data is written by bunches. This is slower and you have to register styles before you start creating the tables. This may be the only solution when you have a very low memory.
You have a NamedOdsDocument
from a NamedOdsFileWriter
. You will use the various NamedOdsDocument.addXXXStyle
to register styles, then you will use NamedOdsDocument.freezeStyles
. If you try to use a style that was not registred, you will get an IllegalStateException
. With NamedOdsDocument.debugStyles
, the exception is replaced by a log message of level severe.
The data styles are what LO calls "formats". First, you have to create the data styles:
final DataStylesBuilder dsb = DataStylesBuilder.create(Locale.XXX);
// now, use the builders. See the API for data styles buiders
dsb.XXXStyleBuilder().field1(value1).field2(value2). ...
final DataStyles ds = dsb.build();
Then, you will pass the data styles to the factory:
final AnonymousOdsFileWriter writer = OdsFactory.create().dataStyles(ds).createWriter();
You just have to build
the data style, and set it on the cell.
final DataStyle intStyle = new FloatStyleBuilder("custom-int-datastyle", this.locale).decimalPlaces(8)
.groupThousands(true).build();
cell.setDataStyle(intStyle);
This question is outdated: buildHidden()
was replaced by hidden().build()
if the style is not hidden by default, build()
else.
FastODS create some styles as "visible styles" and some others as "hidden styles" by default:
- data styles are hidden by default, but can be visible (
visible() method of the builder
) - cell, row, column and table styles are visible by default, but can be hidden (
hidden() method of the builder
) - page styles are visible and cannot be hidden.
## Q10. How do I create a link?
Link to a table:
String targetTableName;
cell.setText(
Text.builder().par().span("<before link>").link("link text", targetTableName).span("<after link>")
.build());
Link to an URL:
URL url;
cell.setText(
Text.builder().par().span("<before link>").link("link text", url).span("<after link>")
.build());
Link to a file:
File file;
cell.setText(
Text.builder().par().span("<before link>").link("link text", file).span("<after link>")
.build());
First, create the style:
TableCellStyle style = TableCellStyle.builder("my-style").backgroundColor(SimpleColor.GRAY).fontWeightBold().build(); // hidden().build() for automatic styles
For a cell:
cell.setStyle(style);
For a row:
row.setDefaultCellStyle(style);
For a column:
final TableColumnStyle style = TableColumnStyle.builder("col-style").defaultCellStyle(cellStyle).build();
table.setColumnStyle(0, style);