BITTE helfen Sie uns HEUTE mit einer SPENDE
Das LibreOffice Forum braucht jetzt Ihre Hilfe!

❤️ DANKE >><< DANKE ❤️

> KEINE WERBUNG FÜR REGISTRIERTE BENUTZER!<
Ihre Spende wird für die Deckung der laufenden Kosten sowie den Ausbau 🌱 des LibreOffice Forums verwendet.
🤗 Als Dankeschön werden Sie im Forum als LO-SUPPORTER gekennzeichnet. 🤗

Projekt datasurfer, praktisches Makro zum Filtern, Merkwürdigkeiten

Alles zur Programmierung im LibreOffice.
Wanderer
Beiträge: 895
Registriert: Di 11. Feb 2014, 20:03
Wohnort: Berlin

Re: Projekt datasurfer, praktisches Makro zum Filtern, Merkwürdigkeiten

Beitrag von Wanderer » Do 12. Apr 2018, 09:25

newbie-01 hat geschrieben:
Do 12. Apr 2018, 08:43
trotzdem wundere ich mich manchmal, und hilft es mir manchmal das aufzuschreiben, und mag es manchmal anderen leuten helfen sich zu orientieren.
genau das funktioniert nicht. Dieser Tread ist ein Beispiel wie man es nicht machen sollte.
Haufenweise Themen in denen man eventuell mal eine Antwort findet, meist aber nur Theorien und zuviel Geschwafel.
Daher die Empfehlung in den meisten Foren:
Ein Thread pro konkrete Frage und vernünftige Titel.
Wenn Du Datumsprobleme googelst, würdest Du eine vernünftige Antwort in
Projekt datasurfer, praktisches Makro zum Filtern, Merkwürdigkeiten erwarten? Das liest nach uns keiner mehr...
newbie-01 hat geschrieben:
Do 12. Apr 2018, 08:43
... finger hoch und ehrlich sein ... wer hatte es gewusst? und warum hat man es mir nicht gleich gesagt sondern versucht es auf 'sonstige abweichungen' zu schieben?
Könnte an deinem Fragestil liegen - wie schrieb mal jemand "da fehlt wohl die höhere Aufsicht".
Empfehlung: Frag die Dinge bei denen man Dir helfen kann und vermeide alle Programmierer für Deppen zu erklären.
Die Leute die hier schreiben kennen zwar je nach Spezialisierung viele der Probleme, haben Sie aber nicht verursacht
und sind auch nicht die Programmentwickler.
Und ganz nebenbei: Wir machen das hier alle freiwillig und ohne Bezahlung, daher dürfen wir entscheiden wem "wir" helfen.

Ich halte die fehlende Aufsicht übrigens für ein Zeichen von Freiheit.

mfg, Jörn
LO 6.0.7 (32Bit) Win8.1 Pro 32 Bit/ LO 6.3.2 Win10 64Bit / LO 6.0.7 Win7 Pro 64 Bit

newbie-01
Beiträge: 19
Registriert: Mo 2. Apr 2018, 07:21

Re: Projekt datasurfer, praktisches Makro zum Filtern, Merkwürdigkeiten

Beitrag von newbie-01 » Do 12. Apr 2018, 09:50

hi,

wenn ich die lösungen kennte bevor ich frage würde ich sie einfach aufschreiben,

provozieren kann ich scheinbar gut, auch wenn ich es garnicht will,

sinnvoll wäre ... nach dem geschwafel eine sammlung mit belastbaren ergebnissen anzulegen und suchen darauf einzugrenzen,

ist aber im real existierenden www genausowenig vorgesehen wie z.b. alle beiträge mit datum zu versehen,

ich habe nicht! 'alle' programmierer für deppen erklärt, selbst wenn viele solches wären sind mitlesende und mithelfende natürlich immer ausgenommen,

so leid mir das geschwafel tut, aus meiner sicht sind! in diesem thread mehrere wichtige? fragestellungen geklärt oder vorangebracht worden, nicht auf 'forenüblichem weg', aber relativ effektiv ... aus meiner subjektiven sicht unterscheidet ihn das von vielen anderen, und aus meiner subjektiven sicht ist es richtig uns im weiteren auf 'die sache' zu konzentrieren ... soweit ich davon abgewichen bin übe ich selbstkritik und bitte um entschuldigung, an diskussionen um form oder sinn werde ich nicht mehr mitarbeiten

b.

