c# - 更新已打开的 Excel 工作簿 C#
问题描述
我有经常从传感器和外部数据源更新的 excel 文档。
在 C# 中,我打开文件并处理数据。我需要做什么来更新我的工作表变量而不尝试再次重新打开文件。
void test(){
Application xlApp = new Application();
excelBook = xlApp.Workbooks.Open(filePath);
Worksheet sheet = excelBook.Worksheets[sheetName];
if (sheet != null){
var r = sheet.UsedRange.Value2;
while(true){
string json = JsonConvert.SerializeObject(r, Formatting.Indented);
//do work with the json data here
//........
//make sure we have latest updated sheet
//these are not working.
excelBook.RefreshAll();
excelBook.AutoUpdateSaveChanges = true;
}
}
}
解决方案
推荐阅读
- javascript - 从 JavaScript 退出 Chrome 全屏 --start-fullscreen
- linux - 在 Linux CentOS 中注销当前用户
- encryption - GLib 使用哪种加密密钥大小?
- postgresql - Postgres:让重复的子查询更有效率?
- azure-devops - 如何查询初始“剩余工作”
- sql - 选择专家查询
- codeigniter - Codeigniter4 中的重定向问题
- spring-batch - StaxEventItemWriter XML 标头
- database - 在 oracle 中使用 rowid 条件时合并不起作用
- python - Gensim -- [Errno 2] 没有这样的文件或目录:'model.wv'