[RESOLVED] [2005] Save DGV to HTML
Hello again,
I'm working to an app that need to export some XLS files. I have tried for many many many days to solve more problems using Office.Interop COM but is to hard for me to understand why some microsoft products don't work with others microsoft produscts.
By the way... i have read in many webpages that is possible to save a DGV to HTML and then to rename the file as XLS and works.
I have looked on many forums and articles but i don find a sample about how can i export a DGV to HTML.
Can anyone help me with some code sample because realy i'm going crazy ?
Thanks in advice!
Re: [2005] Save DGV to HTML
Where did you get the information telling you to save a DGV data to an HTML file and then to rename the file as XLS to make an excel file?
Re: [2005] Save DGV to HTML
Re: [2005] Save DGV to HTML
Quote:
Originally Posted by Alexandru_mbm
I tested it and it seems to work. However, there's no easy way to convert the data in a DGV to an html table... Using a streamwriter, you have to manually write the elements (table, tr, td...) yourself to a text file with fake xls extension.
What I did was to create an asp.net application with a test aspx page. On this page, I add an html table and fill up the cells with values, format the table and the cells as I like, then run the application. Once the web page displays, I view it source and save the file with an xls extension. It opens in Excel fine (except that all the excel grid lines you normally see now disappear). The data are in correct rows and columns.
I think you can do the same and use this test file as a sample (so that you know what needs to be written to your text file)
Re: [2005] Save DGV to HTML
Yes it's working for sure... but with few options to format the cells and add formulas etc. It's good to know anyway depends on application ;)
Btw... i did my job using Office Interop lib.
The application installed on the client machines with non "en-US" cultureinfo give's many many many and strange errors.
I figured out how this can be done and i made my project working.
For all others with the same problem the solution is...
Code:
'Put this code before exporting XLS procedure...
Dim sCurrentUICulture As String
Dim sCurrentCulture As String
'Save the current culture values.
sCurrentUICulture = System.Threading.Thread.CurrentThread.CurrentUICulture.ToString
sCurrentCulture = System.Threading.Thread.CurrentThread.CurrentCulture.ToString
'Switch to english-United States culture for the purposes of date conversion.
System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo("en-US")
System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-US")
'.............. YOUR CODE HERE ..................
'And finaly at the end of procedure use:
System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo(sCurrentUICulture)
System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo(sCurrentUICulture)
After this your app works fine... ;)