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

Need to indent Text on Excel & PDF Exports

4 Answers 253 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chuck
Top achievements
Rank 1
Veteran
Chuck asked on 15 May 2020, 07:10 PM
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.

4 Answers, 1 is accepted

Sort by
0
Doncho
Telerik team
answered on 20 May 2020, 03:45 PM

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.
0
Chuck
Top achievements
Rank 1
Veteran
answered on 20 May 2020, 04:27 PM
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.
0
Chuck
Top achievements
Rank 1
Veteran
answered on 21 May 2020, 03:50 PM
Update: I'm now able to perform the Indention of Text in the Excel Export but still struggling with the PDF export.
0
Accepted
Attila Antal
Telerik team
answered on 25 May 2020, 03:46 PM

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.
Tags
Grid
Asked by
Chuck
Top achievements
Rank 1
Veteran
Answers by
Doncho
Telerik team
Chuck
Top achievements
Rank 1
Veteran
Attila Antal
Telerik team
Share this question
or