C# 更新Excel
来源:互联网 发布:等离子数控切割机编程 编辑:程序博客网 时间:2024/06/01 08:04
需要添加连个COM链接库、
Microsoft Office 14.0 Object Library
Microsoft Excel 14.0 Object Library
/// <summary>
/// 更新Excel 的指定行指定列的内容
/// </summary>
/// <param name="templetFile">Excel 的路径</param>
/// <param name="row">指定Row (Cell 下面固定的可修改)</param>
/// <param name="value">需要更新的值</param>
public void UpdateExcel2(string templetFile, int row, string value)
{if (!File.Exists(templetFile))
{
return;
}
Microsoft.Office.Interop.Excel.Application xApp = new Microsoft.Office.Interop.Excel.Application(); ;
Microsoft.Office.Interop.Excel.Workbook xBook;
Microsoft.Office.Interop.Excel.Worksheet xSheet;
Microsoft.Office.Interop.Excel.Range rng2;
try
{
xApp.Visible = false;
xBook = xApp.Workbooks._Open(templetFile,
Missing.Value, Missing.Value, Missing.Value, Missing.Value
, Missing.Value, Missing.Value, Missing.Value, Missing.Value
, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
xSheet = (Microsoft.Office.Interop.Excel.Worksheet)xBook.Sheets[1];
rng2 = (Microsoft.Office.Interop.Excel.Range)xSheet.Cells[row, 2];
rng2.Value = value;
xBook.Save();
xSheet = null;
xBook = null;
}
catch (Exception)
{
xSheet = null;
xBook = null;
}
finally
{
xApp.Quit();
xApp = null;
GC.Collect();
}
}
阅读全文
0 0
- C# 更新Excel
- 教你用C#读写、删除、更新excel表格记录
- 【C#】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 报:“不能更新。数据库或对象为只读。”
- EXCEL 更新 ACCESS数据库。
- excel文件更新数据库
- Centos7.2 Redis数据库的安装与自启动配置
- 恒德无线远程城市照明管理系统
- 有关Java虚拟机内存机制以及回收机制的简单理解
- jQuery 选择器
- 如何防止SQL注入
- C# 更新Excel
- C3 粒子闪烁效果
- jmeter性能测试,基于scf框架的"java请求"接口封装、环境配置与测试
- PyCharm设置
- 菜鸟前端日记10 (原生JS--数组的操作方法)
- 高级篇 II: 作业的执行
- Makefile赋值符号的使用——"=" ":=" "?=" "+="
- 解决inteijj Idea 编辑器中 @Override 报错问题
- Swift与JS交互