VBA 代码,用于从与以下模式匹配的文本文件中提取文本 #{pqfn:format('<要提取的文本>')



例如。

我有以下文件数据

<f:facet name="header"><h:outputText  value="#{pqfn:format('FILENAME')}" /></f:facet>
<h:outputText value="#{file.file.notes}"/>
</t:column>
<t:column>
<br></br><h:outputText value="#{pqfn:format('INVALID_DEALER_CODE')}"/>
<f:facet name="header"><h:outputText  value="#{pqfn:format('STATUS')}" /></f:facet>
<h:outputText value="#{bm:getStatusText(file)}"/>
</t:column>
<t:column>
<f:facet name="header"><h:outputText  value="#{pqfn:format('PERIOD')}" /></f:facet>
<h:outputText rendered="#{file.status == 0}" value="#{pqfn:formatPeriod(file.period)}"/>
</t:column>
<t:column>
<f:facet name="header"><h:outputText  value="#{pqfn:format('DEALER')}" /></f:facet>
<h:outputText rendered="#{file.status == 0}" value="#{file.networkEntity.name}"/>
</t:column>
<t:column align="left">
<f:facet name="header">&#160;</f:facet>
<h:selectBooleanCheckbox disabled="#{file.status != 0}" value="#{file.processed}" id="process"/>
<h:outputLabel for="process" value="#{pqfn:format('PROCESS')}" />
</t:column>
</t:dataTable>
</td>`enter code here`
</tr>
<tr>
<td align="center" style="height:40px">
<h:commandButton action="#{submissions.processDmsFiles}" value="#{pqfn:format('PROCESS')}" disabled="#{! submissions.someProcessed}" styleClass="form-button" />
&#160;
<h:commandButton action="#{submissions.dmsImport}" value="#{pqfn:format('CANCEL')}" immediate="true" styleClass="form-button" />
</td>

我需要以下值作为单独的 excel 工作表中的输出

文件名 INVALID_DEALER_CODE 地位 时期 贩子 过程

等等。

谢谢

这应该有效(但它每行一个搜索输出(:

Sub Search()
Const strFileName = "C:UserYourTextfile.txt" 'Textfile path
Const strSearch = "'" 'Textfile search char
Dim strLine As String
Dim f As Integer
Dim lngLine As Long
Dim char1Pos As Integer
char1Pos = 1
Dim char2Pos As Integer
Dim strText As String
f = FreeFile
Open strFileName For Input As #f
Do While Not EOF(f)
lngLine = lngLine + 1
Line Input #f, strLine
If InStr(char1Pos, strLine, strSearch, vbBinaryCompare) > 0 Then
char1Pos = InStr(1, strLine, strSearch, vbBinaryCompare)
char2Pos = InStr(char1Pos + 1, strLine, strSearch, vbBinaryCompare)
strText = Mid(strLine, char1Pos + 1, (char2Pos - char1Pos) - 1)
Debug.Print strText
End If
Loop
Close #f
End Sub

最新更新