2016-05-04 46 views
0

私は私のプログラムのためのレポートを生成するためにMS Wordを使用してきましたが、すべてがうまくいきます。今私は同じコードで別のもの(私が望むものではない)を使ってみたので問題がWordのテンプレートから来ていることを知っています。WordはVB.NETを使用している特定のテンプレートでフリーズ

  1. 、テンプレートを削除して新しいものにコピー/ペーストを使用して、新しいものを作る:ここ

    は、私がこれまで試したもののリストです。
  2. 最初から作成する。 (ただし、この1つのテンプレートだけでフリーズしています。通常は何もありません。同じテーブルとデータを持つ別のテンプレートがありますが、フリーズしません)
  3. add- MS Wordから(管理者として、そしてそれなしで)
  4. テンプレートを開いて修復する。

私はコードは必要ないと思っていますが、誰かが何かを見たら私は自分のコードを投稿します。

すべてのヘルプは大歓迎:)

編集:

If My.Settings.Language = "Arabic" Then 
     Dim appWord As Word.Application = New Microsoft.Office.Interop.Word.Application 

     If appWord Is Nothing Then 
      MessageBox.Show("Word is not properly installed!!") 
      Return 
     End If 

     Dim doc As Word.Document 

     appWord = CreateObject("Word.Application") 
     appWord.Visible = False 

     doc = appWord.Documents.Add(Application.StartupPath & "\AncestorsSheetTempArabic2.dotx") 

     connect() 
     Dim objConn As OleDbConnection 
     objConn = acsconn 
     objConn.Open() 


     Dim daMain As OleDbDataAdapter 
     Dim DataSetMain As DataSet 
     Dim strSQLMain As String 

     If ID = 0 Or ID = 1 Or ID = vbNull Then 
      strSQLMain = "SELECT * from People WHERE ((ID=" & IDW & "))" 
     Else 
      strSQLMain = "SELECT * from People WHERE ((ID=" & ID & "))" 
     End If 

     daMain = New OleDbDataAdapter(strSQLMain, objConn) 
     DataSetMain = New DataSet 
     DataSetMain.Clear() 
     daMain.Fill(DataSetMain, "Main") 

     With doc 
      .FormFields("PersonTitle").Result = DataSetMain.Tables("Main").Rows(0).Item("FirstName") & " " & DataSetMain.Tables("Main").Rows(0).Item("LastName") 
      ''''PERSON''''' 
      .FormFields("PersonsName").Result = DataSetMain.Tables("Main").Rows(0).Item("FirstName") & " " & DataSetMain.Tables("Main").Rows(0).Item("LastName") 
      If IsDBNull(DataSetMain.Tables("Main").Rows(0).Item("BirthDate")) Then 
       .FormFields("PersonsBirthDate").Result = "(غير معروف)" 
      Else 
       .FormFields("PersonsBirthDate").Result = DataSetMain.Tables("Main").Rows(0).Item("BirthDate") 
      End If 
      If DataSetMain.Tables("Main").Rows(0).Item("BirthPlace") = "" Or IsDBNull(DataSetMain.Tables("Main").Rows(0).Item("BirthPlace")) Then 
       .FormFields("PersonsBirthPlace").Result = "(غير معروف)" 
      Else 
       .FormFields("PersonsBirthPlace").Result = DataSetMain.Tables("Main").Rows(0).Item("BirthPlace") 
      End If 

      Try 
       If IsDBNull(DataSetMain.Tables("Main").Rows(0).Item("PictureFile")) Then 
       Else 
        Dim bytes As Byte() = (DataSetMain.Tables("Main").Rows(0).Item("PictureFile")) 
        Dim ms As New MemoryStream(bytes) 
        Dim img As Image = Image.FromStream(ms) 
        img = FixedSize(img, 100, 100) 

        Dim ms2 As New MemoryStream 
        img.Save(GetDesktop() & "\TempImage.jpg", System.Drawing.Imaging.ImageFormat.Jpeg) 

        .InlineShapes.AddPicture(GetDesktop() & "\TempImage.jpg").Select() 
        appWord.Selection.Cut() 
        .Tables(3).Cell(1, 1).Select() 
        appWord.Selection.PasteAndFormat(Word.WdRecoveryType.wdChartPicture) 
        appWord.Selection.Cut() 
        .Tables(3).Cell(1, 1).Select() 
        appWord.Selection.Paste() 
        My.Computer.FileSystem.DeleteFile(GetDesktop() & "\TempImage.jpg") 

       End If 
      Catch ex As Exception 

      End Try 
      .FormFields("PersonsNameEvents").Result = DataSetMain.Tables("Main").Rows(0).Item("FirstName") & " " & DataSetMain.Tables("Main").Rows(0).Item("LastName") 

      If IsDBNull(DataSetMain.Tables("Main").Rows(0).Item("CurrentEducationLevel")) Then 
      Else 
       .FormFields("EventsName").Result = "التعليم: " 
       .FormFields("EventsDisc").Result = DataSetMain.Tables("Main").Rows(0).Item("CurrentEducationLevel") 
       .Tables(3).Rows(3).Select() 'Select the table 
       appWord.Selection.CopyAsPicture() 'Copy the table 
       appWord.Selection.MoveDown(Word.WdUnits.wdParagraph, 1) 
       appWord.Selection.PasteAndFormat(Word.WdRecoveryType.wdPasteDefault) 'pastes the original table(template) 
      End If 
      If DataSetMain.Tables("Main").Rows(0).Item("Nationality") = "" Or IsDBNull(DataSetMain.Tables("Main").Rows(0).Item("Nationality")) Then 
      Else 
       .FormFields("EventsName").Result = "الجنسية: " 
       .FormFields("EventsDisc").Result = DataSetMain.Tables("Main").Rows(0).Item("Nationality") 
       .Tables(3).Rows(3).Select() 'Select the table 
       appWord.Selection.CopyAsPicture() 'Copy the table 
       appWord.Selection.MoveDown(Word.WdUnits.wdParagraph, 1) 
       appWord.Selection.PasteAndFormat(Word.WdRecoveryType.wdPasteDefault) 'pastes the original table(template) 
      End If 
      If DataSetMain.Tables("Main").Rows(0).Item("CurrentJob") = "" Or IsDBNull(DataSetMain.Tables("Main").Rows(0).Item("CurrentJob")) Then 
      Else 
       .FormFields("EventsName").Result = "المهنة: " 
       .FormFields("EventsDisc").Result = DataSetMain.Tables("Main").Rows(0).Item("CurrentJob") 
       .Tables(3).Rows(3).Select() 'Select the table 
       appWord.Selection.CopyAsPicture() 'Copy the table 
       appWord.Selection.MoveDown(Word.WdUnits.wdParagraph, 1) 
       appWord.Selection.PasteAndFormat(Word.WdRecoveryType.wdPasteDefault) 'pastes the original table(template) 
      End If 
      If DataSetMain.Tables("Main").Rows(0).Item("Religion") = "" Or IsDBNull(DataSetMain.Tables("Main").Rows(0).Item("Religion")) Then 
      Else 
       .FormFields("EventsName").Result = "الديانة: " 
       .FormFields("EventsDisc").Result = DataSetMain.Tables("Main").Rows(0).Item("Religion") 
       .Tables(3).Rows(3).Select() 'Select the table 
       appWord.Selection.CopyAsPicture() 'Copy the table 
       appWord.Selection.MoveDown(Word.WdUnits.wdParagraph, 1) 
       appWord.Selection.PasteAndFormat(Word.WdRecoveryType.wdPasteDefault) 'pastes the original table(template) 
      End If 
      If .FormFields("EventsName").Result = "" And .FormFields("EventsDisc").Result = "" Then 
       .Tables(3).Rows(3).Select() 'Select the table 
       appWord.Selection.Delete() 
       .Tables(3).Rows(2).Select() 'Select the table 
       appWord.Selection.Delete() 
      End If 
      'daKids.Dispose() 
      '''''''FATHER'''''' 
      Dim daFatherRela As OleDbDataAdapter 
      Dim DataSetFatherRela As DataSet 
      Dim strSQLFatherRela As String 

      strSQLFatherRela = "SELECT * from Relationship WHERE ((Person2ID=" & DataSetMain.Tables("Main").Rows(0).Item("ID") & " and RelationshipeTypeCode=2))" 

      daFatherRela = New OleDbDataAdapter(strSQLFatherRela, objConn) 
      DataSetFatherRela = New DataSet 
      DataSetFatherRela.Clear() 
      daFatherRela.Fill(DataSetFatherRela, "FatherRela") 

      Dim daFather As OleDbDataAdapter 
      Dim DataSetFather As DataSet 
      Dim strSQLFather As String 
      Dim FathersID As String 

      For i = 0 To DataSetFatherRela.Tables("FatherRela").Rows.Count - 1 
       strSQLFather = "SELECT * from People WHERE ((ID=" & DataSetFatherRela.Tables("FatherRela").Rows(i).Item("Person1ID") & "))" 
       FathersID = DataSetFatherRela.Tables("FatherRela").Rows(i).Item("Person1ID").ToString 
       daFather = New OleDbDataAdapter(strSQLFather, objConn) 
       DataSetFather = New DataSet 
       DataSetFather.Clear() 
       daFather.Fill(DataSetFather, "Father") 
       If DataSetFather.Tables("Father").Rows.Count > 0 Then 
        .FormFields("PNum").Result = .Tables.Count - 4 
        .FormFields("PName").Result = DataSetFather.Tables("Father").Rows(0).Item("FirstName") & " " & DataSetFather.Tables("Father").Rows(0).Item("LastName") 
        If IsDBNull(DataSetFather.Tables("Father").Rows(0).Item("BirthDate")) Then 
         .FormFields("PDOB").Result = "(غير معروف)" 
        Else 
         .FormFields("PDOB").Result = DataSetFather.Tables("Father").Rows(0).Item("BirthDate") 
        End If 
        If DataSetFather.Tables("Father").Rows(0).Item("BirthPlace") = "" Or IsDBNull(DataSetFather.Tables("Father").Rows(0).Item("BirthPlace")) Then 
         .FormFields("PPOB").Result = "(غير معروف)" 
        Else 
         .FormFields("PPOB").Result = DataSetFather.Tables("Father").Rows(0).Item("BirthPlace") 
        End If 


        Try 
         If IsDBNull(DataSetFather.Tables("Father").Rows(0).Item("PictureFile")) Then 
         Else 
          Dim bytes As Byte() = (DataSetFather.Tables("Father").Rows(0).Item("PictureFile")) 
          Dim ms As New MemoryStream(bytes) 
          Dim img As Image = Image.FromStream(ms) 
          img = FixedSize(img, 100, 100) 

          Dim ms2 As New MemoryStream 
          img.Save(GetDesktop() & "\TempImage.jpg", System.Drawing.Imaging.ImageFormat.Jpeg) 

          .InlineShapes.AddPicture(GetDesktop() & "\TempImage.jpg").Select() 
          appWord.Selection.Cut() 
          .Tables(5).Cell(1, 1).Select() 
          appWord.Selection.PasteAndFormat(Word.WdRecoveryType.wdChartPicture) 
          appWord.Selection.Cut() 
          .Tables(5).Cell(1, 1).Select() 
          appWord.Selection.Paste() 
          My.Computer.FileSystem.DeleteFile(GetDesktop() & "\TempImage.jpg") 

         End If 
        Catch ex As Exception 

        End Try 

        .FormFields("PNameEvents").Result = DataSetFather.Tables("Father").Rows(0).Item("FirstName") & " " & DataSetFather.Tables("Father").Rows(0).Item("LastName") 

        If IsDBNull(DataSetFather.Tables("Father").Rows(0).Item("CurrentEducationLevel")) Then 
        Else 
         .FormFields("PEventsName").Result = "التعليم: " 
         .FormFields("PEventsDisc").Result = DataSetFather.Tables("Father").Rows(0).Item("CurrentEducationLevel") 
         .Tables(5).Rows(3).Select() 'Select the table 
         appWord.Selection.CopyAsPicture() 'Copy the table 
         appWord.Selection.MoveDown(Word.WdUnits.wdParagraph, 1) 
         appWord.Selection.PasteAndFormat(Word.WdRecoveryType.wdPasteDefault) 'pastes the original table(template) 
        End If 
        If IsDBNull(DataSetFather.Tables("Father").Rows(0).Item("Nationality")) Then 
        Else 
         .FormFields("PEventsName").Result = "الجنسية: " 
         .FormFields("PEventsDisc").Result = DataSetFather.Tables("Father").Rows(0).Item("Nationality") 
         .Tables(5).Rows(3).Select() 'Select the table 
         appWord.Selection.CopyAsPicture() 'Copy the table 
         appWord.Selection.MoveDown(Word.WdUnits.wdParagraph, 1) 
         appWord.Selection.PasteAndFormat(Word.WdRecoveryType.wdPasteDefault) 'pastes the original table(template) 
        End If 
        If IsDBNull(DataSetFather.Tables("Father").Rows(0).Item("CurrentJob")) Then 
        Else 
         .FormFields("PEventsName").Result = "المهنة: " 
         .FormFields("PEventsDisc").Result = DataSetFather.Tables("Father").Rows(0).Item("CurrentJob") 
         .Tables(5).Rows(3).Select() 'Select the table 
         appWord.Selection.CopyAsPicture() 'Copy the table 
         appWord.Selection.MoveDown(Word.WdUnits.wdParagraph, 1) 
         appWord.Selection.PasteAndFormat(Word.WdRecoveryType.wdPasteDefault) 'pastes the original table(template) 
        End If 
        If IsDBNull(DataSetFather.Tables("Father").Rows(0).Item("Religion")) Then 
        Else 
         .FormFields("PEventsName").Result = "الديانة: " 
         .FormFields("PEventsDisc").Result = DataSetFather.Tables("Father").Rows(0).Item("Religion") 
         .Tables(5).Rows(3).Select() 'Select the table 
         appWord.Selection.CopyAsPicture() 'Copy the table 
         appWord.Selection.MoveDown(Word.WdUnits.wdParagraph, 1) 
         appWord.Selection.PasteAndFormat(Word.WdRecoveryType.wdPasteDefault) 'pastes the original table(template) 
        End If 
        'If .FormFields("EventsName").Result = "" And .FormFields("EventsDisc").Result = "" Then 
        ' .Tables(5).Rows(3).Select() 'Select the table 
        ' appWord.Selection.Delete() 
        ' .Tables(3).Rows(2).Select() 'Select the table 
        ' appWord.Selection.Delete() 
        'End If 
        .Tables(5).Select() 
        appWord.Selection.CopyAsPicture() 'Copy the table 
        appWord.Selection.MoveDown(Word.WdUnits.wdParagraph, 1) 'moves after the table 
        'appWord.Selection.MoveDown(Word.WdUnits.wdScreen, 2) 
        'appWord.DefaultTableSeparator = Environment.NewLine & "-" 
        Try 
         appWord.Selection.InsertStyleSeparator() 

        Catch ex As Exception 

        End Try 
        appWord.Selection.PasteAndFormat(Word.WdRecoveryType.wdPasteDefault) 'pastes the original table(template) 
        Try 
         appWord.Selection.InsertStyleSeparator() 
        Catch ex As Exception 

        End Try 
'''''''''''''''''''''''''''' After this line nothing works ''''''''''''''''''''''''''''''''''' 
        .Tables(6).Split(.Tables(6).Rows.Count) ''''''''''''''''''''''' 
       End If 

      Next 
      '''''''''''''''''''''' After this is the same code as the father but for finding the Mother and grandparents ... etc ... I can't add them because that is too much characters. 
      objConn.Close() 
     End With 
     appWord.Visible = True 

    ElseIf My.Settings.Language = "English" Then 

    End If 

これは、問題がどこにあるIF文の「アラビア語」部分にある......、私が使用しているコードですが同じコードが "英語"の部分で使われていますが、何も間違いはありません。

は、英語の部分では、文書は、私は、アラビア語の部分とすべてがうまくいったことを試してみました

doc = appWord.Documents.Add(Application.StartupPath & "\AncestorsSheetTemp.dotx") 

です。だから、明らかに

+0

をあなたがしている間、目に見える言葉ですレポートを作成しますか?警告が表示されているかどうかを確認することができます。 –

+0

私はそれを試みました。一番上に「応答しない」と表示されます。 –

+0

ロックアップが発生したコード行と使用しているデータを質問に追加できますか? –

答えて

0

、この部分を削除:

Try 
    appWord.Selection.InsertStyleSeparator() 

Catch ex As Exception 

End Try 

は、問題を解決しました。その部分は、すべて私のコードの上にあると私はどこにもそれで問題をもらっていないので、私は本当に理解していないけど。しかし助けを/

感謝:)

関連する問題