This is a migrated thread and some comments may be shown as answers.

Export to Excel "SheetName" already exists

1 Answer 194 Views
PivotGrid and PivotFieldList
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 2
Bronze
Iron
Veteran
Mark asked on 14 Oct 2015, 08:38 PM

Is there something built into the export of the PivotTable to a Excel file to have to check for the name w/out throwing an error or better yet, have it auto Index it? 

 

Thanks

1 Answer, 1 is accepted

Sort by
0
Ralitsa
Telerik team
answered on 19 Oct 2015, 08:40 AM
Hi Mark,

Thank you for contacting us. 

You can create unique names of SheetName using number or date. Please refer to the code snippet below: 
PivotGridSpreadExport exporter;
SpreadExportRenderer exportRenderer;
int sheetNumber;
 
private void radButton1_Click(object sender, EventArgs e)
{
    sheetNumber++;
    exportRenderer = new SpreadExportRenderer();
    exporter = new PivotGridSpreadExport(this.radPivotGrid1);
    exporter.SheetName = "SpreadExport" + sheetNumber;
    exporter.ExportFormat = SpreadExportFormat.Xlsx;
    exporter.FileExportMode = FileExportMode.NewSheetInExistingFile;
    exporter.RunExport(@"..\..\file.xlsx", exportRenderer);
}

Another suggestion is to set the FileExportMode property to CreateOrOverrideFile which will override the specified file and it is not necessary to create unique name of sheet each time. 

Hope this will help you. Let me know if you have any other questions.

Regards,
Ralitsa
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
PivotGrid and PivotFieldList
Asked by
Mark
Top achievements
Rank 2
Bronze
Iron
Veteran
Answers by
Ralitsa
Telerik team
Share this question
or