非常好用的 C# winform 操作EXCEL文件源代码
private void button1_Click(object sender, System.EventArgs e) {//保存为EXCEL文件 if(this.listView1.Items.Count0) { MyRange =MyWorkSheet.get_Range("A2",Missing.Value); object [,] MyData = new Object[this.listView1.Items.Count,3]; foreach(ListViewItem lvi in this.listView1.Items) { MyData[lvi.Index,0] = lvi.Text; MyData[lvi.Index,1] = lvi.SubItems[1].Text; MyData[lvi.Index,2] = lvi.SubItems[2].Text; } MyRange = MyRange.get_Resize(this.listView1.Items.Count,3); MyRange.Value2= MyData; MyRange.EntireColumn.AutoFit(); } MyExcel= null; } catch(Exception Err) { MessageBox.Show("调用EXCEL程序时出现错误!"+Err.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information); } }
文件列表
C#操作EXCEL文件.rar
(预估有个19文件)
File.suo
8KB
Form1.cs
6KB
bin
Release
Interop.Excel.dll
1.04MB
Interop.Microsoft.Office.Core.dll
212KB
Interop.VBIDE.dll
56KB
File.exe
28KB
obj
Interop.Excel.dll
1.04MB
用户评论