0

個別の HTML ファイルに変換した pdf ファイルがあります。私の目標は、それらを MS SQL にインポートして、テーブルで特定の識別子を検索し、結果を Web ページに表示できるようにすることです。

すべての html ファイルを読み取って SQL テーブルに入れることはできますが、複数の div コンテナーに分割されているため、コンバーターによって完全な文が切り取られています。

<div class="S2"> DA0-17.0</div>
<div class="S5"> 1416</div>
<div class="S2"> Required when the subscriber is the same person as the patient. If</div>
<div class="S5"> 2698</div>
<div class="S2"> the subscriber is not the same person as the patient, do not use</div>
<div class="S2"> this element.</div>
<div class="S4"> CODE</div>
<div class="S4"> DEFINITION</div>
<div class="S2"> 18</div>
<div class="S2"> Self</div>

クラス S2 を取得しようとしています。

クラス S5 や S4 は必要ありません 添付は SQL 結果のサンプルです。挿入文字列は、必要なフィールドの数に応じて動的に作成されます。

SQL の結果

以下は、挿入値を作成する部分です。

If iFieldNum = 1 Then
    sInsertstring = sInsertstring + "id2, " + "num" + CStr(iFieldNum)
    sInsertValues = sInsertValues + "'" + msbr + "', '" + ms2 + "'"
Else
    sInsertstring = sInsertstring + ", num" + CStr(iFieldNum)
    sInsertValues = sInsertValues + ", '" + ms2 + "'"
End If
iFieldNum += 1

うまくいけば、誰かがこの問題について私を助けてくれるか、この問題を解決する方法について正しい方向に向けてくれます. 完全なコードはリクエストに応じて入手できます。お時間をいただきありがとうございます、ロバート。

Ps: これはアプリケーション ベースであり、Web ではありません

エドパーへの返信:

Dim fFileName As String
Dim dListing As New DirectoryInfo(My.Settings.ImportDir)
Dim aFileArray As FileInfo() = dListing.GetFiles()
Dim fFiles As FileInfo
    For Each fFiles In aFileArray
    fFileName = fFiles.Name
    Dim fStream = New FileStream(My.Settings.ImportDir + "\" + fFileName, FileMode.Open)
    Dim sReader = New StreamReader(fStream)

エドパーへの返信。
私が欲しいのは次のとおりです。

HTML ファイル (約 700) には、異なるクラス名を持つ div コンテナーがあります。

 <div class="S2"> Required when the subscriber is the same person as the patient. If</div>
 <div class="S5"> 2698</div>
 <div class="S2"> the subscriber is not the same person as the patient, do not use</div>
 <div class="S2"> this element.</div>

発生ごとに挿入ステートメントを作成できますが、<div class="S5">との間の「説明」<div class="S4">を 1 行の長いテキストにしたいのですが、現時点では 3 つの部分に分割されていますが、これは望ましくありません。それらを組み合わせる方法を知っています。
VB.NET に関する私の知識はかなり限られており、学習を進めながら学習しようとしています。私は従来の ASP で効率的でしたが、この場合はうまくいきません。

私の質問の表現が悪くて申し訳ありません..
私は単にそれをさらに説明する方法がわかりません..

4

1 に答える 1

0

おそらくWebbrowser、フォームにコントロールをドロップして、それvisible = falseを表示しないようにすることができます。次に、次のように文字列ビルダーのグローバル変数を宣言します。

Dim builder As New StringBuilder

次に、このコードですべての HTML ファイルを取得すると、おそらく次のようにすることができます。

Dim fFileName As String
Dim dListing As New DirectoryInfo(My.Settings.ImportDir)
Dim aFileArray As FileInfo() = dListing.GetFiles()
Dim fFiles As FileInfo

For Each fFiles In aFileArray
    WebBrowser1.Navigate(dListing&"\"&fFiles)
Next

そして、WebBrowser1_DocumentCompletedイベントを使用して html が完全にロードされると、次のようなS2複数のクラスからすべてのクラス ( など) を取得します。divs

    Dim elems As HtmlElementCollection
    elems = WebBrowser1.Document.GetElementsByTagName("DIV")

    For Each elem As HtmlElement In elems

        If (elem.GetAttribute("className") = "S2") Then
            builder.Append(elem.InnerHtml).Append(" ")
        End If
    Next

    'Do something for string builder (i.e. builder.ToString()) here before clearing the String Builder like this could be where you insert the records to your table probably

    builder.Clear()
于 2013-05-23T00:24:50.367 に答える