views:

144

answers:

1

I'm writing an xml file to be consumed by excel.

excel wants this:

<Cell><Data ss:Type="Number">25</Data></Cell>

I'm writing this...

<Cell>
   <Data ss:Type="Number">25</Data>
</Cell>

I get that EXCEL is picky, but since I'm using XElelments, how do i control the formatting of the output?

here is my code to write a cell.

foreach( var propertyInfo in fi )
                {

                    XElement oneCell =  new XElement( root + "Cell",
                                            new XElement( root + "Data",
                                                    new XAttribute( ss + "Type", "String" ), propertyInfo.GetValue( cv, null )
                                            )
                                        );
                    oneRow.Add( oneCell );

                }

How do i get that to output the cell and data on the same line?

Thanks,

Cal-

+1  A: 

Look this: XElement.Save Method

If you want to save indented XML, do not specify the DisableFormatting flag for options. This will remove all extraneous insignificant white space, and add appropriate insignificant white space so that the XML is properly indented. This is the default behavior, and the behavior of the overloads of the Save methods that do not take options as a parameter.

For more information, see Preserving White Space while Loading or Parsing XML and Preserving White Space While Serializing.

Rubens Farias