2016-06-01 12 views
0

関数をhttps://msdn.microsoft.com/en-us/library/office/cc546917.aspxから使用しています。問題は、ドキュメントのヘッダーセクションにある可能性のあるイメージやテーブルを取得していないことです。ヘッダーから他の文書にすべてを取得する方法はありますか?1つのWord文書から別のWord文書に複合ヘッダーを追加する

+0

を、手動のタイプに基づいてそれらを個別にコピーする必要がありますあなたのヘッダーが保持する内容。 – Flowerking

答えて

0

私は1つのファイルからヘッダを取得し、別のものにそれらを挿入するために、次のコードを使用することができたOpenXMLPowerTools使用:残念ながら

var to = @"C:\Users\dheale\Desktop\Word Docs\_Blank_Skeleton.DOCX"; 
var from = @"C:\Users\dheale\Desktop\Word Docs\Letterheads\StandardLetterhead3.DOCX"; 
var outDoc = @"C:\Users\dheale\Desktop\Word Docs\test.DOCX"; 

var sources = new List<Source> 
{ 
    new Source(new WmlDocument(to), false), 
    new Source(new WmlDocument(from), true) 
}; 

DocumentBuilder.BuildDocument(sources, outDoc); 
0

下記のVBAスクリプトはあなたのためにそれを行う必要があります。 Word文書から実行します。適するように修正する。

Sub editAll() 
    Dim Doc 
    Dim i As Integer 
    Dim docToOpen As FileDialog 
    Set docToOpen = Application.FileDialog(msoFileDialogFilePicker) 
    docToOpen.Show 
    For i = 1 To docToOpen.SelectedItems.Count 
     'Open each document 
     Set Doc = Documents.Open(FileName:=docToOpen.SelectedItems(i)) 

     With ActiveDocument.Sections(1) 
      'insert new headers 
      Call editheader 
     End With 
    Next i 
End Sub 


Sub editheader() 

    If ActiveWindow.View.SplitSpecial <> wdPaneNone Then 
     ActiveWindow.Panes(2).Close 
    End If 
    If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _ 
     ActivePane.View.Type = wdOutlineView Then 
     ActiveWindow.ActivePane.View.Type = wdPrintView 
    End If 
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader 
    With Selection.PageSetup 
     .LineNumbering.Active = False 
     .Orientation = wdOrientPortrait 
     .TopMargin = InchesToPoints(1) 
     .BottomMargin = InchesToPoints(1) 
     .LeftMargin = InchesToPoints(1) 
     .RightMargin = InchesToPoints(1) 
     .Gutter = InchesToPoints(0) 
     .HeaderDistance = InchesToPoints(0.1) 
     .FooterDistance = InchesToPoints(0.5) 
     .PageWidth = InchesToPoints(8.5) 
     .PageHeight = InchesToPoints(11) 
     .FirstPageTray = wdPrinterDefaultBin 
     .OtherPagesTray = wdPrinterDefaultBin 
     .SectionStart = wdSectionNewPage 
     .OddAndEvenPagesHeaderFooter = False 
     .DifferentFirstPageHeaderFooter = False 
     .VerticalAlignment = wdAlignVerticalTop 
     .SuppressEndnotes = False 
     .MirrorMargins = False 
     .TwoPagesOnOne = False 
     .BookFoldPrinting = False 
     .BookFoldRevPrinting = False 
     .BookFoldPrintingSheets = 1 
     .GutterPos = wdGutterPosLeft 
    End With 
    Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter. _ 
     LinkToPrevious 
    Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter. _ 
     LinkToPrevious 
    Selection.InlineShapes.AddPicture FileName:= _ 
     "C:\Users\rshuell001\Desktop\test\asher.jpg", LinkToFile:=False, _ 
     SaveWithDocument:=True 
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument 
End Sub 
+0

ありがとう、しかし、私はVBAスクリプトを介してそれを実行することはできません、それはC#のサーバー側でなければなりません。 –

関連する問題