文本到Html列表(Text to Html list)
我想制作一个可以自动获取* .txt文件信息的html
something1 something2 something3
并输出到这个html文件
<!DOCTYPE html> <html> <head> <title>List</title> </head> <body> <ul> #here to output# </ul> </body> </html>
我更喜欢使用JavaScript。 一些帮助表示赞赏。
I want to make a html which will auto get the information for a *.txt file
something1 something2 something3
and output into this html file
<!DOCTYPE html> <html> <head> <title>List</title> </head> <body> <ul> #here to output# </ul> </body> </html>
I prefer to use JavaScript. Some help is appreciated.
原文:https://stackoverflow.com/questions/40817894
最满意答案
如果“ - ”是输入数据的一部分,您可以使用RegExp替换,如:
>> Set r1 = New RegExp >> r1.Pattern = "^[^-]+(-[^-]+-).*" >> WScript.Echo r1.Replace("L2-A-1234", "$1") >> -A-
要么:
>> Set r1 = New RegExp >> r1.Pattern = "^[^-]+-([^-]+).*" >> WScript.Echo r1.Replace("L2-B-123", "$1") >> B
您也可以使用子匹配代替.Replace:
>> WScript.Echo r1.Execute("Don't care-wanted-")(0).SubMatches(0) >> wanted
如果需要函数,请将Regexp传递给函数; 并记住必须将返回值赋给函数名称(removeData <> ExtractSDI)。
第二个规范的另一种可能性(“ - ”不是所需输出的一部分):
>> WScript.Echo Split("Whatever-Wanted-Ignore", "-")(1) >> Wanted
更新:
处理嵌入在所需输出中的“ - ”并显示如何在/作为公式使用此方法:
Option Explicit ' needs Ref to RegExp Dim rX As RegExp Function cleanSDI(s) If rX Is Nothing Then Set rX = New RegExp rX.Pattern = "^([^-]*-)(.+)(-.*)$" End If cleanSDI = rX.Replace(s, "$2") End Function
根据您的数据,您可能需要将.Pattern更改为
rX.Pattern = "^([^-]+-)(.+)(-.+)$"
允许(*)/禁止(+)空头或尾巴。 使用文档通过/了解模式。
If the "-" are part of the input data, you could use a RegExp Replace like:
>> Set r1 = New RegExp >> r1.Pattern = "^[^-]+(-[^-]+-).*" >> WScript.Echo r1.Replace("L2-A-1234", "$1") >> -A-
or:
>> Set r1 = New RegExp >> r1.Pattern = "^[^-]+-([^-]+).*" >> WScript.Echo r1.Replace("L2-B-123", "$1") >> B
Instead of .Replace, you can use Submatches too:
>> WScript.Echo r1.Execute("Don't care-wanted-")(0).SubMatches(0) >> wanted
If you need a function, pass the Regexp into the the function; and remember the return value must be assigned to the function name (removeData <> ExtractSDI).
Another possibility for the second spec ("-" not part of desired output):
>> WScript.Echo Split("Whatever-Wanted-Ignore", "-")(1) >> Wanted
UPDATE:
To deal with "-" embedded in the desired output and to show how this approach can be used in/as a formula:
Option Explicit ' needs Ref to RegExp Dim rX As RegExp Function cleanSDI(s) If rX Is Nothing Then Set rX = New RegExp rX.Pattern = "^([^-]*-)(.+)(-.*)$" End If cleanSDI = rX.Replace(s, "$2") End Function
Depending on your data, you may have to change the .Pattern to
rX.Pattern = "^([^-]+-)(.+)(-.+)$"
to allow (*) / forbid (+) empty heads or tails. Use the Docs to work thru/understand the patterns.
相关问答
更多-
Excel VBA单元格字符限制(Excel VBA cell character limit)[2023-03-18]
它们只是丢失了,没有办法恢复它们。 如果您愿意,可以测试一下: Sub test() Dim i As Long Dim text As String For i = 1 To 32767 text = text & "a" Next text = text & "end" Range("A1").Value = text '"end" will be lost End Sub They are simply lost and there is no way to recover them ... -
如何保护Excel中的单元格,但允许这些修改VBA脚本(Protecting cells in Excel but allow these to be modified by VBA script)[2022-09-25]
尝试使用 Worksheet.Protect "Password", UserInterfaceOnly := True 如果UserInterfaceOnly参数设置为true,则VBA代码可以修改受保护的单元格。 Try using Worksheet.Protect "Password", UserInterfaceOnly := True If the UserInterfaceOnly parameter is set to true, VBA code can modify protecte ... -
您可以尝试使用Application.Calculation Application.Calculation = xlCalculationManual Application.Calculation = xlCalculationAutomatic You could try using Application.Calculation Application.Calculation = xlCalculationManual Application.Calculation = xlCalculation ...
-
代码需要一点点运行,但我已经包含代码来删除上标或“正常化”它。 以下内容采用上标字符并删除它们: Sub DeleteSuperScript() Dim c As Range Application.ScreenUpdating = False For Each c In ActiveSheet.UsedRange For i = 1 To Len(c) If c.Characters(i, 1).Font.SuperScript Then ...
-
从#中删除字符以在列的所有单元格中结束(vba-EXCEL)(Remove characters from # to end in all cells of a column (vba-EXCEL))[2022-06-23]
你可以用公式做到这一点 =LEFT(A1,FIND("#",A1)-1) A1是例如。 OOK: vpjsghe.fkds 2002 field1 Field2 # v2.0.11-28 但请注意,这会导致尾随空间。 要删除它,您可以使用TRIM()或查找空格FIND(" #",A1) 。 You can do it with a formula =LEFT(A1,FIND("#",A1)-1) Where A1 is eg. OOK: vpjsghe.fkds 2002 field1 Field2 # ... -
您可以循环检查worksheet.visible和range.hidden属性的工作表,列和行。 下面是一些快速和肮脏的代码,将输出任何隐藏的元素到即时窗口。 Sub FindHidden() Dim wks As Worksheet Dim rng As Range For Each wks In ThisWorkbook.Worksheets If wks.Visible = xlSheetHidden Then Debug.Print ...
-
从特定行开始删除不需要的列 - excel vba(Deleting unwanted columns starting at a specific row - excel vba)[2022-04-08]
如果你使用EntireColumn.Delete它会删除整个列,你需要获取范围并删除它,例如。 Range("C10:C" & Rows.Count).Delete if you use EntireColumn.Delete it will delete the entire column, you need to get the range and delete that instead, eg. Range("C10:C" & Rows.Count).Delete -
在VBA中删除前面和后面单元格中不需要的字符(excel)(Removing unwanted characters from in-front and behind cells in VBA (excel))[2022-01-31]
如果“ - ”是输入数据的一部分,您可以使用RegExp替换,如: >> Set r1 = New RegExp >> r1.Pattern = "^[^-]+(-[^-]+-).*" >> WScript.Echo r1.Replace("L2-A-1234", "$1") >> -A- 要么: >> Set r1 = New RegExp >> r1.Pattern = "^[^-]+-([^-]+).*" >> WScript.Echo r1.Replace("L2-B-123", "$1") >> ... -
如何使用VBA删除第一个空格后单元格中的字符?(How to remove characters in a cell after the first blank space using VBA?)[2024-01-27]
你真正需要的是这个: Dim LastRow As Long LastRow = Cells(Rows.Count, "M").End(xlUp).Row Range("M22:M" & LastRow).Replace what:=" *", replacement:="", lookat:=xlPart All you really need is this: Dim LastRow As Long LastRow = C ... -
您可以在VBA中使用IIF功能。 它类似于Excel IF [c1] = IIf([a1] = [b1], "Yes", "No") You can use the IIF function in VBA. It is similar to the Excel IF [c1] = IIf([a1] = [b1], "Yes", "No")