建议你将其中的数据倒入到doc文件中,然后让他们想怎么打就这么打
解决方案 »
- 多个excel合并到一个excel中生成多个sheet。。但用这个代码会使源excel中的空sheet也生成到目标excel中而产生很多空的sheet。求改进
- C#中通过FTP遍服务器上指定文件夹中所有的文件名?
- 请问C#中如何解析下面的XML文件?
- 请问DirectoryService能不能远程操作IIS?
- 用一台主机同时监控多台客机的桌面?
- 急!!!关于类型转换的问题
- <%# DataBinder.Eval(Container.DataItem,"字段名").ToString()%>
- 请教c#文件共享问题!?
- 關於重寫datagridview控件的問題
- 使用SOCKET通信的时候中文的问题
- 如何在listview控件中实现图标的拖放
- 一个查询方面的问题!请多指教
说明;
1。首先你要在你的项目里添加对Microsoft Excel object library的引用;
2。在当前的Form里加入一个progressBar1;
3。假设你已经得到了数据(DataSet ds)并且绑定到了你的DataGrid1,而且DataGrid1里面加入了CheckBox(假设为第一列);
4。那么下面的代码你可以仿照写一下,应该就没问题了。
private void btExport_Click(object sender, System.EventArgs e)
{
if(DataGrid1.VisibleRowCount==0)return;
this.Cursor =Cursors.WaitCursor;
Excel.Application myExcel=new Excel.Application();
myExcel.Application.Workbooks.Add(true);Excel.Workbook myBook=myExcel.Workbooks[1];
Excel.Worksheet mySheet=(Excel.Worksheet)myBook.Worksheets[1];progressBar1.Visible =true;
int j=0,k=0;
progressBar1.Value=0;
progressBar1.Maximum =ds.Tables[0].Rows.Count;
for(j=0;j<ds.Tables[0].Rows.Count;j++)
{
if (DataGrid1[j,0])//判断是否选中本条记录
{
myExcel.Cells[j,k]=ds.Tables[0].Rows[j][k] ;
progressBar1.Value +=1;
progressBar1.Refresh;
}
}
progressBar1.Visible =false;
this.Cursor =Cursors.Default;MessageBox.Show("数据导出完成!",this.Text);
myExcel.Visible=true;
不过我一般就是自己写.csv文件,这样的话可以想倒入什么就倒入什么。
Response.Clear();
Response.Buffer= true;
Response.Charset="GB2312";
Response.AppendHeader("Content-Disposition","attachment;filename=FileName.htm");
Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
Response.ContentType =" text/HTML";//在些设定一下格式
this.EnableViewState = false;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN",true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.DataGrid1.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
Case ".asf"
ContentType = "video/x-ms-asf"
Case ".avi"
ContentType = "video/avi"
Case ".doc"
ContentType = "application/msword"
Case ".zip"
ContentType = "application/zip"
Case ".xls"
ContentType = "application/vnd.ms-excel"
或者 ContentType = "application/vnd.ms-xls"
Case ".gif"
ContentType = "image/gif"
Case ".jpg", "jpeg"
ContentType = "image/jpeg"
Case ".wav"
ContentType = "audio/wav"
Case ".mp3"
ContentType = "audio/mpeg3"
Case ".mpg", "mpeg"
ContentType = "video/mpeg"
Case ".rtf"
ContentType = "application/rtf"
Case ".htm", "html"
ContentType = "text/html"
Case ".txt"
ContentType = "text/plain"
Case ".pdf"
ContentType = "application/pdf"
Case Else
ContentType = "application/octet-stream"
End Select