Columns width on export

3 posts, 1 answers
  1. Alex Dybenko
    Alex Dybenko avatar
    161 posts
    Member since:
    Jan 2005

    Posted 06 Mar 2018 Link to this post

         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. Answer
    Dimitar
    Admin
    Dimitar avatar
    2984 posts

    Posted 07 Mar 2018 Link to this post

    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.
  3. Alex Dybenko
    Alex Dybenko avatar
    161 posts
    Member since:
    Jan 2005

    Posted 09 Mar 2018 in reply to Dimitar Link to this post

    Thanks Dimitar, works fine!
Back to Top