A
A
Arslanali2021-02-18 12:17:28
excel
Arslanali, 2021-02-18 12:17:28

How to highlight a column when translating from excel to html?

From an excel spreadsheet:

1	04:56	06:25	12:09	15:11	17:47	18:58
2	04:55	06:24	12:09	15:12	17:48	18:59
3	04:53	06:22	12:09	15:12	17:49	19:00
4	04:52	06:20	12:09	15:13	17:50	19:01
5	04:50	06:19	12:09	15:14	17:51	19:02


translate to HTML:
Sub ExportExcelTableToHTML()
    
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set f = FSO.CreateTextFile("export.html", True)
    
    Dim rInput As Range
    Dim rRow As Range
    Dim rCell As Range
    Dim strReturn As String
    
    Set rInput = Range("A1:G31")
    
    'Define table format and font
    strReturn = "<div class=""show-for-medium""> "
    
    strReturn = strReturn & "<table class=""table table-striped"">  "
    
    strReturn = strReturn & "<thead> <tr> <th>День</th> <th>Утро</th> <th class=""voshod"">Восход</th> <th>Обеденный</th> <th>Аср</th> <th>Вечерний</th> <th>Ночной</th> </tr> </thead> "
    
    strReturn = strReturn & "<tbody>"
    
    'Loop through each row in the range
    For Each rRow In rInput.Rows
        'Start new html row
        strReturn = strReturn & "<tr> "
        For Each rCell In rRow.Cells
            strReturn = strReturn & "<td>" & rCell.Text & "</td>"
        Next rCell
        'End a row
        strReturn = strReturn & "</tr>"
    Next rRow
    
    strReturn = strReturn & "</tbody>"
    
    strReturn = strReturn & "</table>"
    
    strReturn = strReturn & "</div> "

    f.WriteLine (strReturn)
End Sub


Дата	Утренний	Восход солнца	Обеденный	Аср	Вечерний	Ночной
1	04:56	06:25	12:09	15:11	17:47	18:58
2	04:55	06:24	12:09	15:12	17:48	18:59
3	04:53	06:22	12:09	15:12	17:49	19:00
4	04:52	06:20	12:09	15:13	17:50	19:01
5	04:50	06:19	12:09	15:14	17:51	19:02


I don’t know how to add style to the third column: having received exactly this HTML table:
<td class="voshod">07:03</td>
<tr>
               <td>1</td>
               <td>04:56</td>
               <td class="voshod">06:25</td>
               <td>12:09</td>
               <td>15:11</td>
               <td>17:47</td>
               <td>18:58</td>
            </tr>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
wisgest, 2021-02-18
@wisgest

You can create an HTMLFile: object and work with it like an HTML document:
Set htmldoc = CreateObject("HTMLFile")

Set htmltable = htmldoc.createElement("TABLE")
MsgBox htmltable.outerHTML

Recommended search terms:
"htmlfile" site:script-coding.com ,
CreateObject HTMLFile .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question