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

Setting cell width in an Excel cell via GridExcelBuilder

2 Answers 107 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Martillo
Top achievements
Rank 2
Martillo asked on 26 Apr 2010, 06:38 AM

When using the GridExcelBuilder to add a new cell (and row) to a worksheet when exporting from the RadGrid, is there a way to specify the width of the cell as in the pseudo-code below?

protected void Grid_ExcelMLExportRowCreated ( object source, Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLRowCreatedArgs e )  
{  
    if ( e.RowType == GridExportExcelMLRowType.HeaderRow )  
    {  
        RowElement myNewRow = new RowElement();  
        CellElement myNewCell = new CellElement();  
        myNewCell.StyleValue = "myNewStyle";  
        myNewCell.MergeAcross = e.Row.Cells.Count - 1;  
        //is there something like the property below? 
        myNewCell.Width = 200;  
        //etc...  
    }  
}  

Thanks,

Keith

2 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 26 Apr 2010, 09:45 PM
Hello Martillo,

The width of your cells depends on the width that is set to the relevant column (as in MS Excel). Here is how to set a width to given column:
bool tempFlag = false;
protected void RadGrid1_ExcelMLExportRowCreated(object source, GridExportExcelMLRowCreatedArgs e)
{
    int colCount = e.Worksheet.Table.Columns.Count;
    if (colCount > 0 && !tempFlag)
    {
        tempFlag = true;
        e.Worksheet.Table.Columns[0].Attributes["ss:Width"] = "200";
        e.Worksheet.Table.Columns[1].Attributes["ss:Width"] = "600";
    }
    ...
}

Best regards,
Daniel
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Martillo
Top achievements
Rank 2
answered on 27 Apr 2010, 04:44 AM
Thanks Daniel. That worked like a charm.
Tags
Grid
Asked by
Martillo
Top achievements
Rank 2
Answers by
Daniel
Telerik team
Martillo
Top achievements
Rank 2
Share this question
or