md5 (oder andere hash-funktion) in calc

Das Tabellenkalkulationsprogramm

Moderator: Moderatoren

sk-am
Beiträge: 7
Registriert: Fr, 25.05.2012 13:19

md5 (oder andere hash-funktion) in calc

Beitrag von sk-am »

Hallo,

Gibt es in Calc sowas wie eine Funktion MD5(), die ich in eine Formel einbauen kann? Gerne auch irgendeine andere Hash-Funktion, oder eine Idee, wie ich sowas selber nachbauen könnte.
Weder die Hilfe noch Google konnten mir da weiterhelfen, aber vielleicht hat ja jemand eine Idee.

Danke schonmal
Karolus
********
Beiträge: 7440
Registriert: Mo, 02.01.2006 19:48

Re: md5 (oder andere hash-funktion) in calc

Beitrag von Karolus »

Hallo
Ich hab mal ge-google-d nach 'python hash md5', und nach 5 Minuten diese Python Funktion geschrieben:

Code: Alles auswählen

from hashlib import md5

def md_five( cellcontent ):
    return md5( '%s' % cellcontent ).hexdigest()
update für Kompatibilität mit LO4&& Python3.3

Code: Alles auswählen

from hashlib import md5
import sys
PY3 = (sys.version_info.major >= 3)
    
def md_five(cellcontent ):
    cellcontent = str(cellcontent)
    if PY3:
        cellcontent = cellcontent.encode('utf8') 
    return md5( cellcontent).hexdigest()
den Code speichern wir in einer Datei namens 'sheetFunction.py' in ~/Scripts/python/ im Benutzerconfigurationsverzeichnis.

Dann brauchen wir noch eine Basic-Schnittstelle in einem Modul der Standard-library mit dem Code:

Code: Alles auswählen

REM Keep a global reference to the ScriptProvider, since this stuff may be called many times:
Global g_MasterScriptProvider
REM Specify location of Python script, providing cell functions:
Const URL_Main = "vnd.sun.star.script:sheetFunction.py$"
Const URL_Args = "?language=Python&location=user"

Function getMasterScriptProvider()
   if NOT isObject(g_MasterScriptProvider) then
      oMasterScriptProviderFactory = createUnoService("com.sun.star.script.provider.MasterScriptProviderFactory")
      g_MasterScriptProvider = oMasterScriptProviderFactory.createScriptProvider("")
   endif
   getMasterScriptProvider = g_MasterScriptProvider
End Function

Function md_five( text )
   sURL = URL_Main & "md_five" & URL_Args
   oMSP = getMasterScriptProvider()
   oScript = oMSP.getScript(sURL)
   x = oScript.invoke( Array( text),Array(),Array())
   md_five = x
end function
Aus Calc heraus wird die Funktion aufgerufen mit bsplw. :

Code: Alles auswählen

=md_five(A1)
Karo
Zuletzt geändert von Karolus am Mi, 27.05.2015 16:59, insgesamt 1-mal geändert.
LO7.4.7.2 debian 12(bookworm) auf Raspberry4b 8GB (64bit)
LO7.6.2.1 flatpak debian 12(bookworm) auf Raspberry4b 8GB (64bit)
offiboy2
*
Beiträge: 13
Registriert: Mi, 27.05.2015 16:11

Re: md5 (oder andere hash-funktion) in calc

Beitrag von offiboy2 »

wo baut man diese Python Funktion ein in office calc ?
oder reicht nur aus die untere ?

kommt dieser folgender Code auch in ph. datei rein oder wo ? oder brauch man es nicht ? und reicht nur die letzte lange code ?

Code: Alles auswählen

from hashlib import md5
import sys
PY3 = (sys.version_info.major >= 3)
    
def md_five(cellcontent ):
    cellcontent = str(cellcontent)
    if PY3:
        cellcontent = cellcontent.encode('utf8') 
    return md5( cellcontent).hexdigest()
Zuletzt geändert von offiboy2 am Mi, 27.05.2015 18:10, insgesamt 2-mal geändert.
Karolus
********
Beiträge: 7440
Registriert: Mo, 02.01.2006 19:48

Re: md5 (oder andere hash-funktion) in calc

Beitrag von Karolus »

offiboy2 hat geschrieben:wo baut man diese Python Funktion ein in office calc ?
oder reicht nur aus die untere ?
die Antwort steht oben im letzten Beitrag.
LO7.4.7.2 debian 12(bookworm) auf Raspberry4b 8GB (64bit)
LO7.6.2.1 flatpak debian 12(bookworm) auf Raspberry4b 8GB (64bit)
offiboy2
*
Beiträge: 13
Registriert: Mi, 27.05.2015 16:11

Re: md5 (oder andere hash-funktion) in calc

Beitrag von offiboy2 »

Diese kommt in Datei sheetFunction.py' in ~/Scripts/python/ im Benutzerconfigurationsverzeichnis. ?

Code: Alles auswählen

from hashlib import md5
import sys
PY3 = (sys.version_info.major >= 3)
    
def md_five(cellcontent ):
    cellcontent = str(cellcontent)
    if PY3:
        cellcontent = cellcontent.encode('utf8') 
    return md5( cellcontent).hexdigest()
Wo kommt diese rein ?

Code: Alles auswählen

REM Keep a global reference to the ScriptProvider, since this stuff may be called many times:
Global g_MasterScriptProvider
REM Specify location of Python script, providing cell functions:
Const URL_Main = "vnd.sun.star.script:sheetFunction.py$"
Const URL_Args = "?language=Python&location=user"

Function getMasterScriptProvider()
   if NOT isObject(g_MasterScriptProvider) then
      oMasterScriptProviderFactory = createUnoService("com.sun.star.script.provider.MasterScriptProviderFactory")
      g_MasterScriptProvider = oMasterScriptProviderFactory.createScriptProvider("")
   endif
   getMasterScriptProvider = g_MasterScriptProvider
