Create an Excel document using XML

xiaoxiao2021-03-17  180

The original example uses VB.NET written, the following use C # rewritten code original code: http://www.gotdot.com/community/Usersamples/details.aspx?sampleguid=ddbaecb9-a260-4656-9f22-300b6a1ce66c this example Use XML to create an Excel document, but do not need to install an Excel program at runtime.

DataSet mdsdata = new dataset (); mdsdata.tables.add ("myTable"); mdsdata.tables ["myTable"]. Column.Add ("ID"); mdsdata.tables ["myTable"]. Columns.add ( "Name"); mdsdata.tables ["myTable"]. Column.add ("password"); for (int i = 0; i <10; i ) {DATAROW DR = mdsdata.tables ["MyTable"]. Newrow (); DR ["ID"] = i; DR ["name"] = i; DR ["password"] = i; mdsdata.tables ["myTable"]. Rows.Add (DR);} SaveFileDialog Dialog1 = new SaveFileDialog (); dialog1.AddExtension = true; dialog1.CheckPathExists = true; dialog1.Filter = "Excel Workbooks (* .xls) | * .xls"; dialog1.OverwritePrompt = true; dialog1.Title = "Save Excel Formatted Report "; If (Dialog1.Showdialog () == DialogResult.ok) {Int Num2 = 0; int Num3 = mdsdata.tables [0]. ROWS.COUNT 1; INT Num1 = mdsdata.tables [0] .columns.count; Num2 = 0; string text1 = Dialog1.FileName; if (file.exists (text1)) {file.delete (text1);} streamwriter Writer1 = new streamwriter (Text1 , False); streamwriter Writer2 = Writer1; Writer2.writeline (""); Writer2.writeline ("

Excel.sheet / "?>"); Writer2.writeline (" "); Writer2.writeline (""); Writer2.writeline (" Automated Report Generator Example "); Writer2.writeLine (String.Format (" {0} t {1} z ", DateTime.now.tostring ("YYY-MM-DD"), DateTime.now.toString ("HH: mm: SS "))); Writer2.writeline (" Your Company Here "); Writer2.writeLine (" 11.6408 "); Writer2 .Writeline ("); Writer2.writeline (" "); Writer2.writeLine (" 8955 "); Writer2.writeline (" "); Writer2.writeline (" 480 "); Writer2.WriteLine ("

15 "); writer2.WriteLine (" False "); writer2.WriteLine (" False "); writer2.WriteLine (" " Writer2.writeline (""); Writer2.writeline ("