getCellByPosition Java

Antwort erstellen


BBCode ist eingeschaltet
[img] ist ausgeschaltet
[url] ist eingeschaltet
Smileys sind ausgeschaltet

Die letzten Beiträge des Themas
   

Ansicht erweitern Die letzten Beiträge des Themas: getCellByPosition Java

von gschuckar » Mo, 12.02.2007 15:56

Hallo Rainer, hallo Thomas,
es ist zwar schon einige Zeit vergangen. Aber : Danke für die Hinweise. Ich hatte da wohl einiges aus dem dev Guide falsch verstanden.
jSo gehts. Jetzt gibs aber eine neues Verständnissproblem. Dazu ein neues Thema
Gruß Gerd

von Toxitom » Mo, 12.02.2007 11:09

Hey Gerd,
Aber muss man wirklich den Cursor mit gotoNext weiterbewegen?
Ja. Das Cursorobjekt ist abgeleitet vom Controller und "weiss" absolut nichts von den umgebenden Zellen - es sei denn, du bewegst den Cursor direkt dorthin ;-)
Setzt nicht getCellByPosition den Cursor dahin, wo ich ihn gerne hin haben möchte?
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".
Du kannst aber doch deinen xCursor frei im Tabellenobjekt bewegen...

Viele Grüße
Thomas

von Eckhardt » Mo, 12.02.2007 08:53

Hallo gschuckar,
ich bin zwar kein JAVA-Spezialist; ich würde aber sagen, dass die Codezeile "xCellRange = xSheet.getCellRangeByName("A1");" das CellRange-Objekt auf die Zelle A1 begrenzt; somit ist die Fehlermeldung berechtigt.

getCellByPosition Java

von gschuckar » Di, 06.02.2007 10:47

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

getCellByPosition Java

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

Nach oben