Hi,
//Using memory stream<o:p></o:p>
byte[] data = File.ReadAllBytes(“23 KB_xls”);<o:p></o:p>
MemoryStream stream = new MemoryStream(data);<o:p></o:p>
excelDocument1.Open(stream, FileFormatType.Excel97To2003);
Thank you.
Hi,
Thanks for your posting and using Aspose.Cells.
Please search on the internet how to read your file into byte array from shared point library. Once you have a byte array, you can convert into MemoryStream object and then from MemoryStream object you can create Workbook object and start using Aspose.Cells APIs.
Please see the following sample code and comments for your reference.
C#
string filePath = @“D:\Downloads\source.xlsx”;
//Your job is to read your sharepoint file in bytes
byte[] bytes = File.ReadAllBytes(filePath);
//Then you can convert your bytes into memory stream
MemoryStream ms = new MemoryStream(bytes);
ms.Position = 0;
Workbook workbook = new Workbook(ms);
workbook.Save(“output.xlsx”);
Hi,
Thanks for your posting and using Aspose.Cells.
Probably this file has some very old format which is not supported by Aspose.Cells. Could you please share your file for our investigation. We will look into it and help you asap.
I have attached two (.xls) files, none of the attached file is working in our case.
Hi,
Thanks for your posting and using Aspose.Cells.
You can detect the format of your excel files using the following code.
C#
string filePath = @“D:\Downloads\23+KB_xls.xls”;
var o = FileFormatUtil.DetectFileFormat(filePath);
Also, I have tested your files with the following code with the latest version: Aspose.Cells
for .NET v8.6.0.2 and it did not throw any exception. So you should download and try the latest version to check if your issue is resolved with this or not.
C#
string filePath = @“D:\Downloads\23+KB_xls.xls”;
Workbook workbook = new Workbook(filePath);
Hi,
Thanks for your posting and using Aspose.Cells.
Please try the following change and see if it makes any difference. Changes are highlighted in red color.
C#
stream.Position = 0;
Hi,
Hi,
Thanks for your feedback and using Aspose.Cells.
Please try the following code, this same code as yours except that it uses OpenBinaryStream() method changes are highlighted in red.
C#
using (SPSite docsite = new SPSite(uploadedDocPath))
{
using (SPWeb docweb = docsite.OpenWeb())
{
SPListItem item = docweb.GetListItem(uploadedDocPath);
SPFile objspFile = item.File;
byte[] byteArray = objspFile.OpenBinaryStream();
Stream stream = new MemoryStream(byteArray)
Aspose.Cells.LoadOptions loadoption = new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Excel97To2003);
Workbook excel = new Workbook(stream, loadoption);
}
}
Hi,
Hi,
Thanks for your posting and considering Aspose.Cells.
Please let us know the complete statck trace of your exception and also let us know if you get this error with any type of excel files or if there is some special excel file which is causing this exception.
Please see, there is no error in the following code
Stream stream = new MemoryStream(byteArray)
Aspose.Cells.LoadOptions loadoption = new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Excel97To2003);
Workbook excel = new Workbook(stream, loadoption);
All the error is present inside this code, so if you could fix it your issue will be resolved
byte[] byteArray = objspFile.OpenBinaryStream();
Somehow you are getting the problem of getting the wrong byte array.which is causing all the issue.
Please also let us know which component you are using
- Aspose.Cells for .NET
- Aspose.Cells for SharePoint
As i already mentioned above that i using .xls (97to2003) file and it works perfectly for other excel formats, i have been getting error only with this format .
Hi,
Thanks for your clarification and using Aspose.Cells.
It means your code is working fine with some of excel file (xls) but not working for other formats like xlsx etc.
So this exception might be causing because of this line
Aspose.Cells.LoadOptions loadoption = new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Excel97To2003);
Because this line will not work if excel format is XLSX, for xlsx the code should be like this
Aspose.Cells.LoadOptions loadoption = new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Xlsx);
It is better you first detect the load format of your excel file using the following code. Please incorporate your code in the main code and try again.
C#
string filePath = @“F:\Shak-Data-RW\Downloads\source.xlsx”;
byte[] bytesArray = File.ReadAllBytes(filePath);
MemoryStream ms = new MemoryStream(bytesArray);
FileFormatInfo info = FileFormatUtil.DetectFileFormat(ms);
LoadOptions opts = new LoadOptions(info.LoadFormat);
Workbook workbook = new Workbook(ms, opts);
Thanks for your reply, i don’t have any issue with .xlsx file only .xls(97to2003) is creating issue, using above code i m unable to get correct file format, its giving info object value - “unknown” .
Hi,
Thanks for your posting and using Aspose.Cells.
Please answer this questions for confirmation
1 - Does your problem occur with all types of xls and xlsx files?
2 - Does your problem occur with only some of xls and xlsx files?
3 - Please attach your xls/xlsx files which are not causing this exception
4 - Please attach your xls/xlsx files which are causing this problem.
Also now we will have to setup the environment to replicate your issue. Could you please let us
1 - Prerequisites of SharePoint
2 - Does it need SQ:L Server
3 - Does it need Visual Studio
It will be helpful if you could provide us detail steps which could help us prepare the setup which we could use to replicate this issue. Thanks for your cooperation.
Hi,
Hi,
Thanks for your detail instructions and using Aspose.Cells.
I have analyzed your having_issue.xls file and found it has wrong extension, it’s extension should be xlsx not xls.
So changing its name having_issue.xls to having_issue.xlsx will resolve your issue.
I have described the issue in detail in the word document attached with this post. Please read it to resolve this issue.