Seite 1 von 2
					
				md5 (oder andere hash-funktion) in calc
				Verfasst: Do, 07.06.2012 12:28
				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
			 
			
					
				Re: md5 (oder andere hash-funktion) in calc
				Verfasst: Do, 07.06.2012 13:18
				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. :
Karo
 
			 
			
					
				Re: md5 (oder andere hash-funktion) in calc
				Verfasst: Mi, 27.05.2015 16:14
				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()
 
			 
			
					
				Re: md5 (oder andere hash-funktion) in calc
				Verfasst: Mi, 27.05.2015 17:00
				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.
 
			 
			
					
				Re: md5 (oder andere hash-funktion) in calc
				Verfasst: Mi, 27.05.2015 18:32
				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
 
			 
			
					
				Re: md5 (oder andere hash-funktion) in calc
				Verfasst: Mi, 27.05.2015 19:03
				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.
 
			 
			
					
				Re: md5 (oder andere hash-funktion) in calc
				Verfasst: Mi, 27.05.2015 19:11
				von offiboy2
				danke ich probiers aus
			 
			
					
				Re: md5 (oder andere hash-funktion) in calc
				Verfasst: Mi, 27.05.2015 19:25
				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
			 
			
					
				Re: md5 (oder andere hash-funktion) in calc
				Verfasst: Mi, 27.05.2015 19:41
				von Karolus
				Welche Fehlermeldung kommt?
Der Pfad `..../Scripts/python/sheetFunction.py` muss auch in exakt dieser Schreibweise (mit Gross/Kleinschreibung) so vorliegen.
			 
			
					
				Re: md5 (oder andere hash-funktion) in calc
				Verfasst: Mi, 27.05.2015 19:43
				von offiboy2
				hier ist doch richtig ?
C:\Program Files (x86)\OpenOffice 4\share\Scripts\python
			 
			
					
				Re: md5 (oder andere hash-funktion) in calc
				Verfasst: Mi, 27.05.2015 19:47
				von offiboy2
				Dateiname ist: sheetFunction.py
welche Coderung soll es gespeichert sein ?
UTF-8; ANSI; Unicode; Unicode Big End.
			 
			
					
				Re: md5 (oder andere hash-funktion) in calc
				Verfasst: Mi, 27.05.2015 19:53
				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
um auf
 
			 
			
					
				Re: md5 (oder andere hash-funktion) in calc
				Verfasst: Mi, 27.05.2015 21:23
				von offiboy2
				Danke vielen Dank
Es funktioniert jetzt alles.
			 
			
					
				Re: md5 (oder andere hash-funktion) in calc
				Verfasst: Di, 28.07.2015 17:56
				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
			 
			
					
				Re: md5 (oder andere hash-funktion) in calc
				Verfasst: Di, 28.07.2015 18:37
				von Karolus
				Ich beantworte keine Anfragen die im wesentlichen aus knapp 500kb fetten Screenshots bestehen.