如何在不锁定的情况下打开Excel文件? [英] How can I open an Excel file without locking it?

查看:109
本文介绍了如何在不锁定的情况下打开Excel文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个构建Excel报告,然后为用户打开报告的过程.问题是,如果有人将文件保持打开状态,则文件将保持锁定状态,直到第一个人退出excel文件之前,其他人都无法构建报告.

I have a process that builds an Excel report, then opens it for the user. The problem is if someone leaves the file open, it stays locked and nobody else can build the report until the first person exits the excel file.

是否可以使用Process.Start或Microsoft的Interop.Excel库打开Excel文件而不锁定它?

Is there a way to open an Excel file without locking it, using either Process.Start or Microsoft's Interop.Excel library?

每次运行报告时,我都使用Interop库来构建文件,并将其作为静态文件名保存在运行该应用程序的共享网络文件夹中

I use the Interop library to build the file each time the report is run, and save it as a static file name in a shared network folder where this application is run from

using Excel = Microsoft.Office.Interop.Excel;

...

xlsBook.SaveAs(newFileName, Excel.XlFileFormat.xlWorkbookNormal);

并使用Process.Start

Process.Start(newFileName);

推荐答案

您可以尝试以只读模式打开文件:

You can try to open the file in read-only mode:

var app = new Microsoft.Office.Interop.Excel.Application();
var workbook = app.Workbooks.Open(filename, ReadOnly: true);

或者您可以尝试以共享模式保存它:

Or you can try to save it in shared mode:

workbook.SaveAs(filename, AccessMode: XlSaveAsAccessMode.xlShared);

这篇关于如何在不锁定的情况下打开Excel文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