Getting issue with multiple sheets while using threads

Dear Team,

I am working with Aspose.cells for .net. I am tring to generate a workbook with say 20 sheets. As part of this I am creating 20 different workbooks each contains one sheet from the list. I am generating this using threads such that all will be processed parallely. And finally I want to merge all this with in a single workbook.

My problem is while generating the work books using threads and copying the each sheet into the final workbook always the code is copying the data of the sheet which is processed finally such that the final workbook contains same data in all the sheets.

Please suggest the solution to resolve the issue as soon as possible.

Using below syntax to copy the worksheet into a workbook.

_workbook.Worksheets[workbookTemp.Worksheets.ActiveSheetIndex].Copy(workbookTemp.Worksheets[workbookTemp.Worksheets.ActiveSheetIndex]);

Hi,


Creating spreadsheets in multiple threads demands you should always create separate workbooks in each thread, so you are doing fine already for this part. But, I am not sure about your issue as you said… “My problem is while generating the work books using threads and copying the each sheet into the final workbook always the code is copying the data of the sheet which is processed finally such that the final workbook contains same data in all the sheets”. I think it might be flaw in your codes. Could you please create a sample console application (runnable), zip it and post it here to reproduce the issue on our end, we will check it soon.

Thank you.

Dear Team,

Below is my scenario.

I have a method say GenerateSheet() on which I am using threads. From this method I am calling a override method of two different classes say CreateReportWorkbook() . I which I am doign the following stuff

Created one work book and assigned the excel template

assigned the respective worksheet of the workbook to a worksheet created as public.

to bind the data I am calling one of its base method(say bind()) by passing the data here to bind the data I am using below code

Worksheet temp = null;

try

{

XmlNode reportNode = param.ReportMarkersDoc.SelectSingleNode("//Report[@reportId='" + ReportId + "']");

XmlNodeList markerList =

param.ReportMarkersDoc.SelectNodes("//Report[@reportId='" + ReportId + "']/Markers/Marker");

//WorkbookDesigner designer = new WorkbookDesigner();

if (markerList != null)

foreach (XmlNode markerNode in markerList)

{

long sectionId = 0;

if (markerNode.Attributes != null && long.TryParse(markerNode.Attributes["reportSectionId"].Value, out sectionId))

{

IEnumerable<DataRow> result = from r in dt.AsEnumerable()

where (r.Field<long>("Section_Id").Equals(sectionId))

select r;

DataTable dtResult = null;

if (result.Any())

{

dtResult = result.CopyToDataTable<DataRow>();

dtResult.TableName = markerNode.Attributes["text"].Value;

param.MarkerProcessor.SetDataSource(dtResult);

}

else

{

// This block of code ensure that the marker are set to Blank incase there is no data.

DataView dvResult = dt.DefaultView;

dvResult.RowFilter = "Section_Id = " + sectionId + "";

dtResult = dvResult.ToTable();

param.MarkerProcessor.SetDataSource(dtResult);

}

}

}

param.MarkerProcessor.Process(true);

temp= param.worksheet;

return temp.

// }

//}

Here param.Markerprocessor is WorkbookDesigner object.

The problem is with the below statement:

param.MarkerProcessor.SetDataSource(dtResult);

only the last thread data is got inseted into the excel for rest of the threads the param.worksheet is left with the markers only.

so please suggest me the solution to resolve this.

Still you need a sample I ll provide sample app by implemeting the same.

Hi,


I could not evaluate your issue properly. Please create a simple console application (runnable) with Aspose.Cells only, zip it and post it here to show the issue on our end, we will check it soon.

Thank you.