Use XML to generate EXCEL

Source: Internet
Author: User

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 ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.