开发者

How to push each Excel row to a different html file

I've created an Excel file with 570 rows and I need to export each row to a different .html file. I've already created the 570 .html files (1.html,2.html....570.html) and they are empty so how can I fill each one with a different ordered row of my Excel file?开发者_如何学Python

Thanks in advance!


Note that I haven't tested this as I don't own Excel or any Microsoft products. I've adapted the code from here in order to work as you asked. I couldn't automate this without using VBA, which should come with every copy of Excel. It's basically used to quickly automate macro sequences.

Public Sub GenerateHTML(ByVal sTitle As String)

Dim iFileNum As Integer
Dim lRow As Long
Dim iColCount As Integer
Dim iCol As Integer
Dim sFileName As String
sFileName = "Your-Title-Here" ' Be sure to change this to a title. '

iColCount = ActiveSheet.UsedRange.Columns.Count
For lRow = 1 To 570
    iFileNum = FreeFile
    Open sFileName + "-row" + lRow + ".html" For Output As iFileNum
    Print #iFileNum, "<HTML>"
    Print #iFileNum, "<TITLE>" + sTitle + " Row: " + CStr(lRow) + "</TITLE>"
    Print #iFileNum, "<BODY>"
    Print #iFileNum, "<TABLE BORDER=1>"
    Print #iFileNum, "<TR>"
    For iCol = 1 To iColCount
        Print #iFileNum, "<TD>"
        Print #iFileNum, CStr(Cells(lRow, iCol).Value)
        Print #iFileNum, "</TD>"
    Next iCol
    Print #iFileNum, "</TR>"
    Print #iFileNum, "</TABLE>"
    Print #iFileNum, "</BODY>"
    Print #iFileNum, "</HTML>"
    Close iFileNum
Next lRow
Close iFileNum
End Sub
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