Top > OOoBeanShell > Calc > drawpage

ドローページとドローオブジェクト Edit

OOoBeanShell で Calc のシート上に描かれたドローオブジェクトを取り扱うためにドローページへアクセスします。そして,ドローページからドローオブジェクトを取得,削除します。

import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.frame.XDesktop;
import com.sun.star.frame.XModel;
import drafts.com.sun.star.script.provider.XScriptContext;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.drawing.XDrawPagesSupplier;
import com.sun.star.drawing.XDrawPages;
import com.sun.star.drawing.XDrawPage;
import com.sun.star.drawing.XShape;
import com.sun.star.beans.XPropertySet;
import com.sun.star.beans.PropertyValue;
import com.sun.star.sheet.XSpreadsheetDocument;
import com.sun.star.sheet.XSpreadsheets;
import com.sun.star.lang.XComponent;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.container.XIndexAccess;
oDoc = XSCRIPTCONTEXT.getDocument();
XSpreadsheetDocument xSheetDoc = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, oDoc);
XSpreadsheets xSpreadsheets = xSheetDoc.getSheets();
XDrawPagesSupplier xDrawPagesSupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(XDrawPagesSupplier.class, xSheetDoc);
Object drawPages = xDrawPagesSupplier.getDrawPages();
XIndexAccess xIndexAccess = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,drawPages);
Object drawPage = xIndexAccess.getByIndex(0);
XDrawPage xDrawPage = (XDrawPage) UnoRuntime.queryInterface(XDrawPage.class, drawPage);
if (xDrawPage.getCount()!=0){
Object drawing = xDrawPage.getByIndex(0);
XShape shape = (XShape) UnoRuntime.queryInterface(XShape.class,drawing);
xDrawPage.remove(shape);
}
// BeanShell OpenOffice.org scripts should always return 0
return 0;

Reload   New Lower page making Edit Freeze Diff Upload Copy Rename   Front page List of pages Search Recent changes Backup   Help   RSS of recent changes