0
任何人都可以幫助我使此代碼可行嗎?將Excel內容轉換爲HTML(從Excel創建HTML文件)
這裏的想法是收集一行信息在不同的行上,並將這些信息一起插入到一個html文件中。
在代碼中的一些特殊待遇時,我會很感謝你:
1)使其工作8P; 2)某種方式讓用戶選擇他將要保存文件的地方,如普通的保存窗口(如果不可能,至少讓他選擇指定文件夾中文件的名稱);和3)確保代碼捕獲行上所有非空行。
非常感謝社會各界的關注!
我想到的是波紋管。
Sub CreateHTML()
'Define your variables.
Dim iRow As Long
Dim iStage As Integer
Dim iCounter As Integer
Dim iPage As Integer
'Create an .htm file in the assigned directory.
Dim sFile As String
sFile = "J:\GEROC1\Avaliação RO\4) CICLOS\ArquivosExportados" & "\test.html"
Close
'Open up the temp HTML file and format the header.
Open sFile For Output As #1
Print #1, "<html>"
Print #1, "<head>"
Print #1, "<style type=""text/css"">"
Print #1, "table {font-size: 16px;font-family: Optimum, Helvetica, sans-serif;Border -collapse: collapse}"
Print #1, "tr {border-bottom: 1px solid #A9A9A9;}"
Print #1, "td {padding: 4px; margin: 3px; padding-left: 20px; width: 75%; text-align: justify;}"
Print #1, "th { background-color: #A9A9A9; color: #FFF; font-weight: bold; font-size: 28px; text-align: center;}"
Print #1, "</style>"
Print #1, "</head>"
Print #1, "<body>"
Print #1, "<table class=""table""><thead><tr class=""firstrow""><th colspan=""2"">Ficha de Risco</th></tr></thead><tbody>"
'Start on the 2nd row to avoid the header.
iRow = 2
'Translate the first column of the table into the first level of the hierarchy.
Do While WorksheetFunction.CountA(Rows(iRow)) > 0
If Not IsEmpty(Cells(iRow, 23)) Then
For iCounter = 1 To iStage
'Print #1, "</ul>"
iStage = iStage - 1
Next iCounter
Print #1, Cells(iRow, 1).Value
iPage = iPage + 1
If iStage < 1 Then
iStage = iStage + 1
End If
End If
Loop
'Add ending HTML tags
Print #1, "</body>"
Print #1, "</html>"
Close
End Sub
您不在循環中添加任何HTML。你需要在表格中添加'tr'和'td'。 – Patrick
Ops我忘了提及...他正在打印的單元格已經有tr和td語句... – PunchTheNewbie