在Button时间中
{
Excel.Application excel= new Excel.Application();
int rowIndex=1;
int colIndex=0; excel.Application.Workbooks.Add(true);
DataTable table=GetData();
foreach(DataColumn col in table.Columns)
{
colIndex++;
excel.Cells[1,colIndex]=col.ColumnName;
}
foreach(DataRow row in table.Rows)
{
rowIndex++;
colIndex=0;
foreach(DataColumn col in table.Columns)
{
colIndex++;
excel.Cells[rowIndex,colIndex]=row[col.ColumnName].ToString();
}
}
excel.Visible=true; }
运行报错:找不到类型或命名空间 名称Excel
{
Excel.Application excel= new Excel.Application();
int rowIndex=1;
int colIndex=0; excel.Application.Workbooks.Add(true);
DataTable table=GetData();
foreach(DataColumn col in table.Columns)
{
colIndex++;
excel.Cells[1,colIndex]=col.ColumnName;
}
foreach(DataRow row in table.Rows)
{
rowIndex++;
colIndex=0;
foreach(DataColumn col in table.Columns)
{
colIndex++;
excel.Cells[rowIndex,colIndex]=row[col.ColumnName].ToString();
}
}
excel.Visible=true; }
运行报错:找不到类型或命名空间 名称Excel
解决方案 »
- WPF Listbox 的奇怪问题
- 阻塞主线程,让子线程创建的窗口活动,能办到吗
- C#如何调用非托管DLL?
- 用button.click事件给datagridview排序遇到一点问题
- 请教关于软件界面中的日期与时间
- 关于C#多台设备共用一个串口的解决方案
- 如何判断time1 = 15:45:32是接近于rime2 = 13:30:30,还是更接近于rime3 = 16:00:00
- 怎样把MSSQL表中相同字段的数相加
- 存储过程和Form窗体关系,各位大侠请进
- 寻求VS.Net下C#的可排序的网格控件!
- 请问在c#中怎么将一个数字组成的字符串转换为一个整数?
- 请教一个超初级的问题,如何才能调用一个按钮的点击事件?
选择COM
到都面找 Microsoft Excel 11.0 Object Library
确实
{
Sw.Write(dc.ColumName+"\t"); //输出列名,你可以改成中文名称
}
Sw.WriteLine();foreach(DataRow dr in this.DataTable1.Rows)
{
for(int i=0;i<this.DataTable1.Columns.Count;i++)
{
Sw.Write(dr[0].ToString()+"\t")
}
Sw.WriteLine();
}