看看这几篇,应该对你有帮助
http://www.chinabs.net/csharp/default.asp?infoid=50
http://www.yesky.com/20020313/1601534.shtml
http://www.c-sharpcorner.com/winforms/ExcelReadMG.asp
http://www.chinabs.net/csharp/default.asp?infoid=50
http://www.yesky.com/20020313/1601534.shtml
http://www.c-sharpcorner.com/winforms/ExcelReadMG.asp
解决方案 »
- C#备份SQL数据库
- 关于C#制作web浏览器的问题
- 请教一个中学题库数据库设计问题
- 请教关于MessageBox的问题
- SqlParameter有几点迷惑
- 价值10W的新闻采集源代码提供!可以自动生成HTML(C#开发)
- WinForm中 ToolStrip.OverflowButton 的外观(文字或图片)如何设置并生效
- 关于TcpListener和TcpClient的两个不明白的地方,请大家指教
- 基于.NET的B/S架构客服系统,欢迎PP
- 在c#中如何使用progressbar控件显示记录的读取进度????
- 讨论c#的执行效率问题
- WinForm程序中,DataGrid在显示出DataTable数据后,怎样改变列的显示顺序及列的可见性?
public void PrintData(string sqlcommand)
{//将当前显示的数据以excel下载到客户端的通用函数
string fileExcel, filePath, fileName, strLine;
System.IO.FileStream objFileStream;
System.IO.StreamWriter objStreamWriter;
Random nRandom = new Random(DateTime.Now.Millisecond);
fileExcel = "t" + nRandom.Next().ToString() + ".xls";
filePath = Server.MapPath("\\netsafe\\print_data");
fileName = filePath + "\\" + fileExcel;
objFileStream = new System.IO.FileStream(fileName, System.IO.FileMode.OpenOrCreate , System.IO.FileAccess.Write);
objStreamWriter = new System.IO.StreamWriter(objFileStream,System.Text.Encoding.Unicode);
sqlCommand1.CommandText=sqlcommand;
SqlDataReader dr;
sqlCommand1.Connection.Open();
dr = sqlCommand1.ExecuteReader();
strLine = "";
for (int i = 0; i <= dr.FieldCount-1; i++)
{
strLine = strLine + dr.GetName(i).ToString() + Convert.ToChar(9);
}
objStreamWriter.WriteLine(strLine);
strLine = "";
while (dr.Read())
{
for (int i = 0; i <= dr.FieldCount-1; i++)
{
strLine = strLine + dr.GetSqlValue(i) + Convert.ToChar(9);
}
objStreamWriter.WriteLine(strLine);
strLine="";
}
dr.Close();
sqlCommand1.Connection.Close();
objStreamWriter.Close();
objFileStream.Close();
Response.Write("<script language=JavaScript>window.open('print_data/"+fileExcel+"','',',,status=yes,location=no,toolbar=yes,scrollbars=yes,,directories=yes,menubar=yes,,')</script>");
}