用C#快速往Excel写数据

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

ÓÃC#¿ìËÙÍùExcelдÊý¾Ý¡¡¡¡±¾Ê¾ÀýÊÇÓÃÓÚ½«ListViewÖеÄÄÚÈݵ¹Èëµ½Excel£¬Óë³£ÓõÄÖðµ¥Ôª¸ñд²»Í¬µÄÊÇ£¬±¾Àý×Ó²ÉÓÃÊý¾ÝдÈëµ½rangeµÄ·½·¨¡£¸Ã·½·¨Ð§ÂÊÃ÷ÏԽϸߡ£¡¡¡¡Excel.Applicationapp=newExcel.ApplicationClass();¡¡¡¡if(app==null)¡¡¡¡{¡¡¡¡MessageBox.Show(ExcelÎÞ·¨Æô¶¯);¡¡¡¡return;¡¡¡¡}¡¡¡¡app.Visible=true;¡¡¡¡Excel.Workbookswbs=app.Workbooks;¡¡¡¡Excel.Workbookwb=wbs.Add(Missing.Value);¡¡¡¡Excel.Worksheetws=(Excel.Worksheet)wb.Worksheets[1];¡¡¡¡Excel.Ranger=ws.get_Range(A1,H1);¡¡¡¡object[]objHeader={±êÌâ1,±êÌâ2,±êÌâ3,¡¡¡¡±êÌâ4,±êÌâ5,±êÌâ6,¡¡¡¡±êÌâ7,±êÌâ8};¡¡¡¡r.Value=objHeader;¡¡¡¡if(lv.Items.Count0)¡¡¡¡{¡¡¡¡r=ws.get_Range(A2,Missing.Value);¡¡¡¡object[,]objData=newObject[this.lv.Items.Count,8];¡¡¡¡foreach(ListViewItemlviinlv.Items)¡¡¡¡{¡¡¡¡objData[lvi.Index,0]=lvi.Text;¡¡¡¡objData[lvi.Index,1]=lvi.SubItems[1].Text;¡¡¡¡objData[lvi.Index,2]=lvi.SubItems[2].Text;¡¡¡¡objData[lvi.Index,3]=lvi.SubItems[3].Text;¡¡¡¡objData[lvi.Index,4]=lvi.SubItems[4].Text;¡¡¡¡objData[lvi.Index,5]=lvi.SubItems[5].Text;¡¡¡¡objData[lvi.Index,6]=lvi.SubItems[6].Text;¡¡¡¡objData[lvi.Index,7]=lvi.SubItems[7].Text;¡¡¡¡}¡¡¡¡r=r.get_Resize(lv.Items.Count,8);¡¡¡¡r.Value=objData;¡¡¡¡r.EntireColumn.AutoFit();¡¡¡¡}¡¡¡¡app=null;

1 / 1
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功