Need to indent Text on Excel & PDF Exports

5 posts, 1 answers
  1. Chuck
    Chuck avatar
    25 posts
    Member since:
    Oct 2018

    Posted 15 May Link to this post

    I have a grid that I'm able to indent a set of text on the webpage but not able to maintain this formatting on PDF & Excel exporting.
  2. Doncho
    Admin
    Doncho avatar
    15 posts

    Posted 20 May Link to this post

    Hi Chuck,

    Please check out the following articles that describe the specifics and different ways of formatting the PDF/Excel output.

    If the desired appearance or formatting is beyond the built-in capabilities of the RadGrid, then usually the DocumentProcessing Libraries come to assistance:

    If these articles are not helping to solve the issue. It would be beneficial if you provide us a sample code representing a concrete scenario so that we have a better overview and advise you best.

    Looking forward to hearing from you!

    Kind regards,
    Doncho
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
  3. Chuck
    Chuck avatar
    25 posts
    Member since:
    Oct 2018

    Posted 20 May in reply to Doncho Link to this post

    Thank you for providing the information to review. I have looked at them but unable to find a specific example of Indention. I'm able to perform the indention now in the ItemDataBound event of the grid using "cellDisplay.Style.Add("padding-left", "20px")" but this doesn't translate to either the Excel or PDF export.
  4. Chuck
    Chuck avatar
    25 posts
    Member since:
    Oct 2018

    Posted 21 May in reply to Chuck Link to this post

    Update: I'm now able to perform the Indention of Text in the Excel Export but still struggling with the PDF export.
  5. Answer
    Attila Antal
    Admin
    Attila Antal avatar
    511 posts

    Posted 25 May Link to this post

    Hi Chuck,

    I have made a quick test and the padding-left does seem to work. Also, I have tested the text-align which did work too.

    Result of the 20px padding

     

    Result of the text-align center

     

    Here is the code I used for testing

    <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" Width="800px" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemDataBound="RadGrid1_ItemDataBound" GridLines="Both">
        <MasterTableView AutoGenerateColumns="False" DataKeyNames="OrderID" CommandItemDisplay="Top">
            <CommandItemSettings ShowExportToPdfButton="true" />
            <Columns>
                <telerik:GridBoundColumn DataField="OrderID" DataType="System.Int32"
                    FilterControlAltText="Filter OrderID column" HeaderText="OrderID"
                    ReadOnly="True" SortExpression="OrderID" UniqueName="OrderID">
                </telerik:GridBoundColumn>
                <telerik:GridDateTimeColumn DataField="OrderDate" DataType="System.DateTime"
                    FilterControlAltText="Filter OrderDate column" HeaderText="OrderDate"
                    SortExpression="OrderDate" UniqueName="OrderDate">
                </telerik:GridDateTimeColumn>
                <telerik:GridNumericColumn DataField="Freight" DataType="System.Decimal"
                    FilterControlAltText="Filter Freight column" HeaderText="Freight"
                    SortExpression="Freight" UniqueName="Freight">
                </telerik:GridNumericColumn>
                <telerik:GridBoundColumn DataField="ShipName"
                    FilterControlAltText="Filter ShipName column" HeaderText="ShipName"
                    SortExpression="ShipName" UniqueName="ShipName">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ShipCountry"
                    FilterControlAltText="Filter ShipCountry column" HeaderText="ShipCountry"
                    SortExpression="ShipCountry" UniqueName="ShipCountry">
                </telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

     

    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        RadGrid1.DataSource = OrdersTable();
    }
    
    private DataTable OrdersTable()
    {
        DataTable dt = new DataTable();
    
        dt.Columns.Add(new DataColumn("OrderID", typeof(int)));
        dt.Columns.Add(new DataColumn("OrderDate", typeof(DateTime)));
        dt.Columns.Add(new DataColumn("Freight", typeof(decimal)));
        dt.Columns.Add(new DataColumn("ShipName", typeof(string)));
        dt.Columns.Add(new DataColumn("ShipCountry", typeof(string)));
    
        dt.PrimaryKey = new DataColumn[] { dt.Columns["OrderID"] };
    
        for (int i = 0; i < 70; i++)
        {
            int index = i + 1;
    
            DataRow row = dt.NewRow();
    
            row["OrderID"] = index;
            row["OrderDate"] = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0).AddHours(index);
            row["Freight"] = index * 0.1 + index * 0.01;
            row["ShipName"] = "Name " + index;
            row["ShipCountry"] = "Country " + index;
    
            dt.Rows.Add(row);
        }
    
        return dt;
    }
    
    
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            var item = e.Item as GridDataItem;
    
            foreach (GridTableCell cell in item.Cells)
            {
                //cell.Style.Add("padding-left", "20px"); // works
    
                cell.Style.Add("text-align", "center"); // works
            }
        }
    }


    Kind regards,
    Attila Antal
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top