Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dim report As String="<html><body><table>........</table></body></html>"


VB
Private Sub WordToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WordToolStripMenuItem.Click
    Dim sa As New SaveFileDialog
    sa.FileName = "report1"
    sa.DefaultExt = ".doc"
    sa.Filter = "word document (*.doc)|"
    If sa.ShowDialog() = DialogResult.OK Then
        System.IO.File.WriteAllText(sa.FileName, report)
    End If
End Sub

Private Sub ExcelToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExcelToolStripMenuItem.Click
    Dim sa As New SaveFileDialog
    sa.FileName = "report1"
    sa.DefaultExt = ".xls"
    sa.Filter = "excel workbook (*.xls)|"
    If sa.ShowDialog() = DialogResult.OK Then
        System.IO.File.WriteAllText(sa.FileName, report)
    End If
End Sub



Hi,
I Want to export html table to doc,xls file and I am using above code. but I want proper code for it, if any one have code for this please forward to me.
Thank you.
Posted
Comments
Maciej Los 6-Oct-14 7:42am    
Think of it. MS Excel and MS Word file is not just text file. You need to use proper methods to write html content to its files.
Have you ever heard about OpenXML standard?
Sid_Joshi 6-Oct-14 7:47am    
Thank you for replay on my question.
No, sir I don't heard OpenXML standard can you help me for it?

1 solution

As i wrote in comment, the best option in this case is to use OpenXML[^]. It's open format for MS Office documents.

Please, visit below links:
How to: Insert a table into a word processing document (Open XML SDK)[^]
Working with WordprocessingML tables (Open XML SDK)[^]
Introduction to Excel XML Part 1: creating a simple table[^]

Here[^] you'll find very interesting library to convert html table to OpenXML. It supports almost all html table tags.

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900