End Function

Function md_five( text )
   sURL = URL_Main & "md_five" & URL_Args
   oMSP = getMasterScriptProvider()
   oScript = oMSP.getScript(sURL)
   x = oScript.invoke( Array( text),Array(),Array())
   md_five = x
end function
Karolus
********
Beiträge: 7440
Registriert: Mo, 02.01.2006 19:48

Re: md5 (oder andere hash-funktion) in calc

Beitrag von Karolus »

Kopiere bitte den BASIC-Code per copy&paste in ein Modul in ...MeineMakros/Standard zu erreichen aus Calc heraus über →Extras→Makros→Makros verwalten→Basic

den Pythoncode ( das Update in Blau) kopiere bitte in eine einfache Textdatei die du im Pfad:

Code: Alles auswählen

....<dein OO-benutzerverzeichnis>/Scripts/python/sheetFunction.py

speicherst.
LO7.4.7.2 debian 12(bookworm) auf Raspberry4b 8GB (64bit)
LO7.6.2.1 flatpak debian 12(bookworm) auf Raspberry4b 8GB (64bit)
offiboy2
*
Beiträge: 13
Registriert: Mi, 27.05.2015 16:11

Re: md5 (oder andere hash-funktion) in calc

Beitrag von offiboy2 »

danke ich probiers aus
offiboy2
*
Beiträge: 13
Registriert: Mi, 27.05.2015 16:11

Re: md5 (oder andere hash-funktion) in calc

Beitrag von offiboy2 »

Wenn ich formel: =md_five(A1) und in A1 ist passwort
Denn öffnet sich basiccode und Makiert ist in blau: oScript = oMSP.getScript(sURL) und Laufzeitfehler
Zuletzt geändert von offiboy2 am Mi, 27.05.2015 19:42, insgesamt 1-mal geändert.
Karolus
********
Beiträge: 7440
Registriert: Mo, 02.01.2006 19:48

Re: md5 (oder andere hash-funktion) in calc

Beitrag von Karolus »

Welche Fehlermeldung kommt?

Der Pfad `..../Scripts/python/sheetFunction.py` muss auch in exakt dieser Schreibweise (mit Gross/Kleinschreibung) so vorliegen.
LO7.4.7.2 debian 12(bookworm) auf Raspberry4b 8GB (64bit)
LO7.6.2.1 flatpak debian 12(bookworm) auf Raspberry4b 8GB (64bit)
offiboy2
*
Beiträge: 13
Registriert: Mi, 27.05.2015 16:11

Re: md5 (oder andere hash-funktion) in calc

Beitrag von offiboy2 »

hier ist doch richtig ?
C:\Program Files (x86)\OpenOffice 4\share\Scripts\python
offiboy2
*
Beiträge: 13
Registriert: Mi, 27.05.2015 16:11

Re: md5 (oder andere hash-funktion) in calc

Beitrag von offiboy2 »

Dateiname ist: sheetFunction.py

welche Coderung soll es gespeichert sein ?
UTF-8; ANSI; Unicode; Unicode Big End.
Karolus
********
Beiträge: 7440
Registriert: Mo, 02.01.2006 19:48

Re: md5 (oder andere hash-funktion) in calc

Beitrag von Karolus »

offiboy2 hat geschrieben:hier ist doch richtig ?
C:\Program Files (x86)\OpenOffice 4\share\Scripts\python
Nein das ist nicht dein Benutzerverzeichnis das ist das Programmverzeichnis.
ändere im Basicode die Zeile

Code: Alles auswählen

Const URL_Args = "?language=Python&location=user"
um auf

Code: Alles auswählen

Const URL_Args = "?language=Python&location=share"
LO7.4.7.2 debian 12(bookworm) auf Raspberry4b 8GB (64bit)
LO7.6.2.1 flatpak debian 12(bookworm) auf Raspberry4b 8GB (64bit)
offiboy2
*
Beiträge: 13
Registriert: Mi, 27.05.2015 16:11

Re: md5 (oder andere hash-funktion) in calc

Beitrag von offiboy2 »

Danke vielen Dank
Es funktioniert jetzt alles.
codeman
Beiträge: 3
Registriert: Di, 28.07.2015 16:57

Re: md5 (oder andere hash-funktion) in calc

Beitrag von codeman »

Hallo,
benötige auch md5 in openoffice und wurde von google hier her verbunden....
ich habe openoffice.org 3.2.1, win xp.
Habe alles gemäß der Anleitung von hier durchgeführt.

Zuerst erhielt ich die Fehlermeldung in Bild 1.
Deshalb habe ich im Basic Code die Variable "text" in "meintext" geändert.

Danach erhalte ich die Fehlermeldung in Bild 2.

Ich bin für jede Hilfe Dankbar. Ich hab von allem nur eine blasse Ahnung....

Grüße
codeman
Dateianhänge
Bild 1
Bild 1
fehler1.jpg (202.2 KiB) 8842 mal betrachtet
Bild 2
Bild 2
fehler2.jpg (231.75 KiB) 8842 mal betrachtet
Karolus
********
Beiträge: 7440
Registriert: Mo, 02.01.2006 19:48

Re: md5 (oder andere hash-funktion) in calc

Beitrag von Karolus »

Ich beantworte keine Anfragen die im wesentlichen aus knapp 500kb fetten Screenshots bestehen.
LO7.4.7.2 debian 12(bookworm) auf Raspberry4b 8GB (64bit)
LO7.6.2.1 flatpak debian 12(bookworm) auf Raspberry4b 8GB (64bit)
Antworten