WordとVB.netのオートメーションを使用して、いくつかのドキュメントをまとめて1つのWordドキュメントを作成する方法VB.NET Word Automation:ファイルを挿入して書式を保存する方法
Word.Documents.Add(firstDocument)を実行し、ファイルの最後に移動してWord.Selection.InsertFile(secondDocument)を実行し、firstDocumentがたとえばVerdana 10ptの場合を除き、期待どおりに動作します。 secondDocumentはCalibiri 11で、firstDocumentのフォント&のスタイルを使用してsecondDocumentを挿入しています。
書式に影響するSelection.InsertFileのドキュメントに何も見つかりませんでしたので、別の方法で制御する必要があります。私はまた、ファイルを挿入する前にページ区切りとセクション区切りを挿入しようとしましたが、それはフォントに違いがないことがわかりました。
現在、私はsecondDocumentからすべてをコピーし、secondDocumentを閉じ、firstDocumentを開いて、最後に移動して貼り付けているアプリを持っています。これは多くの理由で問題がありますが、書式は保持されます。
firstDocumentに挿入するとき、secondDocumentの正確な書式をどのように保持できるかについてのアイデアはありますか?私は離れてクリップボードを使用して取得する必要があります!
ありがとうございます!
編集:ここで私は、ロジックの権利を取得しようとテストしてきたコードだ:
Public Sub TestingWord()
Dim thisApp As New Word.Application
Dim SourceDoc As New Word.Document
Dim DestDoc As New Word.Document
Try
thisApp.Visible = False
DestDoc = thisApp.Documents.Add("X:\Isaac\First.docx")
thisApp.Selection.WholeStory()
thisApp.Selection.EndKey(Unit:=6)
thisApp.Selection.InsertBreak(Word.WdBreakType.wdSectionBreakNextPage)
thisApp.Selection.InsertFile("X:\Isaac\Second.docx")
thisApp.Selection.WholeStory()
thisApp.Selection.EndKey(Unit:=6)
thisApp.Selection.InsertBreak(Word.WdBreakType.wdSectionBreakNextPage)
thisApp.Selection.InsertFile("X:\Isaac\Third.docx")
DestDoc.SaveAs2("X:\Isaac\Yo.docx")
thisApp.Quit(SaveChanges:=Word.WdSaveOptions.wdSaveChanges)
releaseObject(DestDoc)
releaseObject(SourceDoc)
releaseObject(thisApp)
Catch ex As Exception
MsgBox("Error: " & ex.Message.ToString)
Finally
MsgBox("Success!")
End Try
End Sub
は、コピーして貼り付けて元の書式を維持できるようです。http://stackoverflow.com/questions/32472020/add-word-document-and-keep-formatting – Slai
はい、コピーして貼り付けて使用できますしかし、私が元の投稿で言ったように、私は多くの理由でクリップボードを使用しなくてはなりません。 – LegalEagle