0

I am using excellibrary to process excel files. Right now to open the file I am using

ef = Workbook.Load(file)

But if that file is opened somwhere else in another application when I try to access it I get the message:

The process cannot access the file '\OFFICE\MyDocumentsWD\VB2010\Projects\Excel File Checker\Excel File Checker\Test1.xls' because it is being used by another process.

I know that when using streamreader you can use fileshare option and I wonder if there is similar option when working with excellibrary? Or is there workaround to accomplish the same?

tshepang
  • 12,111
  • 21
  • 91
  • 136
user2824519
  • 43
  • 1
  • 1
  • 6

1 Answers1

1

Workbook does support streams so you have a couple of options.

I think you should open the file into a memory stream and then load from that memory stream with something like this:

MemoryStream memory = new MemoryStream(file);
ef = Workbook.Load(memory);

Alternatively you should be able to load the file using a filestream like this:

FileStream fileStream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read);
ef = Workbook.Load(fileStream);
Graymatter
  • 6,529
  • 2
  • 30
  • 50