データは、Lotus ワークブックに変換される前に何らかのシステムで準備されたようです。ソース システムを見つけて、データが解析しやすい形式であるかどうかを確認してください。
それが利用できない場合は、カスタム パーサーを作成して「=」区切り文字に到達するまで行を読み取り、テキストのブロックを結合して空白をトリミングし、列を正しく配置する必要がある場合があります。
ワークブックをタブ区切り形式で保存し、次を実行してみてください。
' ParseSheet.vbs
Dim fso, Text, Out
Set fso = CreateObject("Scripting.FileSystemObject")
Set Text = fso.OpenTextFile("sample.txt")
Set Out = WScript.StdOut
Dim Columns
Dim Delimiter
Dim Content()
Dim Tab
Dim Line
Tab = Chr(9)
Sub ParseLine(Line)
Dim Column
Dim Delimiter
Dim Value
Column = 1
Line = Line & ":" ' Ensure each row is terminated by the delimiter
Do While Instr(Line, ":") > 0
Value = Left(Line, Instr(Line, ":") - 1)
Value = Replace(Value, Tab, "")
' Skip over column separators
Column = Column + 1
If Column > Columns Then
Columns = Column
ReDim Preserve Content(Columns) ' Grow array to match data
Content(Columns) = ""
End If
If Left(Value, 1) = """" Then ' Strip Quoted strings
Value = Mid(Value, 2, Len(Value) - 2)
End If
If Len(Value) > 0 Then ' Introduce space between most non-empty segments
If (Len(Content(Column)) = 0) Or (Right(Content(Column), 1) = "/") Then
Delimiter = ""
Else
Delimiter = " "
End If
Content(Column) = Content(Column) & Delimiter & Value
End If
Line = Mid(Line, Instr(Line, ":") + 1, Len(Line) - Instr(Line, ":"))
Loop
End Sub
Function Strip(Line)
' Canonicalise emphasised text
Line = Replace(Line, " ", "~")
Line = Replace(Line, " ", "")
Line = Replace(Line, "~", " ")
Strip = Line
End Function
Sub WriteContent(Columns)
Delimiter = ""
For Column = 1 To Columns
Out.Write Delimiter & Trim(Content(Column))
Delimiter = Tab
Content(Column) = ""
Next
Out.WriteLine
End Sub
ReDim Content(1)
Columns = 1
Content(1) = "Group"
Line = Text.ReadLine
Do While Not Text.AtEndOfStream
If Left(Line, 1) = "=" Then
Line = Text.ReadLine
Do While Left(Line, 1) <> "="
Call ParseLine(Line)
' Strip expanded columns
For Column = 2 To 3
Content(Column) = Strip(Content(Column))
Next
Line = Text.ReadLine
Loop
Call WriteContent(Columns)
Line = Text.ReadLine
' Read Group as special case
Content (1) = Strip(Left(Line, Instr(Line, Tab) - 1))
Line = Text.ReadLine
Else
Line = Text.ReadLine
Do While Left(Line, 1) <> "-"
Call ParseLine(Line)
Line = Text.ReadLine
Loop
Call WriteContent(Columns)
End If
Loop
を使用CScript ParseSheet.vbs //NoLogo sample.txt > sample.tab
して、必要なものを大まかに確認します。
結果は、行区切り記号を使用して複数行の列を単一の行にアンラップし、展開された見出しの不必要なスペースを付随的に削除する、タブ区切りのコンソール出力です。
これは、コード スタイルの実践の良い例として意図されたものではありませんが、1 回限りの変換の仕事を行うものです。