Cell Element width in Excel

2 posts, 0 answers
  1. Anandhi
    Anandhi avatar
    12 posts
    Member since:
    Apr 2013

    Posted 14 Mar 2014 Link to this post

    How to set cell element width in rad grid ExcelMLRowCreated Event
  2. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1494 posts

    Posted 18 Mar 2014 Link to this post

    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.

     
Back to Top