/**
* 表計算の操作
*/
import com.sun.star.lang.*;
import com.sun.star.bridge.*;
import com.sun.star.uno.*;
import com.sun.star.frame.*;
import com.sun.star.sheet.*;
import com.sun.star.container.XIndexAccess;
import com.sun.star.table.*;
import com.sun.star.beans.PropertyValue;
public class Calc {
XMultiServiceFactory xMSF = null;
public Calc(XMultiServiceFactory xMSF)
{
this.xMSF = xMSF;
}
/**
* Calc ドキュメントを起動します。
* @param doc オープンするドキュメント
* @param type _blankなど、開き方
* @return XSpreadsheetDocument
*/
public XSpreadsheetDocument open(String doc,String type)
throws java.lang.Exception
{
//define variables
XInterface oInterface;
XDesktop oDesktop;
XComponentLoader oCLoader;
XSpreadsheetDocument oDoc = null;
XComponent aDoc = null;
oInterface =
(XInterface) xMSF.createInstance("com.sun.star.frame.Desktop");
oDesktop =
(XDesktop)UnoRuntime.queryInterface(XDesktop.class,oInterface);
oCLoader =
(XComponentLoader) UnoRuntime.queryInterface(
XComponentLoader.class,oDesktop);
PropertyValue[] szEmptyArgs = new PropertyValue[0];
aDoc = oCLoader.loadComponentFromURL(doc,type, 0, szEmptyArgs);
oDoc = (XSpreadsheetDocument) UnoRuntime.queryInterface(
XSpreadsheetDocument.class,aDoc);
return oDoc;
}
/**
* シートをとってきます。
* @param myDoc とってくるドキュメント
* @param pos 取ってくるシート(0先頭)
* @return XSpreadsheet
*/
public XSpreadsheet getSheetByPosition
(XSpreadsheetDocument myDoc,int pos)
throws java.lang.Exception
{
XSpreadsheet oSheet = null;
//Calc のシートオブジェクトを取得
XSpreadsheets oSheets = myDoc.getSheets();
XIndexAccess oIndexSheets =
(XIndexAccess) UnoRuntime.queryInterface(
XIndexAccess.class,oSheets);
//一番目のシートオブジェクトを取得
oSheet = (XSpreadsheet) UnoRuntime.queryInterface(
XSpreadsheet.class,oIndexSheets.getByIndex(pos));
return oSheet;
}
/**
* セルをとってきます。
* @param oSheet とってくるシート
* @param posstr 場所
* @return XCell
*/
public XCell getRange(XSpreadsheet oSheet,String posstr)
throws java.lang.Exception
{
//==========================//
//指定されたレンジを取ってくる
//==========================//
XCellRange xCellRange = oSheet.getCellRangeByName(posstr);
com.sun.star.sheet.XSheetCellRange xSheetCellRange =
(com.sun.star.sheet.XSheetCellRange) UnoRuntime.queryInterface(
com.sun.star.sheet.XSheetCellRange.class,xCellRange);
com.sun.star.sheet.XSheetCellCursor xSheetCellCursor =
oSheet.createCursorByRange(xSheetCellRange);
//==========================//
//そこにカーソルを持ってきて
//==========================//
com.sun.star.table.XCellCursor xCursor =
(com.sun.star.table.XCellCursor) UnoRuntime.queryInterface(
com.sun.star.table.XCellCursor.class,
xSheetCellCursor);
//==========================//
// カーソルの先頭を返す
//==========================//
return xCursor.getCellByPosition(0, 0);
}
}
|