First useExcelDesign the table we want to generate:
Save itXMLTable:
The generatedBook1.xmlCopy to project and open:
FindTableNode.SS: expandedrowcount = "2"Delete
Next we will see the title we just entered.
row
cell SS: styleid = " S23 " > data SS: Type =" string "> name data > cell >
cell SS: styleid = " S23 " > data SS: Type =" string "> score data > cell >
</Row>
Below is the data
<Row>
cell SS: styleid = " S24 " > data SS: Type =" string "> Michael data > cell >
cell SS: styleid = " S24 " > data SS: Type =" Number "> 80 data > cell >
</Row>
Cut the data row and replace it with {0}
table SS: expandedcolumncount = " 2 " SS: expandedrowcount =" 2 " X: fullcolumns = " 1 "
X: fullrows="1"SS: defaultcolumnwidth="54"SS: defaultrowheight="14.25">
<Row>
cell SS: styleid = " S23 " > data SS: Type =" string "> name data > cell >
cell SS: styleid = " S23 " > data SS: Type =" string "> score data > cell >
</Row>
{0}
</Table>
Okay, you can start writing.Program.
Datatable dtdata = new datatable ();
DtdataThe data is (name, score)
//Here is the row just cut in XML
String ROW = @"<Row>
cell SS: styleid = " " S24 " "> data SS: Type =" " string " "> {0} data > cell >
cell SS: styleid = " " S24 " "> data SS: Type =" " Number " ">{1} data > cell >
</Row>";
List <string> rows = new list <string> ();
Foreach (datarow DR in dtdata. Rows)
{
Rows. Add (string. Format (row, Dr ["Name"], Dr ["Score"]);
}
Streamreader reader = new streamreader ("XMLName. xml");
Streamwriter writer = new streamwriter ("New excel.xls")
Writer.Write (reader. readtoend (), String. Join (""R" n", Row. toarray ()));
Writer. Flush ();
Writer. Close ();
Reader. Close ();