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

Columns width on export

2 Answers 31 Views
PivotGrid and PivotFieldList
This is a migrated thread and some comments may be shown as answers.
Alex Dybenko
Top achievements
Rank 2
Alex Dybenko asked on 06 Mar 2018, 09:06 AM

     Hi,

when I manually resize columns on PivotGrid and then run Export to Excel (or PDF) - row descriptor columns (Day, Aggregates) are same size in Excel, but aggregates columns somehow resized. Is it by design or there is a way to export row descriptor columns width as well?

Alex

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 07 Mar 2018, 09:42 AM
Hello Alex,

By default the custom width is not exported, however, you can set the width after the workbook is created. The following code shows how you can get the width from the pivot as well:
void button_Click(object sender, EventArgs e)
{
    PivotGridSpreadExport spreadExport = new PivotGridSpreadExport(this.radPivotGrid1);
    spreadExport.ExportVisualSettings = true;
    var renderer = new SpreadExportRenderer();
    renderer.WorkbookCreated += Renderer_WorkbookCreated;
    spreadExport.RunExport(@"D:\exported-file.xlsx", renderer);
}
 
private void Renderer_WorkbookCreated(object sender, WorkbookCreatedEventArgs e)
{
    var sheet = e.Workbook.Sheets[0] as Worksheet;
    sheet.Columns[0].SetWidth(new ColumnWidth(GetWidth(0), true));
    sheet.Columns[1].SetWidth(new ColumnWidth(GetWidth(1), true));
    sheet.Columns[2].SetWidth(new ColumnWidth(GetWidth(2), true));
}
public int GetWidth(int column)
{
    int width = 100;
    foreach (RadElement element in this.radPivotGrid1.PivotGridElement.RowDescriptorsArea.Children)
    {
        PivotGroupDescriptorElement group = element as PivotGroupDescriptorElement;
        if (group == null)
        {
            continue;
        }
        if (radPivotGrid1.RowGroupDescriptions.IndexOf(group.GroupDescriptor) == column)
        {
            width = group.Size.Width;
        }
 
    }
    return width;
}

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Alex Dybenko
Top achievements
Rank 2
answered on 09 Mar 2018, 08:53 AM
Thanks Dimitar, works fine!
Tags
PivotGrid and PivotFieldList
Asked by
Alex Dybenko
Top achievements
Rank 2
Answers by
Dimitar
Telerik team
Alex Dybenko
Top achievements
Rank 2
Share this question
or