Hi,
I have a excel template which is having 10 sheets, out of those, few of them should be visible in run time.
So, for that we are creating a temporary excel, and adding the sheets based on requirement from the source template.
In that case, there is one scenario in which 2 sheets are having the same smart markers, and based on the sheet name data will be assigned.
Following is the sample code:
// Creation of Destination Workbook
WorkbookDesigner destinationDesigner = new WorkbookDesigner();
destinationDesigner.Workbook = new Workbook(FileFormatType.Xlsx);
DestinationWorkbook = destinationDesigner.Workbook;
foreach (Sheet in Source Template Excel)
{
DestinationWorkbook.Worksheets.Add(SourceSheet.Name);
DestinationWorkbook.Worksheets[DestinationWorkbook.Worksheets.Count - 1].Copy(SourceSheet);
DestinationSheet = DestinationWorkbook.Worksheets[DestinationWorkbook.Worksheets.Count - 1];
foreach (Marker markerObj in markerList)
{
object source = markerObj.SourceDataView;
DataTable dtSource = ((DataView)source).ToTable();
dtSource.TableName = markerObj.text;
destinationDesigner.SetDataSource(dtSource);
}
destinationDesigner.Process(DestinationSheet.Index, false);
}
In the above code while the loop iterates second time, it is finding that the smart marker is already assigned with some value, and if the same marker is trying to update with any data, its throwing
Item has already been added. Key in dictionary: 'DVExample' Key being added: 'DVExample'
Please help me in this.
Hi Kiranmayi,
Thanks for your posting and using Aspose.Cells.
Please download and try the latest version: Aspose.Cells for .NET 7.6.1 and see if it fixes your issue.
If your problem persists, then please provide us your source file and sample project replicating this issue with the latest version. We will look into it and help you asap.
Hi Aspose team,
As advised, I have downloaded the latest aspose dll and tried with that, even my issue is not resolved.
I tried with ClearDataSource() option also, but it is clearing all the datasources associated with that excel.
But I want overwrite only few markers, not all.
Please suggest me in this regard.
Following is my code:
// Creation of Destination Workbook
WorkbookDesigner destinationDesigner = new WorkbookDesigner();
destinationDesigner.Workbook = new Workbook(FileFormatType.Xlsx);
DestinationWorkbook = destinationDesigner.Workbook;
foreach (Sheet in Source Template Excel)
{
DestinationWorkbook.Worksheets.Add(SourceSheet.Name);
DestinationWorkbook.Worksheets[DestinationWorkbook.Worksheets.Count - 1].Copy(SourceSheet);
DestinationSheet = DestinationWorkbook.Worksheets[DestinationWorkbook.Worksheets.Count - 1];
foreach (Marker markerObj in markerList)
{
object source = markerObj.SourceDataView;
DataTable dtSource = ((DataView)source).ToTable();
dtSource.TableName = markerObj.text;
destinationDesigner.SetDataSource(dtSource);
}
destinationDesigner.Process(DestinationSheet.Index, false);
}
Hi Kiranmayi,
Thanks for your posting and using Aspose.Cells.
We are not able to compile your code. Please provide us your sample project replicating this issue. Please also provide the source xls/xlsx files which you are using inside your code/project. It will help us to investigate your issue at our end. If we find any bug, we will log it in our database so that it could be fixed asap.