2017-12-11 8 views
0

を使用せずに、DOCXファイルの高さと幅を取得し、私は次のコード内のページのカウントを取得:オフィス

using DocumentFormat.OpenXml.Packaging; 

WordprocessingDocument doc = WordprocessingDocument.Open(@"D:\2pages.docx", false); 

Console.WriteLine(
    doc.ExtendedFilePropertiesPart.Properties.Pages.InnerText.ToString() 
); 

は、私は、ファイルのこの方法の高さと幅で入手できますか? または別の方法でオフィスを使用せずに

+0

これまでに何を試みましたか? – mjwills

+1

「ファイルの高さと幅」とは何ですか?ページの寸法?一般に、1つのWord文書には、ページのサイズが異なる複数のセクションが含まれている場合があります。 –

答えて

1

Aspose.Word(無料ではありません)に建てられたこれらのものを持っています https://docs.aspose.com/display/wordsnet/Changing+Page+Setup+for+Whole+Document+using+Aspose.Words

Document doc = new Document(); 

// This truly makes the document empty. No sections (not possible in Microsoft Word). 
doc.RemoveAllChildren(); 

// Create a new section node. 
// Note that the section has not yet been added to the document, 
// but we have to specify the parent document. 
Section section = new Section(doc); 

// Append the section to the document. 
doc.AppendChild(section); 

// Lets set some properties for the section. 
section.PageSetup.SectionStart = SectionStart.NewPage; 
section.PageSetup.PaperSize = PaperSize.Letter; 

誰かが同様の問題を抱えていたし、これはSO(ただし、OpenXMLの付き)の議論である:
Change Page size of Wor Document using Open Xml SDK 2.0
おそらくあなたはこれからあなたの答えを差し引くことができます。

+0

フリーdllで使用しないで別の答えがありますか?あなたのお世話に感謝します! – Rachel

0

PageSetup.PageHeightプロパティとPageSetup.PageWidthプロパティを使用して、ページの高さと幅を取得してください。これがあなたを助けることを願っています

Document doc = new Document(MyDir + "input.docx"); 

Console.WriteLine(doc.FirstSection.PageSetup.PageHeight); 
Console.WriteLine(doc.FirstSection.PageSetup.PageWidth); 

私は開発者エバンジェリストとしてAsposeを使用しています。

+0

私はそれを試みたが、私のプログラムはこの言葉を知らなかったので、私はdll/use/referenceをDocumentとMyDirの単語と一緒に使う必要がある。あなたのanswer-rachelを待つ – Rachel

+0

参照DLLは[Aspose.Words for .NET](https://www.nuget.org/packages/Aspose.Words/)で、MyDirは文字列変数です。 –

+0

無料のDLLを使用せずに別の答えがありますか? – Rachel

関連する問題