Difference between revisions of "AODL example 1"
From Apache OpenOffice Wiki
m |
m |
||
Line 1: | Line 1: | ||
− | <b>Create a Spreadsheet document and add a table with | + | <b>Create a Spreadsheet document and add a table with formatted cells.</b> |
<syntaxhighlight lang="c"> | <syntaxhighlight lang="c"> | ||
//Create new spreadsheet document | //Create new spreadsheet document | ||
Line 24: | Line 24: | ||
//Insert table into the spreadsheet document | //Insert table into the spreadsheet document | ||
spreadsheetDocument.TableCollection.Add(table); | spreadsheetDocument.TableCollection.Add(table); | ||
− | spreadsheetDocument.SaveTo(" | + | spreadsheetDocument.SaveTo("formatted.ods"); |
</syntaxhighlight> | </syntaxhighlight> | ||
Latest revision as of 12:33, 22 May 2022
Create a Spreadsheet document and add a table with formatted cells.
//Create new spreadsheet document
SpreadsheetDocument spreadsheetDocument = new SpreadsheetDocument();
spreadsheetDocument.New();
//Create a new table
Table table = new Table(spreadsheetDocument, "First", "tablefirst");
//Create a new cell, without any extra styles
Cell cell = table.CreateCell();
//Add a paragraph to this cell
Paragraph paragraph = ParagraphBuilder.CreateSpreadsheetParagraph(spreadsheetDocument);
//Create some Formated text
FormatedText fText = new FormatedText(spreadsheetDocument, "T1", "Some Text");
//fText.TextStyle.TextProperties.Bold = "bold";
fText.TextStyle.TextProperties.Underline = LineStyles.dotted;
//Add formated text
paragraph.TextContent.Add(fText);
//Add paragraph to the cell
cell.Content.Add(paragraph);
//Insert the cell at row index 2 and column index 3
//All need rows, columns and cells below the given
//indexes will be build automatically.
table.InsertCellAt(2, 3, cell);
//Insert table into the spreadsheet document
spreadsheetDocument.TableCollection.Add(table);
spreadsheetDocument.SaveTo("formatted.ods");
Back to the AODL examples overview.