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

Exporting wingrid setting col & row Widhts and Heights?

3 Answers 74 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Frank
Top achievements
Rank 1
Frank asked on 16 Oct 2018, 12:04 PM

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

 

 

3 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 16 Oct 2018, 01:03 PM
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.
0
Frank
Top achievements
Rank 1
answered on 16 Oct 2018, 02:20 PM

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?

 

0
Dimitar
Telerik team
answered on 17 Oct 2018, 10:16 AM
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.
Tags
GridView
Asked by
Frank
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Frank
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or