2009-04-23 9 views
1

OpenOffice.orgドキュメントを印刷した場合に生成されるページ数を数えたいと思います。どうすればいいですか? OpenOffice.orgスプレッドシートのページをプログラムで取得できますか?

public short getPageCount() { 
     XModel model = (XModel) UnoRuntime.queryInterface(XModel.class, 
         getDocument()); 

     XTextViewCursorSupplier supplier = (XTextViewCursorSupplier) UnoRuntime 
         .queryInterface(XTextViewCursorSupplier.class, model 
             .getCurrentController()); 

     XTextViewCursor viewCursor = supplier.getViewCursor(); 

     XPageCursor pageCursor = (XPageCursor) UnoRuntime.queryInterface(
         XPageCursor.class, viewCursor); 

     pageCursor.jumpToLastPage(); 

     return pageCursor.getPage(); 
} 

public Object getDocument() { 
     XComponentContext context = Bootstrap.bootstrap(); 

     XMultiComponentFactory factory = context.getServiceManager(); 

     Object desktop = factory.createInstanceWithContext(
         "com.sun.star.frame.Desktop", context); 

     XComponentLoader loader = (XComponentLoader) UnoRuntime.queryInterface(
         XComponentLoader.class, desktop); 

     XComponent component = loader.loadComponentFromURL("file:///path/to/file.odt", 
         "_blank", 0, new PropertyValue[0]); 

     return UnoRuntime.queryInterface(XTextDocument.class, 
         component); 
} 

私はODSファイルと同様のことができるかどうかを知りたいと思います。たぶん、いいえを数えます。シートに改ページの? SpreadsheetViewSettingsクラスにはShowPageBreaksプロパティがありますが、PageBreakCountまたはgetPageBreaks()はありません。 :P

答えて

0
// get the sheet document using UnoRuntime 
XSpreadsheetDocument sheetDoc = ...; 
// get an object containing all sheets 
XSpreadsheets sheets = sheetDoc.getSheets(); 
// get the sheets names 
String[] sheetnames = sheets.getElementNames(); 

あなたは何かを数えたり繰り返したりできます。

編集:
シート自体にはおそらく印刷ページの概念がありません。
だから、XPrintPreviewのようなものを使う必要があると思いますが、そこからページを特定する方法がわかりません。 Printing Spreadsheet Documentsを参照し、PrintAreasといくつかの数学を試してみてください。

+0

申し訳ありませんが、私は気づいていませんでした。私がスプレッドシートを印刷した場合に生成されるページの数。 常に同じではない場合があります。印刷されたページの数。 –

関連する問題