Results 1 to 5 of 5

Thread: [RESOLVED] [2005] Save DGV to HTML

  1. #1

    Thread Starter
    Addicted Member Alexandru_mbm's Avatar
    Join Date
    Jul 2007
    Location
    VBForums.com
    Posts
    157

    Resolved [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!
    Last edited by Alexandru_mbm; Aug 11th, 2008 at 10:22 AM.
    I'm still learning VB.NET
    Sorry for my bad english
    Thanks for your help

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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?
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3

    Thread Starter
    Addicted Member Alexandru_mbm's Avatar
    Join Date
    Jul 2007
    Location
    VBForums.com
    Posts
    157

    Re: [2005] Save DGV to HTML

    I'm still learning VB.NET
    Sorry for my bad english
    Thanks for your help

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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)
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  5. #5

    Thread Starter
    Addicted Member Alexandru_mbm's Avatar
    Join Date
    Jul 2007
    Location
    VBForums.com
    Posts
    157

    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...
    I'm still learning VB.NET
    Sorry for my bad english
    Thanks for your help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width