Hello,
Several questions --
1. How do I get the number of sheets in a spreadsheet in Python. I would like to loop thru them??
2. How do I test if a named range exists. eg. I want to see if START_DATE is defined?? What happens if getCellRangeByName gets an undefined range name??
3. How do I detemine the current calculate mode using python.
4. How do I recalc using python.
Thanks,
Saleem
Python Commands
Python Commands
OpenOffice 3.4.0
Mac OS X 10.5.8
Mac OS X 10.5.8
Re: Python Commands
Hello
Karolus
Code: Select all
context = XSCRIPTCONTEXT
#1. Question
def sheetscount()
doc = context.getDocument()
return doc.Sheets.Count
#2. Question
def name_exists( rangename ):
doc = context.getDocument()
if rangename in doc.NamedRanges.getElementNames():
#do something
# 3. what do you mean by 'Calculate-mode' ??
# 4. Question
def calculate_all():
doc = context.getDocument()
doc.calculateAll()
# general: Use Mri for Introspection, and you don't need ask these Questions
Karolus
Libreoffice 25.2… on Debian 13 (trixie) (on RaspberryPI5)
Libreoffice 25.8… flatpak on Debian 13 (trixie) (on RaspberryPI5)
Libreoffice 25.8… flatpak on Debian 13 (trixie) (on RaspberryPI5)
Re: Python Commands
OpenOffice 3.4.0
Mac OS X 10.5.8
Mac OS X 10.5.8
Re: Python Commands
MRI http://extensions.services.openoffice.org/project/MRI allows you to see the properties and methods of UNO objects. It is extremely valuable when writing macros. For example, here is MRI's list of properties of the doc object from Karlous's code. You can see the NamedRanges and Sheets properties used in the code
Code: Select all
(Name) (Value Type) (Value) (Info.) (Attr.) (Handle)
ActionLocks short Pseud WriteOnly
AllowMacroExecution boolean True Attr. Read_Only
ApplyFormDesignMode boolean False 0
AreaLinks .sheet.XAreaLinks -INTERFACE- 0
Args [].beans.PropertyValue -Sequence- Pseud Read_Only
AutomaticControlFocus boolean False 0
AvailableServiceNames []string -Sequence- Pseud Read_Only
AvailableViewControllerNames []string -Sequence- Pseud Read_Only
BasicLibraries .script.XLibraryContainer -INTERFACE- Read_Only 0
BuildId string "" 0
CalcAsShown boolean False 1
CharLocale .lang.Locale -STRUCT- 0
CharLocaleAsian .lang.Locale -STRUCT- 0
CharLocaleComplex .lang.Locale -STRUCT- 0
CodeName string "" 0
ColumnLabelRanges .sheet.XLabelRanges -INTERFACE- 0
Controllers .container.XEnumeration -INTERFACE- Pseud Read_Only
CurrentController .frame.XController -INTERFACE- Pseud
CurrentSelection .uno.XInterface -INTERFACE- Pseud Read_Only
DDELinks .container.XNameAccess -INTERFACE- 0
DatabaseRanges .sheet.XDatabaseRanges -INTERFACE- 0
DefaultTabStop short 720 2
Delegator .uno.XInterface Pseud WriteOnly
DialogLibraries .script.XLibraryContainer -INTERFACE- Read_Only 0
DocumentInfo .document.XDocumentInfo -INTERFACE- Pseud Read_Only
DocumentProperties .document.XDocumentProperties -INTERFACE- Pseud Read_Only
DocumentStorage .embed.XStorage -INTERFACE- Pseud Read_Only
DocumentSubStoragesNames []string -Sequence- Pseud Read_Only
DrawPages .drawing.XDrawPages -INTERFACE- Pseud Read_Only
Events .container.XNameReplace -INTERFACE- Pseud Read_Only
ExternalDocLinks .sheet.XExternalDocLinks -INTERFACE- 0
ForbiddenCharacters .i18n.XForbiddenCharacters -INTERFACE- Read_Only 0
HasDrawPages boolean True Read_Only 0
HasValidSignatures boolean False Read_Only 0
Identifier string com.sun.star.sh... Pseud
IgnoreCase boolean False 3
ImplementationId []byte -SEQUENCE- Pseud Read_Only
ImplementationName string ScModelObj Pseud Read_Only
IsAdjustHeightEnabled boolean True 0
IsChangeReadOnlyEnabled boolean False 0
IsExecuteLinkEnabled boolean True 0
IsIterationEnabled boolean False 4
IsLoaded boolean True 0
IsUndoEnabled boolean True 0
IterationCount long 100 5
IterationEpsilon double 0.001 6
LibraryContainer .container.XNameContainer -INTERFACE- Pseud Read_Only
Links .container.XNameAccess -INTERFACE- Pseud Read_Only
LocalName string "" Attr. Read_Only
Location string "" Pseud Read_Only
LookUpLabels boolean True 7
MatchWholeCell boolean True 8
Modified boolean Ignored
NamedRanges .sheet.XNamedRanges -INTERFACE- 0
Namespace string vnd.sun.star.td... Attr. Read_Only
NullDate .util.Date -STRUCT- 9
NumberFormatSettings .beans.XPropertySet -INTERFACE- Pseud Read_Only
NumberFormats .util.XNumberFormats -INTERFACE- Pseud Read_Only
Parent .uno.XInterface -void- Pseud
Printer [].beans.PropertyValue Ignored
PropertySetInfo .beans.XPropertySetInfo -INTERFACE- Pseud Read_Only
RDFRepository .rdf.XRepository -INTERFACE- Pseud Read_Only
ReferenceDevice .awt.XDevice -INTERFACE- Read_Only 0
RegularExpressions boolean True 12
RowLabelRanges .sheet.XLabelRanges -INTERFACE- 0
RuntimeUID string 9 Read_Only 0
ScriptContainer .document.XEmbeddedScripts -INTERFACE- Attr. Read_Only
ScriptProvider .script.provider.XScriptProvider -INTERFACE- Pseud Read_Only
SheetLinks .container.XNameAccess -INTERFACE- 0
Sheets .sheet.XSpreadsheets -INTERFACE- Pseud Read_Only
SpellOnline boolean True 10
StandardDecimals short -1 11
StringValue string vnd.sun.star.td... Attr. Read_Only
StyleFamilies .container.XNameAccess -INTERFACE- Pseud Read_Only
SupportedServiceNames []string -Sequence- Pseud Read_Only
Title string Untitled 3 Pseud
TransferDataFlavors [].datatransfer.DataFlavor -Sequence- Pseud Read_Only
Types []type -Sequence- Pseud Read_Only
UIConfigurationManager .ui.XUIConfigurationManager Ignored Read_Only
URL string "" Pseud Read_Only
UntitledPrefix string : Pseud Read_Only
ViewData .container.XIndexAccess -INTERFACE- Pseud
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.