von gschuckar » Di, 06.02.2007 10:07
Moin,
mit der folgenden Java Methode möchte ich Adressdaten in ein Spreadsheet eintragen:
-----Code -----
public void insertAddress(AddressModel addressModel_in) throws RuntimeException, Exception {
com.sun.star.sheet.XSpreadsheet xSheet = getSpreadsheet("Kunden");
com.sun.star.table.XCell xCell = null;
com.sun.star.table.XCellRange xCellRange = null;
// find the end of filled spreadsheet and move cursor
xCellRange = xSheet.getCellRangeByName("A1");
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 =
xSheet.createCursorByRange(xSheetCellRange);
com.sun.star.table.XCellCursor xCursor = (com.sun.star.table.XCellCursor)UnoRuntime.queryInterface(
com.sun.star.table.XCellCursor.class, xSheetCellCursor);
//Move to the last filled cell
xCursor.gotoEnd(); // cursor is in 'P2'
//Move down one row and left 13 columns
xCursor.gotoOffset(-13,1);//Cursor is in 'C3'
xCursor.getCellByPosition( 0,0 ).setFormula(addressModel_in.getAnrede());
// 5.2.2007
// the following position wouldn't found. Here caught an error. Why?
xCursor.getCellByPosition( 1,0 ).setFormula(addressModel_in.getName1());//'D3'
xCursor.getCellByPosition( 2,0 ).setFormula(addressModel_in.getName2());//'E3'
xCursor.getCellByPosition( 3,0 ).setFormula(addressModel_in.getStreet());//'F3'
//speichere Document
}// done newAddress
--- code ende ---
Der ertse Wert wird mit xCursor.getCellByPosition( 0,0 ).setFormula(addressModel_in.getAnrede()); auch korrekt eingetragen.
Die Zeile xCursor.getCellByPosition( 1,0 ).setFormula(addressModel_in.getName1());//'D3' lässt folgende Exception entstehen:
com.sun.star.lang.IndexOutOfBoundsException:
at com.sun.star.lib.uno.environments.remote.Job.remoteUnoRequestRaisedException(Job.java)
at com.sun.star.lib.uno.environments.remote.Job.execute(Job.java)
at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java)
at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java)
at com.sun.star.lib.uno.environments.remote.JavaThreadPool.enter(JavaThreadPool.java)
at com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge.sendRequest(java_remote_bridge.java)
at com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge.sendRequest(java_remote_bridge.java)
at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.request(ProxyFactory.java)
at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.invoke(ProxyFactory.java)
at $Proxy11.getCellByPosition(Unknown Source)
Muss ich jedes getCellByPosition irgendwie anders einleiten? Was übersehe ich denn hier?
Gruß Gerd
Moin,
mit der folgenden Java Methode möchte ich Adressdaten in ein Spreadsheet eintragen:
-----Code -----
public void insertAddress(AddressModel addressModel_in) throws RuntimeException, Exception {
com.sun.star.sheet.XSpreadsheet xSheet = getSpreadsheet("Kunden");
com.sun.star.table.XCell xCell = null;
com.sun.star.table.XCellRange xCellRange = null;
// find the end of filled spreadsheet and move cursor
xCellRange = xSheet.getCellRangeByName("A1");
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 =
xSheet.createCursorByRange(xSheetCellRange);
com.sun.star.table.XCellCursor xCursor = (com.sun.star.table.XCellCursor)UnoRuntime.queryInterface(
com.sun.star.table.XCellCursor.class, xSheetCellCursor);
//Move to the last filled cell
xCursor.gotoEnd(); // cursor is in 'P2'
//Move down one row and left 13 columns
xCursor.gotoOffset(-13,1);//Cursor is in 'C3'
xCursor.getCellByPosition( 0,0 ).setFormula(addressModel_in.getAnrede());
// 5.2.2007
// the following position wouldn't found. Here caught an error. Why?
xCursor.getCellByPosition( 1,0 ).setFormula(addressModel_in.getName1());//'D3'
xCursor.getCellByPosition( 2,0 ).setFormula(addressModel_in.getName2());//'E3'
xCursor.getCellByPosition( 3,0 ).setFormula(addressModel_in.getStreet());//'F3'
//speichere Document
}// done newAddress
--- code ende ---
Der ertse Wert wird mit xCursor.getCellByPosition( 0,0 ).setFormula(addressModel_in.getAnrede()); auch korrekt eingetragen.
Die Zeile xCursor.getCellByPosition( 1,0 ).setFormula(addressModel_in.getName1());//'D3' lässt folgende Exception entstehen:
com.sun.star.lang.IndexOutOfBoundsException:
at com.sun.star.lib.uno.environments.remote.Job.remoteUnoRequestRaisedException(Job.java)
at com.sun.star.lib.uno.environments.remote.Job.execute(Job.java)
at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java)
at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java)
at com.sun.star.lib.uno.environments.remote.JavaThreadPool.enter(JavaThreadPool.java)
at com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge.sendRequest(java_remote_bridge.java)
at com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge.sendRequest(java_remote_bridge.java)
at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.request(ProxyFactory.java)
at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.invoke(ProxyFactory.java)
at $Proxy11.getCellByPosition(Unknown Source)
Muss ich jedes getCellByPosition irgendwie anders einleiten? Was übersehe ich denn hier?
Gruß Gerd