We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Opening an Excel File using a stream

Thread ID:

Created:

Updated:

Platform:

Replies:

18214 Aug 26,2004 06:50 AM UTC Mar 8,2005 11:50 AM UTC WinForms 3
loading
Tags: XlsIO
Richard Howarth
Asked On August 26, 2004 06:50 AM UTC

Hi, I am having a problem opening an .xls file using a stream as a parameter, it raises the following error: "Index was out of range. Must be non-negative and less than the size of the collection" the c# code is below: FileStream FS = new FileStream(@"c:\temp\test.xls", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); IWorkbook myWorkBook = ExcelUtils.Open(FS); IWorksheet sheet = myWorkBook.Worksheets[0]; after watching the myWorkBook interface the worksheet collection is empty, however when I open the worksheet using the code: IWorkbook myWorkBook = ExcelUtils.Open(@"c:\temp\test.xls"); it works as expected with no errors, can you explain the problem, as the help for ExcelRW is very limited, with no examples in this area. Also I noticed on the Forum, that reading from a .xls file which is open is not suppoted as yet, has this been fixed? Thanks Richard Howarth

Administrator [Syncfusion]
Replied On August 26, 2004 11:06 AM UTC

Hi Richard, 1) Could you try adding this line FileStream FS = new FileStream("Template.xls", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); FS.Seek(0, SeekOrigin.Begin); IWorkbook myWorkbook = ExcelUtils.Open(FS); Also, make sure you are using version 2.1.0.9. If not please log on to Direc Trac to download the latest version of Essential ExcelRW. It has many enhancements over the previous versions. 2) An XLS file that is already opened can be opened using ExcelRW in the procedure mentioned above. Using FileStream to open the file in Read mode and then opening the filestream using ExcelRW. Please let me know if you have any questions. Thanks. Best regards, Stephen. >Hi, > >I am having a problem opening an .xls file using a stream as a parameter, it raises the following error: > >"Index was out of range. Must be non-negative and less than the size of the collection" > >the c# code is below: > >FileStream FS = new FileStream(@"c:\temp\test.xls", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); >IWorkbook myWorkBook = ExcelUtils.Open(FS); >IWorksheet sheet = myWorkBook.Worksheets[0]; > >after watching the myWorkBook interface the worksheet collection is empty, however when I open the worksheet using the code: > >IWorkbook myWorkBook = ExcelUtils.Open(@"c:\temp\test.xls"); > >it works as expected with no errors, can you explain the problem, as the help for ExcelRW is very limited, with no examples in this area. > >Also I noticed on the Forum, that reading from a .xls file which is open is not suppoted as yet, has this been fixed? > >Thanks >Richard Howarth

Geir Aamodt
Replied On March 4, 2005 12:26 PM UTC

I''m also having problems with opening the Excel as an MemoryStream. Are receiving this Exception: "System.IndexOutOfRangeException : Index was outside the bounds of the array" when executing the "myWorkBook = ExcelUtils.Open(memStream);" statement (see below). Any clues on how to solve this? --------------- code snippet --------------- public void ImportProductData(byte [] excelFile) { IWorkbook myWorkBook=null; using (MemoryStream memStream = new MemoryStream(excelFile)) { memStream.Seek(0, SeekOrigin.Begin); myWorkBook = ExcelUtils.Open(memStream); // Create the worksheet object IWorksheet sheet = myWorkBook.Worksheets[0]; //..code deleted } } --------------- code snippet --------------- (The excelFile parameter contains a byte representation of the excel file and I have tested it to be 100% correct.) System information: I''m using ExcelRW.Base version 3.0.1.0 and are working on an Excel 2003 document. All on WinXP SP2 machine with .NET FW 1.1 Best regards, Geir

Administrator [Syncfusion]
Replied On March 8, 2005 11:50 AM UTC

Hi Geir, Are you able to open the same file without any problem when you open it from file?, I just want to make sure that its not a problem opening that specific file since there are sutuations where some files can be opened using MS Excel and not using ExcelRW. Could you please create a Direc-Trac incident and send me the file that you are not able to open from memory stream. Thanks, Stephen. >I''m also having problems with opening the Excel as an MemoryStream. Are receiving this Exception: "System.IndexOutOfRangeException : Index was outside the bounds of the array" when executing the "myWorkBook = ExcelUtils.Open(memStream);" statement (see below). > >Any clues on how to solve this? > >--------------- code snippet --------------- >public void ImportProductData(byte [] excelFile) >{ > IWorkbook myWorkBook=null; > > using (MemoryStream memStream = new MemoryStream(excelFile)) > { > memStream.Seek(0, SeekOrigin.Begin); > myWorkBook = ExcelUtils.Open(memStream); > > // Create the worksheet object > IWorksheet sheet = myWorkBook.Worksheets[0]; > > //..code deleted > } >} >--------------- code snippet --------------- > >(The excelFile parameter contains a byte representation of the excel file and I have tested it to be 100% correct.) > >System information: >I''m using ExcelRW.Base version 3.0.1.0 and are working on an Excel 2003 document. All on WinXP SP2 machine with .NET FW 1.1 > >Best regards, > >Geir >

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;