How to remove the html tags from file exported from grid view

1 Answer 60 Views
GridView Spreadsheet
Arun
Top achievements
Rank 1
Iron
Arun asked on 26 May 2022, 11:50 AM | edited on 26 May 2022, 11:53 AM

 

code using for export

 Case ".XLSX"
                            Dim exporter As Telerik.WinControls.Export.GridViewSpreadExport = New Telerik.WinControls.Export.GridViewSpreadExport(GridView) With {.HiddenColumnOption = UI.Export.HiddenOption.DoNotExport, .HiddenRowOption = UI.Export.HiddenOption.DoNotExport, .SummariesExportOption = UI.Export.SummariesOption.ExportAll, .ExportVisualSettings = True, .ExportViewDefinition = False}
                              exporter.RunExport(SaveFileDialog1.FileName, New Telerik.WinControls.Export.SpreadExportRenderer())

 

 

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 27 May 2022, 09:31 AM

Hello, Arun,   

According to the provided screenshots, it seems that the HTML like formatting is used to make some of the cells with bold text. I can suggest a better solution for achieving this and thus the export result will be as expected.

Instead of using HTML like text formatting, simply apply a bold font for the desired cells. Then, export the visual settings. I have prepared a sample project for your reference. Please give it a try and see how it works on your end:

    Sub New() 
        InitializeComponent()

        AddHandler Me.RadGridView1.CellFormatting, AddressOf RadGridView1_CellFormatting

    End Sub
    Private Sub RadForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.ProductsTableAdapter.Fill(Me.NwindDataSet.Products)
        Me.RadGridView1.BestFitColumns()

    End Sub

    Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
        Dim fileName As String = "..\..\exported" & DateTime.Now.ToLongTimeString().Replace(":", "_") & ".xlsx"
        Dim exporter As Telerik.WinControls.Export.GridViewSpreadExport = New Telerik.WinControls.Export.GridViewSpreadExport(Me.RadGridView1) With {.HiddenColumnOption = HiddenOption.DoNotExport, .HiddenRowOption = HiddenOption.DoNotExport, .SummariesExportOption = SummariesOption.ExportAll, .ExportVisualSettings = True, .ExportViewDefinition = False}
        exporter.ExportVisualSettings = True
        exporter.RunExport(fileName, New SpreadExportRenderer())

        Process.Start(fileName)
    End Sub

    Dim boldFont As New Font("Arial", 10.0F, FontStyle.Bold)
    Private Sub RadGridView1_CellFormatting(sender As Object, e As Telerik.WinControls.UI.CellFormattingEventArgs)
        If e.Column.Name = "UnitPrice" AndAlso e.CellElement.Value IsNot Nothing AndAlso CInt(e.CellElement.Value) > 20 Then
            e.CellElement.Font = boldFont
        Else
            e.CellElement.ResetValue(LightVisualElement.FontProperty, ValueResetFlags.Local)
        End If

    End Sub

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Arun
Top achievements
Rank 1
Iron
commented on 27 May 2022, 01:13 PM

hi Dess ,

thank you for your response ,

 in our case we cannot specify that which cell need to be formatted , so that we are using HTML based formatting , please let me know any solution is available for the current issue 

Regards

 Arun KM

 


Dess | Tech Support Engineer, Principal
Telerik team
commented on 30 May 2022, 11:50 AM

Hello, Arun,   

Please have in mind that the HTML-like text formatting functionality is applicable only for the Telerik Presentation Framework. MS Excel doesn't recognize such a syntax. GridViewSpreadExport simply exports the cells' text. Hence, it can't automatically style the exported cells in the worksheet in the same way as in RadGridView. That is why I suggested applying a bold font to the grid cells and exporting the visual style settings. Thus, the exported cells will have the proper bold font.

If you insist on using the HTML-like text formatting approach in RadGridView, it is up to you to apply the desired formatting for the exported worksheet cells. This can be achieved in the GridViewSpreadExport.CellFormatting event: https://docs.telerik.com/devtools/winforms/controls/gridview/exporting-data/spread-export#events 

Since the GridViewSpreadExport utilizes our RadSpreadProcessing library, please have a look at the relevant API for styling the exported cells
https://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/working-with-cells/get-set-clear-properties 

Feel free to use this approach which suits your requirements best.
Tags
GridView Spreadsheet
Asked by
Arun
Top achievements
Rank 1
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or