2013-02-20 44 views
3

我需要將橫向設置爲文檔的某些頁面。我想這樣的代碼:更改文檔中間的頁面方向

SectPr sectionLandscape = objectFactory.createSectPr(); 

String rsidR = sectionLandscape.getRsidR();  

SectPr sectionPortrait = objectFactory.createSectPr(); 
sectionPortrait.setRsidR(rsidR); 
sectionPortrait.setRsidSect(rsidR);  

PgSz landscape = new PgSz(); 
landscape.setOrient(STPageOrientation.LANDSCAPE); 
landscape.setH(BigInteger.valueOf(11906)); 
landscape.setW(BigInteger.valueOf(16383));  

sectionLandscape.setPgSz(landscape); 

mdp.addObject(sectionLandscape); 

它創建了一個XML代碼:

<w:sectPr> 
    <w:pgSz w:w="16383" w:orient="landscape" w:h="11906"/> 
</w:sectPr> 

與分區的標籤後,有文字和表格,我需要橫向頁面內。在Word 2007/2010中,我只能看到縱向頁面,並且在頁面的編輯模式下,我可以看到選爲橫向的頁面。

http://i.stack.imgur.com/HHuGB.png

+0

不需要rsId的東西。 – JasonPlutext 2013-02-20 20:23:20

回答

2

的sectPr應該是在W:P/W:它是出現在橫向的內容後,PPR

您需要在該內容之前指定肖像的sectPr。

+0

謝謝!它的工作原理,我用此代碼進行測試,並運行: SectPr sectionLandscape = objectFactory.createSectPr(); \t \t PgSz landscape = new PgSz(); landscape.setOrient(STPageOrientation.LANDSCAPE); landscape.setH(BigInteger.valueOf(11906)); landscape.setW(BigInteger.valueOf(16383)); \t sectionLandscape.setPgSz(landscape); \t org.docx4j.wml.P p = objectFactory.createP(); \t \t PPr createPPr = objectFactory.createPPr(); createPPr.setSectPr(sectionLandscape); \t \t p.setPPr(createPPr); \t mdp.addObject(p); – phew 2013-02-21 01:29:49