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

[Solved] Cell Element width in Excel

1 Answer 112 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Anandhi
Top achievements
Rank 1
Anandhi asked on 14 Mar 2014, 11:03 AM
How to set cell element width in rad grid ExcelMLRowCreated Event

1 Answer, 1 is accepted

Sort by
0
Danail Vasilev
Telerik team
answered on 18 Mar 2014, 11:54 AM
Hi Anandhi,

You can set the width of the column by accessing it through the Workbook objects exposed by the event args of the ExcelMLWorkBookCreated event. For example:
ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" AllowPaging="true" OnExcelMLExportRowCreated="RadGrid1_ExcelMLExportRowCreated" OnExcelMLExportStylesCreated="RadGrid1_ExcelMLExportStylesCreated"
    PageSize="7" AutoGenerateColumns="false" OnExcelMLWorkBookCreated="RadGrid1_ExcelMLWorkBookCreated"
    OnItemCreated="RadGrid1_ItemCreated" OnHTMLExporting="RadGrid1_HtmlExporting"
    OnBiffExporting="RadGrid1_BiffExporting">
    <MasterTableView>
        <Columns>
            <telerik:GridBoundColumn DataField="EmployeeID" HeaderText="Employee ID" HeaderStyle-Width="100px">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="LastName" HeaderText="Last Name" HeaderStyle-Width="130px">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="FirstName" HeaderText="First Name" HeaderStyle-Width="130px">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="BirthDate" HeaderText="Birth Date" DataFormatString="{0:MM-dd-yy}"
                HeaderStyle-Width="140px">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="HireDate" HeaderText="Hire Date" DataFormatString="{0:MM/dd/yyyy}"
                HeaderStyle-Width="140px">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Address" HeaderText="Address" HeaderStyle-Width="240px">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="City" HeaderText="City" HeaderStyle-Width="100px">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Country" HeaderText="Country">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
C#:
protected void RadGrid1_ExcelMLWorkBookCreated(object sender, GridExcelMLWorkBookCreatedEventArgs e)
{
    e.WorkBook.Worksheets[0].Table.Columns[0].Width = Unit.Pixel(400);
}

The above example is a modified version of this online demo. You may also find useful ExcelML structure / GridExcelBuilder help article and especially the section called ColumnElement.

Regards,
Danail Vasilev
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
Tags
General Discussions
Asked by
Anandhi
Top achievements
Rank 1
Answers by
Danail Vasilev
Telerik team
Share this question
or