0

I have an app that reads data from an Excel workbook. It fails when the workbooks is already opened by someone else. I'm not writing to this workbook at all, so read-only would be just fine for my purposes.

Is there a way to read from an Excel workbook that someone else already has open? This is the beginning of the code that accesses the workbook and where it fails.

foreach (var worksheet in Workbook.Worksheets(excelInput))
    {
    foreach (var row in worksheet.Rows.Skip(1))
        {
            DataRow dr = dt.NewRow();
            foreach (var cell in row.Cells)
John
  • 313
  • 5
  • 9
  • Where does it fail? – Michael Gunter Mar 10 '17 at 16:39
  • You say read only would be fine, so have you tried that? You can specify read only when calling the Open method. Docs: https://msdn.microsoft.com/en-gb/library/microsoft.office.interop.excel.workbooks.open.aspx – Equalsk Mar 10 '17 at 16:42
  • I looked at that, but was told that Office would need to be installed on the machine that's running the app, and they don't want to do that. – John Mar 10 '17 at 18:11
  • Take sometime to search on SO. Check [**`this`**](http://stackoverflow.com/a/13803824/1652222) and [**`this`**](http://stackoverflow.com/a/8906733/1652222) link. – ManishChristian Mar 10 '17 at 18:38
  • At the first foreach, Michael. Error Message: The process cannot access the file (my path and file) – John Mar 10 '17 at 18:45
  • I did search SO, Manish, but found no help, including the two links you shared. We can't use Microsoft.Office.Interop.Excel here. Thanks, though! – John Mar 10 '17 at 18:50

0 Answers0