How can I custom format an html page that has been exported from a VB6 msflexgrid?

Posted on 2011-05-03
Last Modified: 2012-05-11
I found the following code (below) here on EE that allows me to send msflexgrid data to an html page. The code works fine in my VB6 program.....

How can I custom format the html so that I can show gridlines, customize backcolor, change font color etc.

Public Sub gridToHtml()
Dim iFree As Long
iFree = FreeFile
Open "report.html" For Output As #iFree
Print #iFree, "<html><head></head><body><table>"
With MSFlexGrid1
For I = 0 To .Rows - 1
    Print #iFree, "<tr>"
    For J = 0 To .Cols - 1
        Print #iFree, "<td>" & .TextMatrix(I, J) & "</td>"
    Print #iFree, "</tr>"
Print #iFree, "</table></body><html>"
Close #iFree
End With
End Sub
Question by:jazjef
    LVL 1

    Accepted Solution

    Fastest way to do this is inserting HTML markup in the strings.

    For gridlines: Print #iFree, "<html><head></head><body><table border=1>"

    For font color:         Print #iFree, "<td><font color=#FF0000>" & .TextMatrix(I, J) & "</font></td>"

    Better way is using CSS...
    LVL 4

    Author Comment

    any other suggestions?..... I am having a difficult time formatting the data this way. The html seems to be buggy when used this way. How does one integrate CSS?
    LVL 1

    Expert Comment

    You can integrate CSS inline or with a separate .css file

    In header section of your HTML, link to the .css file, you'll get something like this:
    Print #iFree, "<html><head><link rel="stylesheet" href="stylesheet.css" type="text/css"></head><body><table>"

    Open in new window

    you can place a reference to the appropriate class in each html-tag like this:
    Print #iFree, "<td class=TableCell>" & .TextMatrix(I, J) & "</td>"

    Open in new window

    Your CSS file will look like this:
    	color: #FFFFFF;

    Open in new window

    LVL 4

    Author Closing Comment

    Thanks d3n... I was able to learn how to create a nice basic html report with your code from your first post; I can see how the style sheet thing would probably be better----but I think I'll make that a separate question in the near future.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now