[求助]生成Excel的问题???
我想实现这样的功能:当我点击下面的按钮时<asp:button Text="生成Excel" ID="ExcelButton" runat="server" OnClick="ExcelButton_Click"/>
能够把库里的数据生成Excel,我有2个问题不明白
1、在cs文件里 ,顶部应该包含Excel的什么类
using System;
...
2、这个ExcelButton_Click事件应该怎么写呢?
我写了下面的这个做为测试,可是有错误
编译器错误信息: CS0246: The type or namespace name 'Excel' could not be found (are you missing a using directive or an assembly reference?)
protected void ExcelButton_Click(object sender, System.EventArgs e)
{
string filename="";
Excel.ApplicationClass oExcel;
oExcel = new Excel.ApplicationClass();
oExcel.UserControl = false;
Excel.WorkbookClass wb = (Excel.WorkbookClass) oExcel.Workbooks.Add(System.Reflection.Missing.Value);
for(int i = 1;i <= 5; i++)
{
oExcel.Cells[i,1]=i.ToString();
oExcel.Cells[i,2]="第2列";
oExcel.Cells[i,3]="第3列";
oExcel.Cells[i,4]="第4列";
}
wb.Saved = true;
filename= Server.MapPath("test.xls");
oExcel.ActiveWorkbook.SaveCopyAs(filename);
oExcel.Quit();
System.GC.Collect();
}
做过这个功能的朋友,请指点一二,谢谢先!!!