C#でPOIを使い、wordファイルのヘッダを取得したいです。
本文は取得できましたが、ヘッダは下記コードでは取得できません。
どのようにしたら良いでしょうか。
よろしくお願いします。
C#
1using (FileStream sr = System.IO.File.OpenRead(@"C:\local\data.docx")) 2{ 3 XWPFDocument document = new XWPFDocument(sr); 4 XWPFWordExtractor we = new XWPFWordExtractor(document); 5 string[] lines = we.Text.Split('\n'); 6 for (int count=1; count< lines.Count(); count++) 7 { 8 Console.WriteLine(lines[count]); 9 } 10 XWPFHeaderFooter hf = new XWPFHeaderFooter(document); ←ヘッダ取得 11}
https://poi.apache.org/apidocs/dev/org/apache/poi/xwpf/usermodel/XWPFHeader.html
を見て、
C#
1XWPFHeader(XWPFDocument doc, org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtr hdrFtr)
でヘッダが取得できそうですが、引数の2番目に何を記載すればよいのか分かりません。
Apache POIのドキュメントはご覧になっておられるのでしょうか?
https://poi.apache.org/apidocs/dev/org/apache/poi/xwpf/usermodel/XWPFDocument.html
https://poi.apache.org/apidocs/dev/org/apache/poi/xwpf/usermodel/XWPFDocument.html#headers
未確認ですが、上記でヘッダ情報リストが取得できると思われますので、試してみてはいかがでしょうか?

あなたの回答
tips
プレビュー