Wanderer
Beiträge: 895
Registriert: Di 11. Feb 2014, 20:03
Wohnort: Berlin

Re: Projekt datasurfer, praktisches Makro zum Filtern, Merkwürdigkeiten

Beitrag von Wanderer » Sa 14. Apr 2018, 21:37

newbie-01 hat geschrieben:
Do 12. Apr 2018, 09:50
provozieren kann ich scheinbar gut, auch wenn ich es garnicht will,

sinnvoll wäre ... nach dem geschwafel eine sammlung mit belastbaren ergebnissen anzulegen und suchen darauf einzugrenzen,

ist aber im real existierenden www genausowenig vorgesehen wie z.b. alle beiträge mit datum zu versehen,
Hallo,
auf http://de.openoffice.info/index.php findest Du einen FAQ-Bereich und ein Wissensarchiv.
Google bietet durchaus Möglichkeiten die Suche auf eine Webseite oder spezielle URLs zu beschränken.
Was Deinen Einwand zum Datum angeht, kann ich Dir wohl nicht helfen, wenn Dir die hiesige Datierung nicht reicht.

MfG, Jörn
LO 6.0.7 (32Bit) Win8.1 Pro 32 Bit/ LO 6.3.2 Win10 64Bit / LO 6.0.7 Win7 Pro 64 Bit

newbie-01
Beiträge: 19
Registriert: Mo 2. Apr 2018, 07:21

Re: Projekt datasurfer, praktisches Makro zum Filtern, Merkwürdigkeiten

Beitrag von newbie-01 » Di 17. Apr 2018, 08:09

hi,

nochmal zur Sache:

die untenstehende Version des macros funktioniert schon ziemlich gut und weitgehend allgemeingültig,

ist aber leider nur 'evolutionär erärgert' (netterer Ausdruck für trial and error) und damit weder vollständig noch 'schön'.

sie enthält aber viele - alle? - Hilfsmittelchen und Werkzeuge um das Thema zu erledigen.

hat vielleicht jemand mit fundierten Kenntnissen in calc-makroprogrammierung Zeit und Lust das aufzuhübschen?

Wäre toll.

Code: Alles auswählen

sub datasurfer

' this macro will filter the actual column in a database range 
' with 'autofilter' to the value of the actual cell, while 
' leaving the filtering for the other columns untouched. 
'
' the only requirement is that you have a 'database range' defined 
' in the table under <data - define range>, and that the 'focus' 
' - the actual cell - is within that range. 
'
' remaining problems: 
' shorten the code, 
' clear handling of different types of fields, 
' comment code, 
'
' abbreviations: 
	oDoc     = ThisComponent
	oControl = oDoc.CurrentController
	oSheet   = oControl.getActiveSheet
	oCell    = oDoc.getCurrentSelection
	
'variables and values
	Row     = oCell.CellAddress.Row
	Column  = oCell.CellAddress.Column
	Content_v = oCell.value
	content_s = ocell.string
' numeric values will be abbreviated to their display format for the string-value
' thus it's better to handle them as .values
''	if isnumeric(content) then content = ocell.value
' isnumeric will fail for "0,0", filtering for "0,0" will fail for cells with '0' values
''    if content = "0,0" then content = "0"
' some date formats do need interpretation, some are 'misunderstandable', 
' to prevent errors here is some special handling for special formats
' JJ-MM-TT (or YY-MM-DD) is a candidate for errors, it's 'numberformat' is 83
'Standard
'there are two sections for handling of special formattings in the macro, 
'that' due to trial and error evolution and should be changed ... 
'reformat date strings: 
	if ocell.numberformat = 30 and len(content_s) = 8 then content_s = "20"&right(content_s,2)&"-"&mid(content_s,4,2)&"-"&left(content_s,2)
	if ocell.numberformat = 37 and content_s <> "" then content_s = "20"&right(content_s,2)&"-"&mid(content_s,4,2)&"-"&left(content_s,2)
	if ocell.numberformat = 82 and content_s <> "" then content_s = "2018-"&content_s
	if ocell.numberformat = 83 and content_s <> "" then content_s = "20"&content_s

'  this search is not neccessary in most cases, but keeps us universal
	' lookup if the actual cell is within a database range 
	oDBRanges = oDoc.DatabaseRanges
	for i = 0 to oDBRanges.Count-1
	    oDBrange   = oDBRanges.getByIndex(i)
	    oCellrange = oDbrange.ReferredCells
	    if oCellrange.queryIntersection(oCell.RangeAddress).Count > 0 then
	        oRange = oDBrange
	    End If
	next
	
