Hi
I’m trying to open a password encrypted Excel workbook from a Sharepoint SPListItem object following the code snippet:
LoadOptions loadOptions = new LoadOptions();
loadOptions.Password = config.WorkbookPassword;
Workbook workbook = new Workbook(item.File.OpenBinaryStream(), loadOptions);
The code is throwing an exception at line:
Workbook workbook = new Workbook(item.File.OpenBinaryStream(), loadOptions);
Exception details:
System.ArgumentOutOfRangeException was unhandled
Message=“Index and count must refer to a location within the buffer.\r\nParameter name: bytes”
Source=“mscorlib”
ParamName=“bytes”
StackTrace:
at System.Text.UnicodeEncoding.GetString(Byte[] bytes, Int32 index, Int32 count)
at Aspose.Cells.Workbook.ԯ(ࣂ )
at Aspose.Cells.Workbook.ԝ(Stream Ԡ, LoadOptions ԟ)
at IOZ.UFAG.Workflows.PublishingWorkflow.Documents.ExcelHandler.HandleDocument(SPListItem item, PublishingConfiguration config, Boolean saveAsXPS)
at IOZ.UFAG.Workflows.PublishingWorkflow.Documents.DocumentFactory.PrepareDocument(SPListItem item, PublishingConfiguration config, Boolean saveAsXPS)
at IOZ.UFAG.Workflows.PublishingWorkflow.PublishingWorkflow.HandlePublishConfig(PublishingConfiguration publishConfig)
After some Googeling I found this here. I’m actually using V5.3.0
Hi,
Could you give us the Password for opening your template Excel file, so that we could check your issue.
Thank you.
Just forgot about that.
The password is super88
Hi,
Thanks for providing us the password.
I have found the issue as you have mentioned using your sample code and template file.
I have logged your issue into our issue tracking system with an id: CELLSNET-25266. We will look into your issue soon.
Thank you.
Hi,
It seems like this issue is not with your template file, but with xlsx files.
I created two files, one is source.xls and the other is source.xlsx and tested them with this code.
For source.xls, it ran fine, but for source.xlsx it gave me the same error i.e
System.ArgumentOutOfRangeException was unhandled
C#
string path = @“F:\Downloads\issue\source.xlsx”;
LoadOptions opt = new LoadOptions();
opt.Password = “super”;
Workbook workbook = new Workbook(path, opt);
Hi,
Unfortunately I need to process Excel files from Office XP up to Office 2010.
Is there a way to easily overcome this issue?
Hi,
We will support the encryption for Excel 2010 in the next bug fixed version that is expected within 3-5 days from now.
Thank you.
Hi,
Please download Aspose.Cells for .NET v5.3.1.4. We have fixed the issue you
mentioned.
We have already supported reading Excel 2010 encrypted workbook.
Hi,
I’ve just tried your provided version of Aspose.Cells. It is now possible to open password encrypted Excel files without the mentioned ArgumentOutOfRangeException but I have noticed another issue.
Although it is possible to open password encrypted files I can not iterate through the workbooks “Worksheets” collection respectively the workbook.Worksheets.Count property return 0. It seems like this property is still sort off protected. I have tested this behaviour with *.xls and *.xlsx files and noticed the issue only within *.xlsx files.
Furthermore the application throws an “Aspose.Cells.CellsException” when the workbook should be saved to a stream.
LoadOptions loadOptions = new LoadOptions();
loadOptions.Password = config.WorkbookPassword;
Workbook workbook = new Workbook(item.File.OpenBinaryStream(), loadOptions);
foreach(Worksheet worksheet in workbook.Worksheets)
{
// do something like search/replace text etc.
}
MemoryStream memoryStream = new MemoryStream();
workbook.Save(memoryStream, SaveFormat.Xlsx); // SaveFormat is depending on file extension
The exception is thrown at line:
workbook.Save(memoryStream, SaveFormat.Xlsx);
Exception details:
Aspose.Cells.CellsException was unhandled
Message=“Dot not support export a wbook without normal worksheet to excel 2007 format”
Source=“Aspose.Cells”
StackTrace:
at ?.?.?()
at ?.?.?()
at Aspose.Cells.Workbook.Save(Stream stream, SaveOptions saveOptions)
at IOZ.UFAG.Workflows.PublishingWorkflow.Documents.ExcelHandler.HandleDocument(SPListItem item, PublishingConfiguration config, Boolean saveAsXPS)
at IOZ.UFAG.Workflows.PublishingWorkflow.Documents.DocumentFactory.PrepareDocument(SPListItem item, PublishingConfiguration config, Boolean saveAsXPS)
at IOZ.UFAG.Workflows.PublishingWorkflow.PublishingWorkflow.HandlePublishConfig(PublishingConfiguration publishConfig)
BTW you can find the Excel files I have been testing with as attachements (PW:1111)
Hi,
I tried with your xlsx file using the following sample code but could not find any issue/exception:
LoadOptions loadOptions = new LoadOptions(LoadFormat.Xlsx);
loadOptions.Password = “1111”;
Workbook workbook = new Workbook(“e:\test2\Test.xlsx”, loadOptions);
foreach (Worksheet worksheet in workbook.Worksheets)
{
worksheet.Cells[“A1”].PutValue(“testing”);
}
MemoryStream memoryStream = new MemoryStream();
workbook.Save(memoryStream, SaveFormat.Xlsx);
Kindly give us complete reference code (same as above) so that we could reproduce the issue on our end.
Thank you.
Hi,
In my application I was using “LoadFormat.Auto”. Changing this to “LoadFormat.Xlsx” solved the problem.
Thanks and kind regards
Jan
Hi,
Good to know that it works fine on your side too.
Have a good day!
The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan