写入在Excel中打开的文件 [英] Write to file that is open in Excel
问题描述
FileSystemWatcher
来查看文件什么时候关闭,然后覆盖这个文件。 不是一个好主意,因为你可能会丢失数据。整个原因excel锁定文件是这样,你不会意外覆盖在Excel中所做的更改。
Suppose I have a program running that periodically adds information to a .CSV file. Is there a way to write to the file while it is already open in Excel? Obviously the changes wouldn't be noticed until the file was re-opened in Excel, but as it stands right now, I'm catching IOException and just starting a new .csv file if the current one is already open.
Excel seems to open the file in exclusive mode, so the only way I can think of would be to write your changes to a temporary file, and then use FileSystemWatcher
to see when the file is closed, and overwrite the file.
Not a very good idea, as you could lose data. The whole reason excel locks the file is so that you don't accidentally overwrite changes made in excel.
这篇关于写入在Excel中打开的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!