Opening open Excel files

dera support,


for an application, I need to process the contents of an excel worksheet which is on a network share. However, the file will probably be open by another user.

Problem. When the user clicks Save when I am processing the file, Excel hangs untill I release the Aspose.cells object. Sometimes Excel also crashed.

Question. How can I load an excel into Aspose.Cells without blocking the original owner from saving the file.

Also, when I open the excel when nobody has it open, I should not pose any lock on it at all. Is this possible ?

thank you

guido

Hi Guido,

Thanks for your posting and using Aspose.Cells.

We were not able to observe this issue with the latest version: Aspose.Cells for .NET 8.2.2. When file is loaded by Aspose.Cells, Excel is able to load it and user is also able to save the contents.

Please note, when Aspose.Cells saves the workbook, it creates a new file, the contents of old file are deleted or overwritten. So, suppose if some file say C:\abc.xlsx is already open in Excel, then Aspose.Cells will not be able to save to C:\abc.xlsx and it will give exception saying

The process cannot access the file ‘C:\abc.xlsx’ because it is being used by another process.

So, you must release abc.xlsx file from Excel in order Aspose.Cells could save it in abc.xlsx file.

If you open “c:\abc.xlsx” file in Aspose.Cells and then also open it in MS-Excel. MS-Excel will be able to open the file too. It means, Aspose.Cells does not lock the file from opening. Instead, Aspose.Cells read the contents of file and leave the file as it is i.e unlocked.

Please see the following code. You can also try it at our end. Here all the bytes of the files are read and Aspose.Cells creates a workbook object from memory stream, so there is no question of locking the file arises.

C#


string filePath = @“F:\Shak-Data-RW\Downloads\test.xls”;


//Read all bytes of the file

byte[] fileData = File.ReadAllBytes(filePath);


//Create memory stream from the read bytes

MemoryStream ms = new MemoryStream();

ms.Write(fileData, 0, fileData.Length);


//Open the workbook from memory stream now

Workbook workbook = new Workbook(ms);