An example:
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"); This example is the test folder created under D disk
}
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";
this._x.cells[i,3]= "' ccc3";
this._x.cells[i,4]= "' Aaa4";
}
Wb. Saved = true;
This._x.activeworkbook.savecopyas (filename);
}
}
"Note: Running in vs.net is to add Excel.dll components, the Excel component Vs.net itself is not, and the following is the method for generating Excel.dll." 】
1. To ensure that the machine itself to install Office.
2. Copy the Excel9.olb file under [C:/Program files/microsoft office/office: Default installation path] to the [c:/visual studio.net/sdk/v1.1/bin:vs.net installation path] path.
3. Open Visual Studio. Net2003 command prompt, run tlbimp excel9.olb Excel.dll, the C:/visual component is generated under [Studio.net/sdk/v1.1/bin Excel.dll].
4. Adding a Excel.dll reference to the project is OK.