Page 1 sur 1

[Calc] fonctions pour la gestion des feuilles et zones

Publié : 02 oct. 2008 14:57
par Factooor
Une fonction qui permet de sélectionner une feuille et une zone .

Code : Tout sélectionner

Function SelectionCell(NomFeuille, arg )
	monDoc = Thiscomponent
 	monControleur = monDoc.currentController
    monControleur.ActiveSheet = monDoc.Sheets.getByName(NomFeuille)
    maFeuille = monControleur.ActiveSheet
    maCellule = maFeuille.getCellRangeByName(arg)
    monControleur.select(maCellule)

End Function
Une fonction qui permet de sélectionner une feuille.

Code : Tout sélectionner

Function ActivationFeuille(arg As String)

	monDoc = Thiscomponent
	lesFeuilles = monDoc.Sheets
	maFeuille = monDoc.currentController.activeSheet
	maFeuille = lesFeuilles.getbyName(arg)
	monDoc.currentController.activeSheet = maFeuille

End Function
Une fonction qui permet de sélectionner une zone dans la feuille courante.

Code : Tout sélectionner

Function ActivationZone(nomZone)

	monControlleur = Thiscomponent.currentController
	maFeuille = monControlleur.activeSheet
	position = maFeuille.getCellRangeByName(nomZone)
	monControlleur.select(position)

End Function
Stéphane

[Calc] Activation d'une feuille

Publié : 27 avr. 2009 21:56
par tytof4042
La fonction qui permet de sélectionner une feuille par Factoor en supreme de code

Code : Tout sélectionner

Function ActivationFeuille(arg As String)
       monDoc = Thiscomponent
       lesFeuilles = monDoc.Sheets
       maFeuille = monDoc.currentController.activeSheet
       maFeuille = lesFeuilles.getbyName(arg)
       monDoc.currentController.activeSheet = maFeuille
End Function
ma version "optimisée"....

Code : Tout sélectionner

FUNCTION ActivationFeuille(NomFeuille) as object
	monDocument = ThisComponent
	ActivationFeuille = monDocument.Sheets.getByName(NomFeuille)
	monDocument.CurrentController.ActiveSheet = ActivationFeuille
END FUNCTION

SUB Test
	ActivationFeuille("Feuille2")
END SUB

Re: [Calc] fonctions pour la gestion des feuilles et zones

Publié : 30 avr. 2009 21:04
par Alain de La Chaume
Bonsoir,
Ca vas être difficile de faire mieux ?
Euh, oui, peut-être... A condition, bien sûr, que cette version fonctionne...
Si Feuille2 est le nom de la feuille à activer, peut-être faudrait-il l'encadrer de doubles-quotes... Non ? 8)
Seconde condition pour que ça fonctionne : que la feuille "Feuille2" existe vraiment.

[Calc] Macros génériques pour la gestion des feuilles

Publié : 12 mars 2013 13:50
par CoachFab
Bonjour,

Je vous propose les macros suivantes que j'utilise dans calc pour la gestion des feuilles : copier, supprimer, afficher une feuille, supprimer différentes feuilles, protéger, déprotéger ....

Code : Tout sélectionner

REM  *****  BASIC  *****
Option Explicit
'-----------------------------------------------------------------------------------------------
'Série de fonctions sur la gestion des feuilles
'-----------------------------------------------------------------------------------------------
'Macro qui affiche la feuille passée en paramètre
'Suppr indique si on doit supprimer la feuille qui était active
'-----------------------------------------------------------------------------------------------
Sub RetourFeuille(Fretour as string, optional suppr as boolean)
Dim feuille as string, efface as boolean
If IsMissing(suppr) then
	efface=false
else
	efface=suppr
end if
feuille=NomActiveFeuille()
ActiverFeuille(Fretour)
if efface=true then 
	oDoc.Sheets.removeByName(feuille)
else
	CacheFeuille(feuille,false)
end if
FinSub()
end sub
'-----------------------------------------------------------------------------------------------
'Fonction qui vérifie l'existence d'une feuille
'return true si Ok
'return un message sinon
'-----------------------------------------------------------------------------------------------
Function IsFeuille(feuille as String, Optional Doc as Object) as Boolean
Dim oSheets as Object, oDoc as Object
If IsMissing(Doc) then 
	oDoc=ThisComponent
else 
	oDoc=Doc
end if
	oSheets=oDoc.Sheets
	if oSheets.hasByName(feuille) then
		IsFeuille=true
	else
		IsFeuille=false
	end if
