C# 操作excel
来源:互联网 发布:三维设计软件 编辑:程序博客网 时间:2024/06/16 12:44
参考来源http://blog.csdn.net/dream_follower/article/details/70339849
1.添加引用 Microsoft.Office.Interop.Excel 15.0.0.0版本
2.添加声明
using Microsoft.Office.Interop.Excel;using Excel = Microsoft.Office.Interop.Excel;using System.Data.OleDb;using System.Diagnostics;
//读取 (只读)
//取得指定或活动工作簿中所有表单的集合。只读Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();_Workbook _wbk = app.Workbooks.Add(@"C:\Users\Desktop\123.xlsx");Sheets shs = _wbk.Sheets; _Worksheet _wsh = (_Worksheet)shs.get_Item(1); //获取下标工作表句柄int rowsint = _wsh.UsedRange.Cells.Rows.Count; //得到行数int columnsint = _wsh.UsedRange.Cells.Columns.Count; //得到列数Range r = _wsh.Range[_wsh.Cells[1, 1], _wsh.Cells[2, 2]]; //获取单元格范围string gdas34 = r.Value2[1,1]; //获取内部值
//写入 (读写)
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();object missing = System.Reflection.Missing.Value;//创建Excel对象Microsoft.Office.Interop.Excel.Workbook wb = excelApp.Workbooks.Open(@"C:\Users\Desktop\123.xlsx", missing, false, missing, missing, missing, missing, missing, missing, true, missing, missing, missing, missing, missing);//取得工作薄内第一个工作表Microsoft.Office.Interop.Excel.Worksheet ws = (Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets.get_Item(1);ws.Cells[4, 7] = "4213"; //单元格赋值ws.get_Range("C7", "D8").Value = r.Value;//范围粘贴赋值wb.Save();excelApp.Quit();wb = null;ws = null;excelApp = null;Process[] procs = Process.GetProcessesByName("excel");foreach (Process pro in procs){ pro.Kill();//没有更好的方法,只有杀掉进程}GC.Collect();
阅读全文
0 0
- c#如何操作excel??
- C#操作Excel!
- C# 操作 Excel
- C#访问Excel操作
- C# 操作 Excel
- C# 操作 Excel
- C#操作Excel
- C#操作Excel
- C# 操作 Excel
- C#操作EXCEL
- C#对Excel操作
- c#操作EXcel
- C# 操作 Excel
- C#操作Excel文档
- C# 操作Excel
- C#操作MS Excel
- C#操作Excel
- .Net C# 操作Excel
- java.lang.IllegalArgumentException: width and height must be > 0
- 【USACO1.3.3】回文串
- STA接入AP的过程分析
- c++ const理解
- 【安卓学习之常见问题】 多国语言横竖屏时,自动切换到默认语言(android:configChanges的使用)
- C# 操作excel
- python实例练习
- 敏捷方法--《启示录》
- MailBee.NET Objects撰写邮件教程(三):请求阅读/发送状态提示
- 单链表的基本操作
- XSS的原理分析
- Codevs 4246 奶牛的身高
- 查看app或是静态库动态库中的函数使用情况
- 集合系列LinkedList