Error for some files:- item has already been added Key in Dictionary

Hi Team,
I am getting Error when I am iterating over sheets.

This is my sample code.

setLicense(License_Path);
Workbook excel1 = new Workbook(Root + “3_Cut_Over_Plan.xlsx”);
WorksheetCollection sheets = excel1.Worksheets;
Workbook final_excel = new Workbook();

        for (int i = 0; i < excel1.Worksheets.Count; i++)
        {
            sheets.ActiveSheetIndex = i;
            Console.WriteLine("Code Name:- {0}, Name:- {1}",sheets[i].CodeName,sheets[i].Name);
            HtmlSaveOptions options = new Aspose.Cells.HtmlSaveOptions();

            options.Encoding = Encoding.UTF8;
            options.ExportImagesAsBase64 = true;
            options.ExportSimilarBorderStyle = true;
            options.ExportActiveWorksheetOnly = true;
            options.ExportBogusRowData = true;
            
            options.ExportHiddenWorksheet = true;
            excel1.Save(Root + sheets[i].Name + ".html", options);
            Workbook html = new Workbook(Root + sheets[i].Name + ".html");
            html.Save(Root + sheets[i].Name +  ".xlsx");
            Console.WriteLine(sheets[i].Name + ".xlsx Created");
            Workbook sheet = new Workbook(Root + sheets[i].Name + ".xlsx");
            final_excel.Worksheets.Add();
            final_excel.Worksheets[i].Copy(sheet.Worksheets[0]);
            final_excel.Worksheets[i].Name = sheets[i].Name;
            Console.WriteLine("Sheet {0} added", i);
        }
        final_excel.Worksheets.RemoveAt(final_excel.Worksheets.Count-1);
        final_excel.Save(Root + "Main_regenerated.xlsx");

@kotharib2,

Thanks for your query.

Could you please send us the sample file “3_Cut_Over_Plan.xlsx” for our analysis here? It will help us to observe the problem and provide our feedback at the earliest.

Hi @ahsaniqbalsidiqui

Please find the documents, Still there are many more documents with same issue.

Document.zip (399.9 KB)

@kotharib2,

Thanks for providing the sample file.
It seems that HtmlSAveOptions.ExportActiveWorksheetOnly shall not be used in the iteration where each worksheet is processed. Please comment the following line and test the scenario again.

//options.ExportActiveWorksheetOnly = true;

Hi @ahsaniqbalsidiqui

My requirement is I want HTML of each and evry sheet …without creation oif any subfolder for css files.

Thats why I am using ActiveWorksheet

without this it is creating html of whole document.

Can you suggest me how to create HTML of each sheet without creation of any subfolder

@kotharib2

I have been able to notice the ArgumentException as mentioned by you in subject of this topic but we need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSNET-46401 - ArgumentException for some files

About creating single file, you can try to set options.ExportWorksheetCSSSeparately property to false. Or you can use MHtml file format as an output file format as mentioned by us in your other thread.

I cant work with mhtml beacuse I need to load file in chrome…
Is there any other way like excel to pdf and pdf to html possible?
I need to find some solution in urgency…
Though I have seen many users have same issue like me and ticked is logged for them since 2010!

@kotharib2,

We are afraid that there is no other option except this one which is already suggested in the previous post. Otherwise you may please wait until the logged issue is analyzed and some feedback is ready to share with you here.

@kotharib2,

Please try our latest version/fix: Aspose.Cells for .NET v18.10.5:

Aspose.Cells18.10.5 For .Net2_AuthenticodeSigned.Zip (4.7 MB)
Aspose.Cells18.10.5 For .Net4.0.Zip (4.7 MB)

Your issue should be fixed in it.

Let us know your feedback.

The issues you have found earlier (filed as CELLSNET-46401) have been fixed in Aspose.Cells for .NET v18.11. This message was posted using BugNotificationTool from Downloads module by Amjad_Sahi