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.