1、在哪可以下载一些比较好的WinForm第三方控件,比如类似DataGrid、打印的控件等等,谢谢了;
2、老问题了,你们都用什么方式将数据导出到Excel中?我在网上看到的这种是没问题,可惜速度太慢了,感觉在VB6.0中很轻松就可以将数据导出去而且速度也很快,你们都是怎么做的,各位大哥给介绍一种好的方法把,最好能详细点! private System.Data.DataTable GetData()
{
SqlConnection conn= new SqlConnection(@"Server=127.0.0.1;Initial Catalog=GMIT;Uid=sa;Pwd=;");
SqlDataAdapter adapter= new SqlDataAdapter("select * from HardWare ",conn); DataSet ds= new DataSet();
try
{
adapter.Fill(ds,"HardWare");
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
return ds.Tables[0];
} //按钮
private void button1_Click_1(object sender, System.EventArgs e)
{
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;
}
2、老问题了,你们都用什么方式将数据导出到Excel中?我在网上看到的这种是没问题,可惜速度太慢了,感觉在VB6.0中很轻松就可以将数据导出去而且速度也很快,你们都是怎么做的,各位大哥给介绍一种好的方法把,最好能详细点! private System.Data.DataTable GetData()
{
SqlConnection conn= new SqlConnection(@"Server=127.0.0.1;Initial Catalog=GMIT;Uid=sa;Pwd=;");
SqlDataAdapter adapter= new SqlDataAdapter("select * from HardWare ",conn); DataSet ds= new DataSet();
try
{
adapter.Fill(ds,"HardWare");
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
return ds.Tables[0];
} //按钮
private void button1_Click_1(object sender, System.EventArgs e)
{
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;
}
已经出了Volume 3了...
谢谢了!
2、如下(转贴)
--如果从SQL数据库中,导出数据到Excel,如果Excel文件已经存在,而且已经按照要接收的数据创建好表头,就可以简单的用:
insert into OPENROWSET('MICROSOFT.JET.OLEDB.4.0'
,'Excel 5.0;HDR=YES;DATABASE=c:\test.xls',sheet1$)
select * from 表
--如果Excel文件不存在,也可以用BCP来导成类Excel的文件,注意大小写:
--导出表的情况
EXEC master..xp_cmdshell 'bcp 数据库名.dbo.表名 out "c:\test.xls" /c -/S"服务器名" /U"用户名" -P"密码"'--导出查询的情况
EXEC master..xp_cmdshell 'bcp "SELECT au_fname, au_lname FROM pubs..authors ORDER BY au_lname" queryout "c:\test.xls" /c -/S"服务器名" /U"用户名" -P"密码"'说明.c:\test.xls 为导入/导出的Excel文件名.
sheet1$ 为Excel文件的工作表名,一般要加上$才能正常使用.
但只能导出数据无法把字段名也一起导出来!
比如表
字段名:A B
1 1
2 2我只能导出
1 1
2 2我想要这种结果
A B
1 1
2 2
马上就结贴,这样就可以把自段名也导出来了。EXEC master..xp_cmdshell 'bcp "select ''字段1'' ,''字段2'' union all SELECT * FROM northwind..orders ORDER BY orderid" queryout C:\Book2.xls -c -S"(local)" -U"sa" -P""'