i am working in nopcommerce solution 3.90, while importing products, from excel file i get this exception. my code is as follow
public virtual void ImportProductsFromXlsx(Stream stream)
{
try
{
#region Import business Logic
using (var xlPackage = new ExcelPackage(stream))
{
//get the first worksheet in the workbook
var worksheet = xlPackage.Workbook.Worksheets.FirstOrDefault();
if (worksheet == null)
throw new NopException("No worksheet found");
//the columns
var properties = GetPropertiesByExcelCells<Product>
(worksheet);
var manager = new PropertyManager<Product>
(properties);
var attributProperties = new[]
.....
.....
}
}
StackTrace:-
at OfficeOpenXml.Utils.CompoundDocument.ILockBytes.WriteAt(Int64 ulOffset, IntPtr pv, Int32 cb, UIntPtr& pcbWritten) at OfficeOpenXml.Utils.CompoundDocument.GetLockbyte(MemoryStream stream) at OfficeOpenXml.ExcelPackage.Load(Stream input, Stream output, String Password) at OfficeOpenXml.ExcelPackage.Load(Stream input) at OfficeOpenXml.ExcelPackage..ctor(Stream newStream) at Nop.Services.ExportImport.ImportManager.ImportProductsFromXlsx(Stream stream) in d:\Arsh\nop3.90\Libraries\Nop.Services\ExportImport\ImportManager.cs:line 330
Solutions That i have tried are :-
- Resaving the file to be uploaded using .xlsx extension.
- Using Memorystream object.
- Adding name of file like(Worksheets.Add("Worksheet Name");)
- Removing header text(i.e. header columns like Name, description, etc)
P.S. I am using Nopcommerce. This is inbuilt code of importing products.
Please try with excel 2010+ because earlier versions of excel differ in encrypt/decrypt algorithm.
You can read more about encryption/decryption here.
User contributions licensed under CC BY-SA 3.0