테이블을 html 형식으로 인쇄하는 데 필요한 거의 완벽한 코드가 있습니다.html 파일의 텍스트를 Excel의 VBA로 바꿉니다.
1) 통화 형식의 숫자 (열 17)으로 가득 하나 개의 컬럼이있다 :
나는 두 가지를 누락. html로 쓰면 통화 형식이 느슨해지고 일반 텍스트가됩니다. 해당 열의 셀 인쇄 내용을 통화 형식의 쉼표가 추가 된 텍스트 형식으로 변경하는 코드를 추가하고 싶습니다.
2) 사물 목록이 표시되고 ";"로 구분되는 셀이 있습니다. 또는 "및". 다음 줄이 ";
"및 "; 및
"으로 변경 될 수 있도록이 문자 다음에 html로 중단을 추가하고 싶습니다. 여기에는 잡기가 있습니다. 왜냐하면 ";"로 끝나는 다른 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). 값, ";", "
")' –