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

[Solved] Export to Excel create a new Tab

1 Answer 333 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 15 May 2013, 08:01 PM
When I export to Excel, can I export other data on the web page into another tab on the excel spreadsheet/workbook?

1 Answer, 1 is accepted

Sort by
0
Hans
Top achievements
Rank 1
answered on 16 May 2013, 11:48 AM
Hello Mike,

Yes, that is possible. I have just this myself.

I use BIFF format so I have:
<telerik:radgrid id="RadGridFailureReportSearch" runat="server" allowpaging="True" autogeneratecolumns="False" cellspacing="0" gridlines="None" 
    onneeddatasource="RadGridFailureReportSearch_NeedDataSource" onprerender="RadGridFailureReportSearch_PreRender" 
    onupdatecommand="RadGridFailureReportSearch_UpdateCommand" OnItemCommand="RadGridFailureReportSearch_ItemCommand" 
    OnBiffExporting="RadGridFailureReportSearch_BiffExporting" allowmultirowedit="True" allowfilteringbycolumn="True" showgrouppanel="False" allowsorting="True">
    <exportsettings>
        <Excel Format="Biff"></Excel>
    </exportsettings>

In the RadGridFailureReportSearch_BiffExporting event handler I have:

// you need this using statement for the below to work: using eis = Telerik.Web.UI.ExportInfrastructure;

            eis.Table newWorksheet = new eis.Table(Localization.GetString("ExcelSearchCriteriaHeader.Text", this.LocalResourceFile));
 
            eis.Cell headerCell = newWorksheet.Cells[1, 1];
            headerCell.Value = Localization.GetString("ExcelSearchCriteriaHeader.Text", this.LocalResourceFile);
            headerCell.Style.HorizontalAlign = HorizontalAlign.Left;
            headerCell.Style.Font.Bold = true;
             
            headerCell = newWorksheet.Cells[1, 2];
            headerCell.Value = Localization.GetString("ExcelSearchItem.Text", this.LocalResourceFile);
            headerCell.Style.HorizontalAlign = HorizontalAlign.Left;
             
            headerCell = newWorksheet.Cells[2, 2];
            headerCell.Value = ddlListSearchItem.SelectedItem.Text;
            headerCell.Style.HorizontalAlign = HorizontalAlign.Left;
             
            headerCell = newWorksheet.Cells[1, 3];
            headerCell.Value = Localization.GetString("ExcelSearchText.Text", this.LocalResourceFile);
            headerCell.Style.HorizontalAlign = HorizontalAlign.Left;
 
            headerCell = newWorksheet.Cells[2, 3];
            headerCell.Value = txtSearch.Text;
            headerCell.Style.HorizontalAlign = HorizontalAlign.Left;
 
            headerCell = newWorksheet.Cells[1, 4];
            headerCell.Value = Localization.GetString("ExcelFromDate.Text", this.LocalResourceFile);
            headerCell.Style.HorizontalAlign = HorizontalAlign.Left;
 
            headerCell = newWorksheet.Cells[2, 4];
            headerCell.Value = txtFromDate.SelectedDate.ToString();
            headerCell.Style.HorizontalAlign = HorizontalAlign.Left;
 
            headerCell = newWorksheet.Cells[1, 5];
            headerCell.Value = Localization.GetString("ExcelToDate.Text", this.LocalResourceFile);
            headerCell.Style.HorizontalAlign = HorizontalAlign.Left;
 
            headerCell = newWorksheet.Cells[2, 5];
            headerCell.Value = txtToDate.SelectedDate.ToString();
            headerCell.Style.HorizontalAlign = HorizontalAlign.Left;
 
            headerCell = newWorksheet.Cells[1, 6];
            headerCell.Value = Localization.GetString("ExcelShowCanceled.Text", this.LocalResourceFile);
            headerCell.Style.HorizontalAlign = HorizontalAlign.Left;
 
            headerCell = newWorksheet.Cells[2, 6];
            headerCell.Value = (cboShowCanceled.Checked ? Localization.GetString("Yes.Text", this.LocalResourceFile) : Localization.GetString("No.Text", this.LocalResourceFile));
                         
            headerCell.Style.HorizontalAlign = HorizontalAlign.Left;
 
            headerCell = newWorksheet.Cells[1, 7];
            headerCell.Value = Localization.GetString("ExcelShowOpen.Text", this.LocalResourceFile);
            headerCell.Style.HorizontalAlign = HorizontalAlign.Left;
 
            headerCell = newWorksheet.Cells[2, 7];
            headerCell.Value = (cboShowOpen.Checked ? Localization.GetString("Yes.Text", this.LocalResourceFile) : Localization.GetString("No.Text", this.LocalResourceFile));
            headerCell.Style.HorizontalAlign = HorizontalAlign.Left;
 
            headerCell = newWorksheet.Cells[1, 8];
            headerCell.Value = Localization.GetString("ExcelShowClosed.Text", this.LocalResourceFile);
            headerCell.Style.HorizontalAlign = HorizontalAlign.Left;
 
            headerCell = newWorksheet.Cells[2, 8];
            headerCell.Value = (cboShowClosed.Checked ? Localization.GetString("Yes.Text", this.LocalResourceFile) : Localization.GetString("No.Text", this.LocalResourceFile));
            headerCell.Style.HorizontalAlign = HorizontalAlign.Left;
 
            e.ExportStructure.Tables.Add(newWorksheet);

Hope that helps!

Regards,
Hans
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Hans
Top achievements
Rank 1
Share this question
or