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
getCellByPosition Java
Moderator: Moderatoren
getCellByPosition Java
Hallo nochmal,
der Code
----- code
xCursor.gotoNext();
xCursor.getCellByPosition( 0,0 ).setFormula(addressModel_in.getName1());//'D3'
xCursor.gotoNext();
xCursor.getCellByPosition( 0,0 ).setFormula(addressModel_in.getName2());//'E3'
xCursor.gotoNext();
xCursor.getCellByPosition( 0,0 ).setFormula(addressModel_in.getStreet());//'F3'
---- code ende ---
funktioniert. Aber muss man wirklich den Cursor mit gotoNext weiterbewegen? Setzt nicht getCellByPosition den Cursor dahin, wo ich ihn gerne hin haben möchte?
Description zu getCellbyPosition sagt:
Returns a single cell within the range.
ist Range nicht das Spreadsheet, ausgehend von
xCursor.gotoEnd(); // cursor is in 'P2'
//Move down one row and left 13 columns
xCursor.gotoOffset(-13,1);//Cursor is in 'C3' ?
Gruß Gerd
der Code
----- code
xCursor.gotoNext();
xCursor.getCellByPosition( 0,0 ).setFormula(addressModel_in.getName1());//'D3'
xCursor.gotoNext();
xCursor.getCellByPosition( 0,0 ).setFormula(addressModel_in.getName2());//'E3'
xCursor.gotoNext();
xCursor.getCellByPosition( 0,0 ).setFormula(addressModel_in.getStreet());//'F3'
---- code ende ---
funktioniert. Aber muss man wirklich den Cursor mit gotoNext weiterbewegen? Setzt nicht getCellByPosition den Cursor dahin, wo ich ihn gerne hin haben möchte?
Description zu getCellbyPosition sagt:
Returns a single cell within the range.
ist Range nicht das Spreadsheet, ausgehend von
xCursor.gotoEnd(); // cursor is in 'P2'
//Move down one row and left 13 columns
xCursor.gotoOffset(-13,1);//Cursor is in 'C3' ?
Gruß Gerd
Hey Gerd,

Du kannst aber doch deinen xCursor frei im Tabellenobjekt bewegen...
Viele Grüße
Thomas
Ja. Das Cursorobjekt ist abgeleitet vom Controller und "weiss" absolut nichts von den umgebenden Zellen - es sei denn, du bewegst den Cursor direkt dorthinAber muss man wirklich den Cursor mit gotoNext weiterbewegen?

Nein. GetCellByPosition liefert dir ein Cellobjekt innerhalb einer gegebenen Range, und die könnte auch die komplete Tabelle sein, bei dir aber ist dies das CellCursor-Objekt - und das hat eben nur die Ausdehnung "eine Zelle".Setzt nicht getCellByPosition den Cursor dahin, wo ich ihn gerne hin haben möchte?
Du kannst aber doch deinen xCursor frei im Tabellenobjekt bewegen...
Viele Grüße
Thomas
Unterstützer LibreOffice, zertifizierter Trainer und Berater
Bücher: LibreOffice 6- Einstieg und Umstieg
Makros Grundlagen - LibreOffice / OpenOffice Basic
Bücher: LibreOffice 6- Einstieg und Umstieg
Makros Grundlagen - LibreOffice / OpenOffice Basic