Read-Only

If I have an 2003 Excel document open in Excel, and open it with Aspose, it opens fine (I'm assuming in Read-Only).

However, if I open a 2007 Excel document in Excel, and I try to use Aspose with it, I get:

System.IO.IOException was unhandled
Message="The process cannot access the file 'test.xlsm' because it is being used by another process."

How do I force them to be opened as read-only?

Found a manual way to do it:

Dim xl As New Aspose.Cells.Workbook()

Dim fs As New IO.FileStream(filename, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.ReadWrite)

Dim sr As New IO.StreamReader(fs)

xl.Open(sr.BaseStream, FileFormatType.Excel2007Xlsm)

If there is an easier way to force read-only, please let me know.

------------------------------------------------------------

On a completely different note: Is there a function I can use where I can pass in a filename and have it determine the FileFormatType I need to use?

Hi,

Well, yes, Aspose.Cells for .NET can auto-detect FileFormatType, so if you don't provide the format type (e.g.., .xls, .xlt, .xlsx, .xlsm etc. ), it will determine the file format type automatically.

e.g..,

Dim xl As New Aspose.Cells.Workbook()

Dim fs As New IO.FileStream(filename, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.ReadWrite)

Dim sr As New IO.StreamReader(fs)

xl.Open(sr.BaseStream)

Thank you.

Amjad Sahi:

Hi,

Well, yes, Aspose.Cells for .NET can auto-detect FileFormatType, so if you don't provide the format type (e.g.., .xls, .xlt, .xlsx, .xlsm etc. ), it will determine the file format type automatically.

e.g..,

Dim xl As New Aspose.Cells.Workbook()

Dim fs As New IO.FileStream(filename, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.ReadWrite)

Dim sr As New IO.StreamReader(fs)

xl.Open(sr.BaseStream)

Thank you.

Ah thanks. Apparently if you use the LoadData function, instead of Open, it throws a fit about file format, so I thought it was the same for both.