テーブルをhtml形式で印刷することは、私の目的にはほぼ完全なコードがあります。htmlファイル内のテキストをExcelのVBAに置き換える
1)通貨形式の番号(列17)で満たされている一つの列があります:
私は二つのことを欠けています。私がhtmlに書き込むと、その通貨フォーマットが失われてプレーンテキストになります。その特定の列のセルの印刷内容を、通貨形式でカンマを追加したテキスト形式に変更するコードを追加したいと思います。
2)物のリストが表示され、「;」で区切られたセルがいくつかあります。または"。私は、この文字の後に改行を入れて、次の行が ";
"と ";と
"に変更されるようにしたいと思います。 ";"で終わる他のhtml要素があるので、ここにキャッチがあります。その交換は、私がテーブルの内容を書いているセクションでのみでなければなりません。さもなければ、CSS属性の要素を変更するでしょう。
以下のコードを送信します。私はすべてのあなたの助けのために事前に感謝します。
Sub CreateHTML()
'Define your variables.
Dim iRow As Long
Dim tRow As Long
Dim iStage As Integer
Dim iCounter As Integer
Dim iPage As Integer
Dim lastCol As Integer
Dim lastRow As Integer
Dim repLine As Variant 'the array of lines you will WRITE
Dim ln As Variant
Dim l As Long
'Find the last Column Number
With ActiveSheet
lastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
End With
'Find the last Column Row
With ActiveSheet
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
'Create an .html file in the assigned directory.
Dim sFile As Variant
sFile = Application.GetSaveAsFilename(fileFilter:="HTML Files (*.html), *.htm")
If fileName <> False Then
SaveWorkbook = fileName
End If
'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: thin 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, "td:first-child { font-weight: bold; width: 25%;}"
Print #1, "</style>"
Print #1, "</head>"
Print #1, "<body>"
'Translate the first column of the table into the first level of the hierarchy.
tRow = 1
'Start on the 2nd row to avoid the header. - iRow=2/tRow is the table header
For iRow = 2 To lastRow
Print #1, "<table class=""table""><thead><tr class=""firstrow""><th colspan=""2"">Ficha de Risco</th></tr></thead><tbody>"
For iCounter = 1 To lastCol
Print #1, "<tr><td>"
Print #1, Cells(tRow, iCounter).Value
Print #1, "</td><td>"
Print #1, Cells(iRow, iCounter).Value
Print #1, "</td></tr>"
Next iCounter
Next iRow
'Add ending HTML tags
Print #1, "</body>"
Print #1, "</html>"
'after this comment the code is awfully wrong - please help!
'Replace ; with ; <br> and ; and with ; and <br> - insert a breaking point after semicollon
'# Read entire file into an array & close it
repLine = Split(sFile.ReadAll, vbNewLine)
'# iterate the array and do the replacement line by line
For Each ln In repLine
ln = IIf(InStr(1, ln, ";", vbTextCompare) > 0, Replace(ln, ";", "<br>"), ln)
repLine(l) = ln
l = l + 1
Next
'# Write to the array items to the file
sFile.Write Join(repLine, vbNewLine)
Close
End Sub
'プリント#1、置換(セル(tRow、iCounter)。値、"; "、
") ' –