Stoppt die Vorratsdatenspeicherung! Jetzt klicken & handeln!Willst du auch bei der Aktion teilnehmen? Hier findest du alle relevanten Infos und Materialien:
Toenda Software Development  ·  toendaCMS - Your ideas ahead  ·  Flickr  ·  PTS Group

» Home -> Archive -> AODL - The .NET Interface for ODF files

AODL - The .NET Interface for ODF files
Published on 22.04.2008 - 11:16 h in ProgrammingCode Snippet

In my spare free time im working on a simple movie database to have a sortable collection list of my movies. Hitherto i've do that with the Spreadsheet of OpenOffice.
After some time of development i've finished a first betaversion of my tool and starts to work on a importer.
The best way to import ODF files is to extract the content files fromt the zip-encoded files and read the xml. This steps were already done by the OpenOffice team and somebody has implement this steps in a .NET interface library. I've found this project (AODL, Sourceforge) and starts to working with it. Bug it has a bad bug.
I have a big table with many cells in many rows, but some of this cell - also severals side by side - are empty. And OpenOffice creates on this empty cells a XML attribute called "table:number-columns-repeated" which descripes how many copies of this cells came after this one.
The AODL assembly do'snt has this attribute calculation implemented so that if've sit down and do that. So, here's the bugfix and the assembly.

Link: Download
Here is the sourcecode to fix the problem:
Add this to the Cell data object:
/// 
/// Gets or sets the number of columns repeated.
/// 
/// The number of columns repeated.
public int NumberOfColumnsRepeated { get; set; }

The method CreateTableCell()
...
...
...

//Create a new Cel
Cell cell = new Cell(this._document, node);
IContentCollection iColl = new IContentCollection();
//Recieve CellStyle
IStyle cellStyle = this._document.Styles.GetStyleByName(cell.StyleName);

if(cellStyle != null)
{
	int i=0;
	cell.Style				= cellStyle;
	if(cellStyle.StyleName == "ce244")
		i=1;
}
//No need for a warning


// this is the new code:::

// check for thew "table:number-columns-repeated" attribute
int repeating = 0;

if(node.Attributes.Count > 0) {
	foreach(XmlAttribute attr in node.Attributes) {
		if(attr.Name == "table:number-columns-repeated") {
			int.TryParse(attr.Value, out repeating);
			cell.NumberOfColumnsRepeated = repeating;
		}
	}
}

// :::end of new code



//Create the cells content
foreach(XmlNode nodeChild in cell.Node.ChildNodes)
{
	IContent iContent		= this.CreateContent(nodeChild);

	if(iContent != null)
	{
		iColl.Add(iContent);
	}
	else
	{
		if(this.OnWarning != null)
		{
			AODLWarning warning	
= new AODLWarning("Couldn't create IContent from a table cell.");
warning.InMethod
= AODLException.GetExceptionSourceInfo(new StackFrame(1, true));
warning.Node
= nodeChild;
this.OnWarning(warning);
}
}
}

cell.Node.InnerXml = "";

foreach(IContent iContent in iColl)
cell.Content.Add(iContent);
return cell;

...
...
...

The method CreateTableRow()
...
...
...

foreach(IContent iContent in iColl)
{
if(iContent is Cell)
{


// this is the new code:::
	// new way
	Cell cell = (Cell)iContent;
	cell.Row = row;

	row.CellCollection.Add(cell);

	if(cell.NumberOfColumnsRepeated > 0) {
		for(int i = 1; i < cell.NumberOfColumnsRepeated; i++) {
			XmlNode copyNode = cell.Node.CloneNode(true);
			copyNode.Attributes.RemoveAll();
			row.CellCollection.Add(this.CreateTableCell(copyNode));
		}
	}

// :::end of new code

	// old way ...
	//( (Cell)iContent ).Row = row;
	//row.CellCollection.Add(cell);
}
else if(iContent is CellSpan)
{
	((CellSpan)iContent).Row	= row;
	row.CellSpanCollection.Add(iContent as CellSpan);
}
else
{
	if(this.OnWarning != null)
	{
		AODLWarning warning
= new AODLWarning("Couldn't create IContent from a row node. Content is unknown table row content!");
warning.InMethod
= AODLException.GetExceptionSourceInfo(new StackFrame(1, true));
warning.Node
= iContent.Node;
this.OnWarning(warning);
}
}
}

...
...
...

0 Comments



No comments posted!



Post new comment

Enter the following code


Name
eMail
Website
Message




Powered by toendaCMS My xing profile kostenloser Counter bloggerei.de - deutsches Blogverzeichnis