【问题标题】:How can the no. of pages in an OpenOffice.org spreadsheet be obtained programmatically?怎么可能没有。以编程方式获取 OpenOffice.org 电子表格中的页数?
【发布时间】:2009-04-23 10:11:15
【问题描述】:

我想计算如果我打印出 OpenOffice.org 文档会产生的页数。我已经可以使用以下代码对 ODT 文件执行此操作:

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 属性,但没有PageBreakCountgetPageBreaks()。 :P

【问题讨论】:

    标签: java api openoffice.org spreadsheet


    【解决方案1】:
    // 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 和一些数学。

    【讨论】:

    • 对不起,我刚刚意识到我没有明确表示我想要否。如果我打印出电子表格会产生的页面。看来,没有。张数可能并不总是与编号相同。打印出来的页数。
    猜你喜欢
    • 2010-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-29
    • 2014-02-16
    相关资源
    最近更新 更多