end Function
'-------------------------------------------------------------------------------------
'Fonction qui retourne l'index d'une feuille
'-------------------------------------------------------------------------------------
Function IndexFeuille(feuille as String, Optional Doc as Object) as Integer
Dim Sheet as Object
If IsMissing(doc) then 
	Sheet=RetourneFeuille(feuille)
else
	Sheet=RetourneFeuille(feuille,Doc)
end if
	IndexFeuille=Sheet.RangeAddress.Sheet
end Function
'-----------------------------------------------------------------------------------------------
'Macro qui insère une feuille après la feuille donnée (ou la dernière)
'-------------------------------------------------------------------------------------
Sub InsereFeuille(feuille as String, Optional prec as String, Optional doc as Object)
Dim Sheets as Object, index as Integer, oDoc as Object, nb as Long
If IsMissing(doc) then 
	oDoc=ThisComponent
else 
	oDoc=doc
end if
Sheets=oDoc.Sheets
'si la feuille précédente n'est pas donnée, on la met en dernier
If IsMissing(prec) then
	nb=Sheets.Count
	index=nb-1
else 
	index=IndexFeuille(prec,oDoc)
end if
	Sheets.insertNewByName(feuille,index+1)
end Sub
'-----------------------------------------------------------------------------------------------
'Macro qui copie (avec nouveau nom) et insère une feuille après la feuille donnée (ou la dernière)
'-------------------------------------------------------------------------------------
Sub CopieFeuille(feuille as String, Nom as String, Optional prec as String, Optional doc as Object)
Dim Sheets as Object, index as Integer, oDoc as Object, nb as Long
If IsMissing(doc) then 
	oDoc=ThisComponent
else 
	oDoc=doc
end if
Sheets=oDoc.Sheets
'si la feuille précédente n'est pas donnée, on la met en dernier
If IsMissing(prec) then
	nb=Sheets.Count
	index=nb-1
else 
	index=IndexFeuille(prec,oDoc)
end if
	Sheets.copyByName(feuille,Nom,index+1)
end Sub
'-----------------------------------------------------------------------------------------------
'Vérifie l'existence d'une feuille : retourne true ou false
'-------------------------------------------------------------------------------------
Function VerifFeuille(feuille as String, Optional doc as Object) as Boolean
Dim oDoc as Object
If IsMissing(doc) then
	oDoc=ThisComponent
else
	oDoc=doc
end if
if Isfeuille(feuille,oDoc) then
	VerifFeuille=true
else
	VerifFeuille=false
end if
end Function
'-------------------------------------------------------------------------------------
'Fonction qui retourne un objet Feuille si elle existe
'-------------------------------------------------------------------------------------
Function RetourneFeuille(feuille as string, Optional doc as Object) as Object
Dim oDoc as Object
If IsMissing(doc) then
	oDoc=ThisComponent
else 
	oDoc=doc
end if
if IsFeuille(feuille,oDoc)=true then
	RetourneFeuille=oDoc.Sheets.getByName(feuille)
end if
end Function
'-----------------------------------------------------------------------------------------------
'Supprime une feuille
'-----------------------------------------------------------------------------------------------
Sub SupprFeuille(feuille as String, Optional doc as Object)
Dim oDoc as Object
If IsMissing(doc) then
	oDoc=ThisComponent
else 
	oDoc=doc
end if
if IsFeuille(feuille,oDoc)=true then
	oDoc.Sheets.removeByName(feuille)
end if
end sub
'-------------------------------------------------------------------------------------
'Fonction qui retourne le nom feuille active
'-------------------------------------------------------------------------------------
Function NomActiveFeuille(Optional doc as Object) as String
Dim Sheet as Object, oDoc as Object
If IsMissing(doc) then
	oDoc=ThisComponent
else 
	oDoc=doc
end if
	Sheet=oDoc.CurrentController.ActiveSheet
	NomActiveFeuille=Sheet.Name
end Function
'-------------------------------------------------------------------------------------
'Rend active la feuille donnée
'-------------------------------------------------------------------------------------
Sub ActiverFeuille(feuille as String, Optional doc as Object)
Dim oSheet as Object, oDoc as Object
If IsMissing(doc) then
	oDoc=ThisComponent
else 
	oDoc=doc
