Class TableSheets
Moves tables between documents and spreadsheets, so a table's numbers and formulas are
calculated by the same engine as a Workbook's.
A cell is a formula when its text starts with =, or when it holds a field whose instruction
does -- the form Word writes for a table formula, such as = SUM(ABOVE). Word's position
words become ranges: ABOVE is the cells over the formula in its column, below the header
rows; LEFT the cells before it in its row; BELOW and RIGHT likewise. A number format
switch such as \# "0.00" is dropped. Every other cell holds its text, or a number when its
text is one.
DocumentModel model = new DocumentModel(new Document());
try {
model.setDocument(Document.read(new ByteArrayInputStream(("<table><tr><th>Region</th>"
+ "<th>Q1</th></tr><tr><td>North</td><td>120</td></tr></table>").getBytes()),
Document.Format.HTML));
} catch (IOException e) {
Log.e(e);
}
// wordprocessing has a Table, and so does com.codename1.ui.table
com.codename1.wordprocessing.Table table = null;
for (int i = 0; i < model.size(); i++) {
if (model.getDocument().get(i) instanceof com.codename1.wordprocessing.Table) {
table = (com.codename1.wordprocessing.Table) model.getDocument().get(i);
}
}
// every formula field shows its value
Document recalculated = TableSheets.recalculate(model.getDocument());
// com.codename1.ui has a Sheet too, hence the full name
com.codename1.spreadsheet.Sheet s = TableSheets.toSheet(table, new Workbook(), "Table 1");
Log.p(s.getCellText(1, 1));
-
Method Summary
Modifier and TypeMethodDescriptionstatic Stringaddress(int row, int column) The spreadsheet address of a cell, such asB3for row 2, column 1.static StringexcelFormula(String formula, Table t, int row, int column) A Word table formula in the spreadsheet engine's syntax, for the cell atrow,column.static TablefromSheet(Sheet s, DocumentModel ids) A table made from a sheet: one paragraph per cell, formulas as fields showing their values, merged regions as merges.static booleanhasFormulas(Table t) Whether a table holds any formula.static DocumentCalculates every table formula in a document and shows each value in its field.static SheetCopies a table into a new sheet of a workbook.static TableWrites a sheet's cells back into a table of the same shape, keeping each cell's paragraphs and formatting and changing only the text of what changed.
-
Method Details
-
hasFormulas
Whether a table holds any formula.
Parameters
t: the table
Returns
true when a cell is a formula
-
toSheet
-
fromSheet
A table made from a sheet: one paragraph per cell, formulas as fields showing their values, merged regions as merges.
Parameters
-
s: the sheet -
ids: the model whose document the table is for; its ids are reserved for the table and its paragraphs
Returns
the table, not yet in the document
-
-
update
Writes a sheet's cells back into a table of the same shape, keeping each cell's paragraphs and formatting and changing only the text of what changed.
Parameters
-
t: the table -
s: the sheet, astoSheetmade it and then edited
Returns
the updated table, or
titself when nothing changed -
-
recalculate
-
excelFormula
A Word table formula in the spreadsheet engine's syntax, for the cell at
row,column.Parameters
-
formula: the formula, with or without= -
t: the table it is in -
row: its row -
column: its column
Returns
the formula with a leading
= -
-
address
The spreadsheet address of a cell, such as
B3for row 2, column 1.Parameters
-
row: from zero -
column: from zero
Returns
the address
-
-