Methods for generating Excel files in C # and methods for Excel.dll component generation
Source: Internet
Author: User
Excel| Build Excel
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 [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.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service