我需要将我的数据表数据转换为此模式(在MS Excel中打开)。
ReferId Name Salary
2457165 ABC 10000
<Worksheet ss:Name="Sheet1">
<ss:Table>
<ss:Row>
<ss:Cell ss:StyleID="s27"><Data ss:Type="String">Refer_ID</Data></ss:Cell>
<ss:Cell ss:StyleID="s27"><Data ss:Type="String">Name</Data></ss:Cell>
<ss:Cell ss:StyleID="s27"><Data ss:Type="String">Salary</Data></ss:Cell>
</ss:Row>
<ss:Row>
<ss:Cell><Data ss:Type="String">2457165</Data></ss:Cell>
<ss:Cell><Data ss:Type="String">ABC</Data></ss:Cell>
<ss:Cell><Data ss:Type="String">10000</Data></ss:Cell>
</ss:Row>
</ss:Table>
我尝试用DataTable.WriteXml()
System.IO.StringWriter writer = new System.IO.StringWriter();
dt.WriteXml(writer, XmlWriteMode.WriteSchema, true);
但架构不同。我尝试了一些循环遍历数据表的行和列。但坚持下去,任何帮助都会受到关注
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="s27">
<Font x:Family="Swiss" ss:Color="#0000FF" ss:Bold="1"/>
</Style>
<Style ss:ID="s21">
<NumberFormat ss:Format="yyyy\-mm\-dd"/>
</Style>
<Style ss:ID="s22">
<NumberFormat ss:Format="yyyy\-mm\-dd\ hh:mm:ss"/>
</Style>
<Style ss:ID="s23">
<NumberFormat ss:Format="hh:mm:ss"/>
</Style>
</Styles>
答案 0 :(得分:1)
试试xml linq:
User