1

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 :-

  1. Resaving the file to be uploaded using .xlsx extension.
  2. Using Memorystream object.
  3. Adding name of file like(Worksheets.Add("Worksheet Name");)
  4. Removing header text(i.e. header columns like Name, description, etc)

P.S. I am using Nopcommerce. This is inbuilt code of importing products.

  • What version of excel are you using? Have you tried exporting a small sample of products? – Ammar Dec 07 '17 at 06:24
  • yes, i have done exporting as well, after exporting i got the fields in file and then i modified that file, filled the products and then i import the products that i want to insert. Version of excel file is Microsoft Office Excel 2003 – Arshdeep Singh Dec 07 '17 at 06:34
  • And right now following this "https://social.msdn.microsoft.com/Forums/vstudio/en-US/5720cbfc-779a-4c5f-8d5f-6adb2fbe839b/disk-error-during-write-operaation?forum=csharpgeneral – Arshdeep Singh Dec 07 '17 at 06:41
  • Please try with excel 2010+ because earlier versions of excel differ in encrypt/decrypt algorithm. – Ammar Dec 07 '17 at 06:45
  • @Ammar Thanks, it worked with Excel 2016...!!!, i would like to know more about encryption/decryption algos – Arshdeep Singh Dec 11 '17 at 06:47
  • I have added an answer so it may help someone who has similar problem and browsed this question. – Ammar Dec 13 '17 at 04:40

1 Answers1

1

Please try with excel 2010+ because earlier versions of excel differ in encrypt/decrypt algorithm.

You can read more about encryption/decryption here.

Ammar
  • 177
  • 12