Exporting wingrid setting col & row Widhts and Heights?

4 posts, 0 answers
  1. Frank
    Frank avatar
    4 posts
    Member since:
    Sep 2017

    Posted 16 Oct 2018 Link to this post

    How's one do this?

    I tried a function that looped thru the cols and did the following;

    //objTheGrid.Columns[intIDX].Width = 1000;

    objTheGrid.MasterTemplate.Columns[intIDX].Width = 1000

    Neither worked.

    Also did a similar thing for Rows, but for height, and that didn't do anything either.

     

    THanks

     

     

  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3759 posts

    Posted 16 Oct 2018 Link to this post

    Hello, Frank, 

    In order to keep the columns width in the exported file, you can set the GridViewSpreadExport.ExportVisualSettings property to true
    this.radGridView1.Columns[1].Width = 200;
    string fileName = @"..\..\exported" + DateTime.Now.ToLongTimeString().Replace(":","_") + ".xlsx";
    GridViewSpreadExport spreadExporter = new GridViewSpreadExport(this.radGridView1);
    spreadExporter.ExportVisualSettings = true;
    SpreadExportRenderer exportRenderer = new SpreadExportRenderer();
    spreadExporter.RunExport(fileName, exportRenderer);



    Alternatively, you can handle the WorkbookCreated event which allows to introduce final customizations to the exported file considering the RadSpreadProcessing API that is introduced. Additional information is available in the following help article: https://docs.telerik.com/devtools/winforms/gridview/exporting-data/spread-export

    I hope this information helps. If you need any further assistance please don't hesitate to contact me.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Frank
    Frank avatar
    4 posts
    Member since:
    Sep 2017

    Posted 16 Oct 2018 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Thanks for the reply.

    spreadExporter.ExportVisualSettings = false;

    I am currently turning that off as I don't want the row colors in the grid showing up in the export.

    Is there another way to set the rows and cols heights and widths?

     

  4. Dimitar
    Admin
    Dimitar avatar
    2892 posts

    Posted 17 Oct 2018 Link to this post

    Hello Frank,

    You can set the width/height after the document is created in the WorkbookCreated event handler. Here is an example:
    private void radButton1_Click(object sender, EventArgs e)
    {
        GridViewSpreadExport spreadExporter = new GridViewSpreadExport(this.radGridView1);
        SpreadExportRenderer exportRenderer = new SpreadExportRenderer();
        exportRenderer.WorkbookCreated += ExportRenderer_WorkbookCreated;
       
        spreadExporter.RunExport("D:\\exportedFile.xlsx", exportRenderer);
    }
     
    private void ExportRenderer_WorkbookCreated(object sender, WorkbookCreatedEventArgs e)
    {
        var sheet = e.Workbook.Sheets[0] as Worksheet;
        sheet.Columns[1].SetWidth(new ColumnWidth(300, true));
        sheet.Rows[0].SetHeight(new RowHeight(100, true));
    }

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

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top