Eric Brown - Cal
Eric Brown - Cal

Reputation: 14379

c# writing excel file as xml

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-

Upvotes: 1

Views: 989

Answers (1)

Rubens Farias
Rubens Farias

Reputation: 57936

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.

Upvotes: 1

Related Questions