一个示例: class AppTest { private Excel.ApplicationClass _x; public static void Main0() { AppTest a = new AppTest(); a._x = new Excel.ApplicationClass(); a._x.UserControl = false; for (int i = 0 ;i < 4; i++) { a.SaveToXls("D:test" + i + ".xls"); // 本例是在D盘下建立的test文件夹 } a._x.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject((object) a._x); System.GC.Collect(); } private void SaveToXls(string filename) { Excel.WorkbookClass wb = (Excel.WorkbookClass) this._x.Workbooks.Add(System.Reflection.Missing.Value); for(int i = 1;i <= 4; i++) { this._x.Cells[i,1]=i.ToString(); this._x.Cells[i,2]="bbb2"; |