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

Copy Grid / Selected Row or Rows to Word (HTML)

2 Answers 28 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ahmuser
Top achievements
Rank 1
Ahmuser asked on 13 Apr 2011, 09:41 PM
I had a look at the "community code library" article

export-gridview-to-html-for-copy-paste.aspx

1. Seems that the code needs to be updated a little to be compatible with  Q1 2011.

2. With Copy and Paste being such a basic and essential feature for many apps, is it not possible for Telerik to provide us with an example/demo project in VB.NET for this kind of functionality.   I've got a few "bugs" using the code in the example so a complete project with the relevant code would be most welcome.

3. Is there anyone who can help that has used copy (from RadGrid) and paste (to MS Word)  successfully?

Many thanks


2 Answers, 1 is accepted

Sort by
0
Ahmuser
Top achievements
Rank 1
answered on 14 Apr 2011, 07:02 PM
I have used the code mentioned above and have the following comments/problems:

1. Had to modify the following line to make it compatible with Q1 2011:

dCol.Prefix = col.UniqueName
        to
dCol.Prefix = col.Name

2. The code was exporting all rows. To export the selected row/s
change
For Each rowInfo As Telerik.WinControls.UI.GridViewDataRowInfo In rGrid.Rows
to
For Each rowInfo As Telerik.WinControls.UI.GridViewDataRowInfo In rGrid.SelectedRows

Question:
How does one export the filtered rows?


3. Added the following code to do the HTML function - but battling to paste into Microsoft Word 2010

continuing from the code....

dg.DataSource = table
dg.DataBind()
Dim SB As StringBuilder = New StringBuilder
Dim SW As StringWriter = New StringWriter(SB)
Dim htmlTW As HtmlTextWriter = New HtmlTextWriter(SW)
dg.RenderControl(htmlTW)


Dim data_object As New DataObject
Dim thegridhtml As String = ""
thegridhtml = SB.ToString
thegridhtml = "<HTML>" & vbCrLf & " <HEAD>COPIED FROM RADGRID1</HEAD>" & vbCrLf & " <BODY>" & vbCrLf & thegridhtml & " </BODY>" & vbCrLf & "</HTML>"
data_object.SetData(DataFormats.Html, thegridhtml)
Clipboard.SetDataObject(thegridhtml)

 

 



The problem is Word does not recognize this as HTML.  I seem to be missing something.


I would also like to convert the HTML to rtf at this point.

Any ideas!!!

0
Martin Vasilev
Telerik team
answered on 19 Apr 2011, 08:45 AM
Hi Ahmuser,

Thank you for writing.

Actually, we do not support the described scenario, since it is made and shared by one of our customers. That is why we do not have any working examples about it. I recommend taking a look into our built-in export to html functionality. You can easily set up the exported file to be opened by default in MS Word, if you specify the file extension to be "doc":
Dim htmlExporter As New ExportToHTML(Me.RadGridView1)
htmlExporter.ExportHierarchy = True
htmlExporter.ExportVisualSettings = True
htmlExporter.FileExtension = "doc"
  
htmlExporter.RunExport("MyFile")

I hope this helps. Let me know if you have any additional questions.

Greetings,
Martin Vasilev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Ahmuser
Top achievements
Rank 1
Answers by
Ahmuser
Top achievements
Rank 1
Martin Vasilev
Telerik team
Share this question
or