Excel 互操作文件重命名
我有一个程序,它使用 Excel 互操作例程根据 Excel 模板生成一堆报告。
这一切都可以接受,但我试图找出的副作用是如何防止用户覆盖原始模板。
由于我无法控制的原因,它必须是优秀的,据我所知,这意味着模板必须位于所有用户都可以读/写的 Intranet 上的某个地方。 (如果它是存档,那么用户运行的应用程序将无法用新数据填充它)
我正在考虑尝试通过重命名文件并将其移动到网络上的其他位置来解决这个问题,但我不确定这是否可能。 (因此是线程的名称)
此外,可能有一种更好的方法来解决我没有想到的问题。
I have a program that is using the excel interop routines to generate a bunch of reports based on an excel template.
This all works acceptably, but the side effect that I am trying to figure out is how to prevent the users from overwriting the original template.
It has to be excel for reasons out of my control, which as far as I can tell means that the template has to be on the intranet somewhere that all the users can read / write. (If it's an archive, then the application run by the users won't be able to fill it with new data)
I was thinking of trying to address this by renaming the file and moving it somewhere else on the network, but I'm not sure if this is even possible. (Thus the name of the thread)
Also, there might be an even better way of addressing the problem that I just haven't thought of.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有尝试过,但我认为如果你把它放在只读共享中,你应该仍然能够打开它并向打开的文档写入内容,只是它无法将其保存回该位置,相反,您必须使用
SaveAs
将其保存到其他位置。否则,如果我错了,那么就按照您自己所说的那样,将其放入只读共享中,然后在开始进行互操作之前将其复制到其他地方。只需使用 File.Copy 复制它,可能会复制到返回的名称< a href="http://msdn.microsoft.com/en-us/library/system.io.path.gettempfilename.aspx" rel="nofollow">Path.GetTempFileName 以确保您不这样做覆盖其他任何内容,最后只需使用
SaveAs
将其保存到用户想要的任何位置。I haven't tried, but I think that if you put it in a read-only share, you should still be able to open it and write things to the open document, just that it can't save it back to that location, instead you'll have to use
SaveAs
to save it somewhere else.Otherwise, if I'm wrong about that, then do as you said yourself in that you put it in a read-only share and then copy it somewhere else before you start doing the interop. Just use File.Copy to copy it, maybe to the name returned Path.GetTempFileName to make sure you don't overwrite anything else, and then in the end, just use
SaveAs
to save it wherever the user wants.