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 ("
Excel.sheet / "?>"); Writer2.writeline ("
15 WindowTopY> "); writer2.WriteLine ("