end if
oSheet=RetourneFeuille(feuille,oDoc)
oDoc.CurrentController.ActiveSheet=oSheet
end Sub
'-----------------------------------------------------------------------------------------------
'macro pour protéger une feuille
'-----------------------------------------------------------------------------------------------
Sub ProtectFeuille(feuille as String, Optional doc as Object)
Dim oSheet as Object, oDoc as Object
If IsMissing(doc) then
	oDoc=ThisComponent
else 
	oDoc=doc
end if
oSheet=RetourneFeuille(feuille,oDoc)
oSheet.protect("passwordachanger")
End Sub
'-----------------------------------------------------------------------------------------------
'macro pour déprotéger une feuille
'-----------------------------------------------------------------------------------------------
Sub UnProtectFeuille(feuille as String, Optional doc as Object)
Dim oSheet as Object, oDoc as Object
If IsMissing(doc) then
	oDoc=ThisComponent
else 
	oDoc=doc
end if
oSheet=RetourneFeuille(feuille,oDoc)
oSheet.unprotect("passwordachanger")
End Sub
'-----------------------------------------------------------------------------------------------
Sub UnProtectFeuilleActive()
Dim feuille as string
feuille=NomActiveFeuille()
UnProtectFeuille(feuille)
MsgBox("Acompleter",64,"Information")
end sub
'-----------------------------------------------------------------------------------------------
'macro pour déprotéger toutes les feuilles
'-----------------------------------------------------------------------------------------------
Sub UnProtectAllFeuille(Optional doc as Object)
Dim oSheets as Object, oDoc as Object, nb as Integer, i as integer, oSheet as Object
If IsMissing(doc) then
	oDoc=ThisComponent
else 
	oDoc=doc
end if
nb=oDoc.Sheets.Count
oSheets=oDoc.Sheets
for i=0 to nb-1
	oSheet=RetourneFeuille(oSheets(i).Name,oDoc)
	oSheet.unprotect("passwordachanger")
next i

End Sub
'-----------------------------------------------------------------------------------------------
'macro pour protéger toutes les feuilles
'-----------------------------------------------------------------------------------------------
Sub ProtectAllFeuille(Optional doc as Object)
Dim oSheets as Object, oDoc as Object, nb as Integer, i as integer, oSheet as Object
If IsMissing(doc) then
	oDoc=ThisComponent
else 
	oDoc=doc
end if
nb=oDoc.Sheets.Count
oSheets=oDoc.Sheets
for i=0 to nb-1
	oSheet=RetourneFeuille(oSheets(i).Name,oDoc)
	oSheet.protect("passwordachanger")
next i

End Sub
'-----------------------------------------------------------------------------------------------
'macro pour cacher une feuille ou pas
'-----------------------------------------------------------------------------------------------
Sub CacheFeuille(feuille as String, val as boolean, Optional Doc as Object)
Dim oSheet as Object, oDoc as Object
If IsMissing(doc) then
	oDoc=ThisComponent
else 
	oDoc=doc
end if
oSheet=RetourneFeuille(feuille,oDoc)
oSheet.IsVisible=val
end sub
'-----------------------------------------------------------------------------------------------
'macro pour cacher toutes les feuille sauf celle en paramètre et active cette feuille
'-----------------------------------------------------------------------------------------------
Sub CacheAllFeuille(feuille as string,Optional Doc as Object)
Dim oSheet as Object, oDoc as Object, nb as integer, oSheets as object, i as integer
If IsMissing(doc) then
	oDoc=ThisComponent
else 
	oDoc=doc
end if
nb=oDoc.Sheets.Count
oSheets=oDoc.Sheets
ActiverFeuille(feuille)
CacheFeuille(feuille,true)
for i=0 to nb-1
	oSheet=RetourneFeuille(oSheets(i).Name,oDoc)
	if oSheets(i).Name<>feuille then oSheet.IsVisible=false
next i
end sub
'-----------------------------------------------------------------------------------------------
'macro pour afficher toutes les feuille sauf la premiere
'-----------------------------------------------------------------------------------------------
Sub AfficheAllFeuille(Optional Doc as Object)
Dim oSheet as Object, oDoc as Object, nb as integer, oSheets as object, i as integer
If IsMissing(doc) then
	oDoc=ThisComponent
else 
	oDoc=doc
end if
nb=oDoc.Sheets.Count
oSheets=oDoc.Sheets
for i=1 to nb-1
	oSheet=RetourneFeuille(oSheets(i).Name,oDoc)
	oSheet.IsVisible=true
next i
end sub
'-----------------------------------------------------------------------------------------------


Fabien
macros-cellules-feuilles.ods