用C#生成Excel文件的方法和Excel.dll组件生成的方法

作者:袖梨 2022-07-02

一个示例:
class AppTest
{
private .ApplicationClass _x;
public static void Main0()
{
AppTest a = new AppTest();
a._x = new Excel.ApplicationClass();
a._x.UserControl = false;
for (int i = 0 ;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 {
this._x.Cells[i,1]=i.ToString();
this._x.Cells[i,2]="’bbb2";

相关文章

精彩推荐