Issue 73094 - Runtime error when loading Calc template with simple Basic code
Summary: Runtime error when loading Calc template with simple Basic code
Status: CLOSED NOT_AN_OOO_ISSUE
Alias: None
Product: App Dev
Classification: Unclassified
Component: api (show other issues)
Version: 3.3.0 or older (OOo)
Hardware: All Windows, all
: P3 Trivial
Target Milestone: ---
Assignee: jsc
QA Contact: issues@api
URL: http://www.oooforum.org/forum/viewtop...
Keywords:
Depends on:
Blocks:
 
Reported: 2007-01-03 21:05 UTC by aziem
Modified: 2013-02-24 21:08 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments
test document (11.84 KB, application/vnd.oasis.opendocument.spreadsheet)
2007-01-03 22:29 UTC, aziem
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
Description aziem 2007-01-03 21:05:08 UTC
I found a way to display the name of the current sheet

 function GetSheetName()
 GetSheetName = ThisComponent.getCurrentController.getActiveSheet.getName()
 end function

However, if I call GetSheetName() in a formula, save it as a template (.ots),
and open it, I get an error

 BASIC runtime error.
 An exception occurred.
 Type: com.sun.star.lang.DisposedException
 Message: .

The error happens on my Windows XP and OOo 2.1, but there is no error with my
Linux and OOo 2.1.
Comment 1 aziem 2007-01-03 22:29:00 UTC
Created attachment 41869 [details]
test document
Comment 2 jsc 2007-01-09 12:46:49 UTC
jsc -> as: can you take a look on it. Seems that ThisComponent returns different
values or is not initialized in the same way. Timing issue!
Or do you have a different idea how to solve. 

StarDesktop.getCurrentComponent.getCurrentController.getActiveSheet.getName()
won't work as well
Comment 3 andreas.schluens 2007-01-09 14:50:22 UTC
AS->JSC: As discussed with you ... seams to be a problem of calc itself.
getActiveSheet() is not valid during loading of documents based on templates.
Comment 4 jsc 2007-01-09 15:03:57 UTC
accepted
Comment 5 jsc 2007-01-09 16:02:11 UTC
Using getActiveSheet won't work anyway in your scenario if you would have more
than one sheet. The function is calculated during the load process. What should
active sheet be in this case?
Be careful with getCurrentComponent, getCurrentControler or for example
getActiveSheet. Think about the semantic of these functions ;-)

Solution:
change your macro to 

function GetSheetName(sheetnumber as Integer)
	msgbox sheetnumber
	GetSheetName = ThisComponent.getSheets().getByIndex(sheetnumber-1).Name
end function

use a parameter to reference the sheet where you call the function!!! In the
document you can simply use

=getSheetName(Sheet(a1))

I hope this helps
Comment 6 jsc 2007-01-15 09:42:54 UTC
closed