Add table to ODT file

 4 posts  » Share this        Feedicon
Replies: 3 - Last Post: March 20, 2010 09:17
by: Darius Damalakas
showing 1 - 4 of 4
 
Posted: March 19, 2010 07:46 by chessie_1013
Hello,

I've tried to do the following operations:

1)Open a odt file
2) Add a new table
3) Save file

All goes fine but when I try to open the new saved odt file, OpenOffice tells me that the file is corrupt.

I used following piece of code:

TextDocument document = new TextDocument();
document.Load(filePath);

//document.New();
Table table = TableBuilder.CreateTextDocumentTable(document,"table3","table",3,3,16.99,false,true);

//Create a standard paragraph
Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
//Add some simple text
paragraph.TextContent.Add(new SimpleText(document, "Some cell text"));
//Insert paragraph into the first cell
table.RowCollection[0].CellCollection[0].Content.Add(paragraph);

//Add table to the document
document.Content.Add(table);
//Save the document
document.SaveTo(destination);
odt = new Odt(destination);
odt.Save(destination);

Can somebody tell me what I did wrong?
 
Posted: March 19, 2010 08:50 by Darius Damalakas
I used AODL mostly to open ODT file and populate it with data (for example, add more rows to table, fill with data from DB, etc).

So can not help you exacty with this, sorry
 
Posted: March 19, 2010 09:22 by chessie_1013
Could you post a piece of code with an example about how to add rows to an existing table.

I could workarround the solution with adding the table header to the template and add my rows to it.

thanks
 
Posted: March 20, 2010 09:17 by Darius Damalakas
That is very easy. Just make a call like this:
table.Rows.Add(new Row(table));


I actually created a simple (chaotic) utility, which reads all localization resources, and outputs everything into single big excel file (with excel i mean actually ods file).


Here is the file which does actual writing to ods file:

http://bitbucket.org/dariusdamalakas/resman/src/tip/resman/Output/ods/OdsOutput.cs
Replies: 3 - Last Post: March 20, 2010 09:17
by: Darius Damalakas
  • Powered by:
Terms of Use; Privacy Policy; Copyright ©2008-2010 (revision 20100827.958a3e4)
 
 
loading
Please Confirm