本帖最后由 pcl_test 于 2016-7-25 00:19 编辑
回复 21# doswork - Set fso = CreateObject("Scripting.FileSystemObject")
- Set shell = CreateObject("WScript.Shell")
-
- str="c: ntfs"&vbTab&"共:55 GB"&vbTab&"可用15 GB"&vbTab&"使用率 60%" _
- & vbCrLf &"d: ntfs"&vbTab&"共:95.512 GB"&vbTab&"可用15.512 GB"&vbTab&"使用率 60%" _
- & vbCrLf &"e: fat32"&vbTab&"共:95 GB"&vbTab&"可用1.5 GB"&vbTab&"使用率 2%"
-
-
- outfile="outfile.txt"
- msgbox(str)
- ShowInfo(replace("方法一,表格<br/>"&formatTable(str), VbCrLf, "<br/>"))
- ShowInfo(replace("方法二,按字段长度填充空格<br/>"&formatSpace(str), VbCrLf, "<br/>"))
-
- '自定义对话框
- Function ShowInfo(info)
- CreateObject("WScript.Shell").Exec("mshta.exe ""about:<hta:application showintaskbar=no />" &_
- "<title>提示</title><script>window.resizeTo(600, 600);" & _
- "function writetxt(){var txt=document.getElementById('info').innerText.replace(/<br\/>/g, '\r\n');" & _
- "(new ActiveXObject('Scripting.FileSystemObject')).OpenTextFile('"& outfile &"',2,true).write(txt);close();}</script>" & _
- "<body style='font-family:SimSun;'><div style='position:fixed;top:0;left:0;'>是否保存以下信息到文本文件 <font style='color:#FF0000;'>"& outfile &"</font>?" & _
- "<input type='button' value='是(Y)' onclick='writetxt()'> " & _
- "<input type='button' value='否(N)' onclick='window.close()'></div><br/><div id='info'><font style='color:#008200;'>"& info &"</font></div></body>""").StdOut.ReadAll
- End Function
-
- '套入表格
- Function formatTable(str)
- tr=split(str, vbCrLf)
- For i=0 to Ubound(tr)
- s=s&"<tr>"
- td = split(tr(i), vbTab)
- For j=0 to Ubound(td)
- s=s&"<td>"&td(j)&"</td>"
- Next
- s=s&"</tr>"
- Next
- formatTable="<table>"&s&"</table>"
- End Function
-
- '按字段长度填充空格
- Function formatSpace(str)
- sp=Space(100)
- Set objDict = WSH.CreateObject("Scripting.Dictionary")
- tr=split(str, vbCrLf)
- For i=0 to Ubound(tr)
- td = split(tr(i), vbTab)
- For j=0 to Ubound(td)
- l=0
- n=0
- For k=1 to len(td(j))
- c=Asc(Mid(td(j), k, 1))
- If c>0 and c<127 Then
- l = l+1
- Else
- n = n+1
- l = l+2
- End If
- Next
- If n>0 Then objDict.Add "#"&i&j, n
- If not objDict.Exists(j) Then
- objDict.Add j, l
- Else
- If l > CInt(objDict.Item(j)) Then objDict.Item(j)=l
- End If
- Next
- Next
-
- For i=0 to Ubound(tr)
- td = split(tr(i), vbTab)
- For j=0 to Ubound(td)-1
- If objDict.Exists("#"&i&j) Then
- s=s&replace(left(td(j)&sp, objDict.Item(j)-objDict.Item("#"&i&j)+3), " ", " ")
- Else
- s=s&replace(left(td(j)&sp, objDict.Item(j)+3), " ", " ")
- End If
- Next
- s=s&td(Ubound(td))&vbCrLf
- Next
- formatSpace=s
- End Function
复制代码
|