' add a messagebox for errors, 
	if isempty(oRange) then msgbox "actual cell not within a database range",0,""
	if isempty(oRange) then exit sub
		
    ' take actual value as filter criteria
    actor() = com.sun.star.sheet.FilterOperator.EQUAL
' handling of empty cells, they have special functionality in the drop-down-check-boxes, 
' was made with '.empty' by the original author, 
' it looks as if with LO 5.4.6.2 '.equal' and '""' do! work
' 'out-from-ori' if Content = "" then  actor() = com.sun.star.sheet.FilterOperator.EMPTY
    Dim oNeu As New com.sun.star.sheet.TableFilterField
    With oNeu
     .Field = Column - oRange.ReferredCells.RangeAddress.StartColumn  ' Filter-Spalte
' normally compare strings
     .IsNumeric = False
'special ahndling of special cases, should be more general!     
'case a number >0 in content_v
     if content_v and isnumeric(content_s) then .IsNumeric = True
'1,4
     if ocell.numberformat = 4 and content_s <> "" and isnumeric(content_s) then .IsNumeric = True
     if ocell.numberformat = 30 and content_s <> "" and isdate(content_s) then .IsNumeric = True
'     if ocell.numberformat = 30 and len(content_s) = 8 then .isnumeric = true
'JJ.MM.TT
     if ocell.numberformat = 37 and content_s <> "" then .IsNumeric = True
     if ocell.numberformat = 82 and content_s <> "" and isnumeric(content_s) then .IsNumeric = True
     if ocell.numberformat = 83 and content_s <> ""  and isnumeric(content_s) then .IsNumeric = True
     if ocell.numberformat = 109 and content_s <> "" and isnumeric(content_s) then .IsNumeric = True
'85,25
     if ocell.numberformat = 118 and content_s <> "" and isnumeric(content_s) then .IsNumeric = True
'1,25 normaler textstring? 
     if ocell.numberformat = 121 and content_s <> "" and isnumeric(content_s) then .IsNumeric = True
'221,250
     if ocell.numberformat = 127 and content_s <> "" and isnumeric(content_s) then .IsNumeric = True
'07
     if ocell.numberformat = 131 and content_s <> "" and isnumeric(content_s) then .IsNumeric = True
'1,4
     if ocell.numberformat = 158 and content_s <> "" and isnumeric(content_s) then .IsNumeric = True
'11,550
     if ocell.numberformat = 159 and content_s <> "" and isnumeric(content_s) then .IsNumeric = True
     .numericvalue = content_v
     .StringValue = Content_s
     .Operator = actor
    End With

	' switch on autofilter
	oRange.AutoFilter = True

	' work through the filtering situation
	oFilterDesc = oRange.getFilterDescriptor()
	aFields()=oFilterDesc.getFilterFields
	n=-1
	Dim aFieldsNeu() As New com.sun.star.sheet.TableFilterField
	neu=true
	for i=0 to ubound(aFields())
		if oNeu.Field=aFields(i).Field then
			'Spalte wurde bereits gefiltert
			neu=false
		else
			n=n+1
			Redim Preserve aFieldsNeu(n)
			' also when afieldsneu is correctly set to .field = 2
			' the filtering is applied to column 8 in the first run
            ' it works better when the database range is commited 
            ' or autofilter is turned of and re-on before running the macro. 
			aFieldsNeu(n)=aFields(i)
		end if
	next
	if neu then
		n=n+1
		Redim Preserve aFieldsNeu(n)
		aFieldsNeu(n)=oNeu
	end if

    ' filtering
   	oFilterDesc.setFilterFields(aFieldsNeu())
   	oFilterDesc.ContainsHeader=true
    oRange.referredcells.filter(oFilterDesc)

End Sub
Dank für alle Hilfe (zur Sache, nicht zur Forenordnung),



newbie-01

An alle, die das LibreOffice-Forum nutzen:


Bitte beteiligen Sie sich mit 7 Euro pro Monat und helfen uns bei unserem Budget für das Jahr 2024.
Einfach per Kreditkarte oder PayPal.
Als Dankeschön werden Sie im Forum als LO-SUPPORTER gekennzeichnet.

❤️ Vielen lieben Dank für Ihre Unterstützung ❤️

Antworten