简体   繁体   English

C#将Excel文件写入XML

[英]c# writing excel file as xml

I'm writing an xml file to be consumed by excel. 我正在写一个供excel使用的xml文件。

excel wants this: excel希望这样:

<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? 我知道EXCEL有点挑剔,但是由于我使用的是XElelments,我如何控制输出的格式?

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- Cal-

Look this: XElement.Save Method 看一下: XElement.Save方法

If you want to save indented XML, do not specify the DisableFormatting flag for options. 如果要保存缩进的XML,请不要为选项指定DisableFormatting标志。 This will remove all extraneous insignificant white space, and add appropriate insignificant white space so that the XML is properly indented. 这将删除所有无关紧要的空白,并添加适当的无关紧要的空白,以便正确缩进XML。 This is the default behavior, and the behavior of the overloads of the Save methods that do not take options as a parameter. 这是默认行为,也是不将选项作为参数的Save方法的重载行为。

For more information, see Preserving White Space while Loading or Parsing XML and Preserving White Space While Serializing . 有关更多信息,请参见在加载解析XML时保留空白和在序列化时保留空白

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM