Re: [api-dev] Calc with two tables
If I understand correctly, you have solved the problem. Excellent! Rudolf Huber wrote: Hallo Andrew, thanks again for your kind response. I have to code for each sheet an extra definition between oTabellenListe = oTabellenDokument.getSheets() and Tabelle11 = oTabellenListe.GetByIndex(0) and thereafter Tabelle31 = oTabellenListe.GetByIndex(1). The additional code looks this: If TabellenListe.hasByName("Tabellen1") Then oTabellenListe.copyByName("Tabelle1", "Tabelle11", 1) Rem for the Copy EndIf If TabellenListe.hasByName("Tabellen31") Then Tabelle1 = oTabellenListe.getByName("Tabelle31") MsgBox "Tabelle31 found" else Tabelle1 = oTabellenDokument.createInstance("com.sun.star.sheet.Spreadsheet") oTabellenListe.insertByName("Tabelle31", "Tabelle1") Rem for the new sheet EndIf Yesterday, I found the solution after searching the internet again and again. You have to see, I have a problem: I am close to 70 years of age. Therefore, it takes a while until I get the point. I really appreciate help in this matter. Have I nice week. Thank you again. Rudi - Original Message - From: "Andrew Douglas Pitonyak" To: Sent: Saturday, December 13, 2008 2:48 AM Subject: Re: [api-dev] Calc with two tables Rudolf Huber wrote: Halle Andrew, again thank you for your answer. I got twice the answer 1 for the printing calls. I interpret this that I have two sheets, namely sheet 0 and sheet 1. A count of 1 means that you have one sheet, and the index of the first sheet is zero. The point is, if the count is 1, then you can not obtain the sheet at index 1. As long as I had oo0 2.0, I had no problem. I handled 10 tables in one macro. On the bottom of the sheet, where I had the sheets-numbers, I always got the correct sheet numbers. Now, I use ooO 3.0, and I suddenly have problems. I assume that something else is happening. I noticed some changes with respect to how a sheet was loaded, and when a call might return, and what the reference to the "loaded" document might be. My mind is vague on this, however, and I never gave it much thought, at least not for a while anyway How long after the document is loaded, do you try to access the sheets? what happens if you add a delay? In our example I declare the sheets-numbers Tabelle11 and Tabelle31. As soon as I call the spreedsheet I get the sheet-number Tabelle1, which apparently is being generated by ooO. I see all the cells which I had typed when I created the table. After I call the macro, the routine goes to the point where I want to call Tabelle31. At that position I get the outofboundexception. The spreadsheet does not show either Tabelle11 or Tabelle31. The system acts as if I would have not called either Tabelle11 or Tabelle31. Here is the entire code. Hmm, now that is interesting. I can not make this code fail. Can you email me a copy of the referenced document? Option Explicit Sub Main Dim Desktop As Object Dim Platzhalter() Dim Url As String Dim oTabellenDokument As Object Dim oTabellenListe As Object Dim Tabelle11 As Object Dim Tabelle31 As Object Dim EndSpalte As Integer Dim EndZeile As Integer Dim I As Integer Dim Cursor As Object Dim ZellenBereich As New com.sun.star.table.CellRangeAddress Dim ZellenAdresse As New com.sun.star.table.CellAddress ZellenBereich.Sheet = 0 ZellenBereich.StartColumn = 0 ZellenBereich.EndColumn = 30 ZellenBereich.StartRow = 0 ZellenBereich.EndRow = 300 ZellenAdresse.Sheet = 0 ZellenAdresse.Column = 0 ZellenAdresse.Row = 0 EndSpalte = ZellenBereich.EndColumn EndZeile = ZellenBereich.EndRow In this next line, you assign to the current document, I would not do that without checking the document type and such. oTabellenDokument = ThisComponent rem oTabellenDokument.LockControllers Desktop = CreateUnoService("com.sun.star.frame.Desktop") Url = "file:///a:/mist.ods" oTabellenDokument = Desktop.loadComponentFromURL(Url, "_blank", 0, Platzhalter()) What happens if you place a print statement here. Print "hello", for example. The only purpose is to give the document time to load. I assume that the loaded document does NOT call a macro when it starts (or anything similar). oTabellenListe = oTabellenDokument.getSheets() Tabelle11 = oTabellenListe.GetByIndex(0) Tabelle31 = oTabellenListe.GetByIndex(1) End Sub You question, I I reference the correct document. I run the macro with break-points. The only point where I am nor sure of are the LockControllers and CurrentController statements. I declared them both, for the cell-area ("Zellenbereich") and the entire document. I also tried getByName instead of getByIndex. I got the same outofboundexception.. I really appreciate your help. Regards, Rudi - Orig
Re: [api-dev] Calc with two tables
Hallo Andrew, thanks again for your kind response. I have to code for each sheet an extra definition between oTabellenListe = oTabellenDokument.getSheets() and Tabelle11 = oTabellenListe.GetByIndex(0) and thereafter Tabelle31 = oTabellenListe.GetByIndex(1). The additional code looks this: If TabellenListe.hasByName("Tabellen1") Then oTabellenListe.copyByName("Tabelle1", "Tabelle11", 1) Rem for the Copy EndIf If TabellenListe.hasByName("Tabellen31") Then Tabelle1 = oTabellenListe.getByName("Tabelle31") MsgBox "Tabelle31 found" else Tabelle1 = oTabellenDokument.createInstance("com.sun.star.sheet.Spreadsheet") oTabellenListe.insertByName("Tabelle31", "Tabelle1") Rem for the new sheet EndIf Yesterday, I found the solution after searching the internet again and again. You have to see, I have a problem: I am close to 70 years of age. Therefore, it takes a while until I get the point. I really appreciate help in this matter. Have I nice week. Thank you again. Rudi - Original Message - From: "Andrew Douglas Pitonyak" To: Sent: Saturday, December 13, 2008 2:48 AM Subject: Re: [api-dev] Calc with two tables Rudolf Huber wrote: Halle Andrew, again thank you for your answer. I got twice the answer 1 for the printing calls. I interpret this that I have two sheets, namely sheet 0 and sheet 1. A count of 1 means that you have one sheet, and the index of the first sheet is zero. The point is, if the count is 1, then you can not obtain the sheet at index 1. As long as I had oo0 2.0, I had no problem. I handled 10 tables in one macro. On the bottom of the sheet, where I had the sheets-numbers, I always got the correct sheet numbers. Now, I use ooO 3.0, and I suddenly have problems. I assume that something else is happening. I noticed some changes with respect to how a sheet was loaded, and when a call might return, and what the reference to the "loaded" document might be. My mind is vague on this, however, and I never gave it much thought, at least not for a while anyway How long after the document is loaded, do you try to access the sheets? what happens if you add a delay? In our example I declare the sheets-numbers Tabelle11 and Tabelle31. As soon as I call the spreedsheet I get the sheet-number Tabelle1, which apparently is being generated by ooO. I see all the cells which I had typed when I created the table. After I call the macro, the routine goes to the point where I want to call Tabelle31. At that position I get the outofboundexception. The spreadsheet does not show either Tabelle11 or Tabelle31. The system acts as if I would have not called either Tabelle11 or Tabelle31. Here is the entire code. Hmm, now that is interesting. I can not make this code fail. Can you email me a copy of the referenced document? Option Explicit Sub Main Dim Desktop As Object Dim Platzhalter() Dim Url As String Dim oTabellenDokument As Object Dim oTabellenListe As Object Dim Tabelle11 As Object Dim Tabelle31 As Object Dim EndSpalte As Integer Dim EndZeile As Integer Dim I As Integer Dim Cursor As Object Dim ZellenBereich As New com.sun.star.table.CellRangeAddress Dim ZellenAdresse As New com.sun.star.table.CellAddress ZellenBereich.Sheet = 0 ZellenBereich.StartColumn = 0 ZellenBereich.EndColumn = 30 ZellenBereich.StartRow = 0 ZellenBereich.EndRow = 300 ZellenAdresse.Sheet = 0 ZellenAdresse.Column = 0 ZellenAdresse.Row = 0 EndSpalte = ZellenBereich.EndColumn EndZeile = ZellenBereich.EndRow In this next line, you assign to the current document, I would not do that without checking the document type and such. oTabellenDokument = ThisComponent rem oTabellenDokument.LockControllers Desktop = CreateUnoService("com.sun.star.frame.Desktop") Url = "file:///a:/mist.ods" oTabellenDokument = Desktop.loadComponentFromURL(Url, "_blank", 0, Platzhalter()) What happens if you place a print statement here. Print "hello", for example. The only purpose is to give the document time to load. I assume that the loaded document does NOT call a macro when it starts (or anything similar). oTabellenListe = oTabellenDokument.getSheets() Tabelle11 = oTabellenListe.GetByIndex(0) Tabelle31 = oTabellenListe.GetByIndex(1) End Sub You question, I I reference the correct document. I run the macro with break-points. The only point where I am nor sure of are the LockControllers and CurrentController statements. I declared them both, for the cell-area ("Zellenbereich") and the entire document. I also tried getByName instead of getByIndex. I got the same outofboundexception.. I really appreciate your help. Regards, Rudi - Original Message - From: "Andrew Douglas Pitonyak" To: Sent: Sunday, December 07, 2008 7:36 P