c#中导出excel的几种方法

c#中导出excel的几种方法

ID:19438389

大小:36.00 KB

页数:9页

时间:2018-10-02

c#中导出excel的几种方法_第1页
c#中导出excel的几种方法_第2页
c#中导出excel的几种方法_第3页
c#中导出excel的几种方法_第4页
c#中导出excel的几种方法_第5页
资源描述:

《c#中导出excel的几种方法》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、C#代码1#region导出当前页到Excel中23//按下导出按钮4privatevoidbutton7_Click(objectsender,EventArgse)5{6print(dataGridView1);7}8publicvoidprint(DataGridViewdataGridView1)9{10//导出到execl11try12{13//没有数据的话就不往下执行14if(dataGridView1.Rows.Count==0)15return;16//实例化一个Excel.Application对象17Microsoft.Office.Interop.Excel

2、.Applicationexcel=newMicrosoft.Office.Interop.Excel.Application();1819//让后台执行设置为不可见,为true的话会看到打开一个Excel,然后数据在往里写20excel.Visible=false;2122//新增加一个工作簿,Workbook是直接保存,不会弹出保存对话框,加上Application会弹出保存对话框,值为false会报错23excel.Application.Workbooks.Add(true);24//生成Excel中列头名称25for(inti=0;i

3、umns.Count;i++)26{27excel.Cells[1,i+1]=dataGridView1.Columns[i].HeaderText;28}29//把DataGridView当前页的数据保存在Excel中30for(inti=0;i

4、adingcadrescomplainthatworkistoocomplicated,toomuchresponsibility,thepressureistoolarge,toomuchemphasisonthedifficultyofthework.Forexample,noncoalmine1{2for(intj=0;j

5、i].Value.ToString();7}8else9{10excel.Cells[i+2,j+1]=dataGridView1[j,i].Value.ToString();11}12}13}1415//设置禁止弹出保存和覆盖的询问提示框16excel.DisplayAlerts=false;17excel.AlertBeforeOverwriting=false;1819//保存工作簿20excel.Application.Workbooks.Add(true).Save();21//保存excel文件22excel.Save("D:"+"\KKHMD.xls");2324

6、//确保Excel进程关闭25excel.Quit();26excel=null;2728}29catch(Exceptionex)30{31MessageBox.Show(ex.Message,"错误提示");32}he"governingforthepeople","Nomattertheinterestsofthemasses"conceptunderstandingisnotinplace.Thespecificworktreatswiththedeployment,afewleadingcadrescomplainthatworkistoocomplicated,too

7、muchresponsibility,thepressureistoolarge,toomuchemphasisonthedifficultyofthework.Forexample,noncoalmine1}2#endregion导出从数据库中查询到的所有的数据到Excel中C#代码3#region导出全部数据到Excel中,可弹出保存对话框,但没用SaveFileDialog45publicvoidprintAll(System.Data.DataTabledt)6{7//导

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。