Datumsformat wird nicht richtig übernommen

  • Hallo zusammen,

    ich versuche "mal wieder" eine Excel Tabelle auszulesen, die u.a. einen Datumswert in andere Zellen kopiert.

    Spoiler anzeigen

    while $eintrag <> ""
    $sFormat = "TT.MM.JJJJ hh:mm:ss" ;Format String tells _ExcelNumberFormat to make it a $ currency
    _ExcelNumberFormat($oBook2, $sFormat, 7,7,7,20) ;Start on Row 1, Start on Column 1, End on Row 5, End on Column 5
    $eintrag = _ExcelReadCell($oBook1,$counter,1)

    Select

    Case $eintrag = string("Ist_PISA_WT25")
    $wert = _ExcelReadCell($oBook1,$counter,2)
    _ExcelWriteCell($obook2,$wert,7,7)


    EndSelect

    Wenn ich so vorgehe, kommt als Ergebnis leider kein Datum raus, sondern #########. Wenn man sich den Zellinhalt dann ansieht, ist es das Datum nur ohne Punkte dazwischen.
    Warum formatiert es nicht richtig, hab schon mehrere Varianten durch getestet.

    Gruß

    milch

  • Wenn dan wäre es der 01.01.1970, aber er formatiert ja die Zelle von daher hat es damit eigentlicht nichts zu tun.

    Andy hat mir ein Schnitzel gebacken aber da war ein Raupi drauf und bevor Oscar das Bugfixen konnte kam Alina und gab mir ein AspirinJunkie.

  • Hi,
    du darfst den Datumswert nicht mit _ExcelReadCell lesen, der Datumswert muss als Formel gelesen werden. Ich habe dazu mal die Funktion _ExcelReadCell etwas abgeändert und sie _ExcelReadFormula genannt. Kopiere sie entweder direkt in dein Skript oder in die Excel.UDF und versuche es.

    Spoiler anzeigen
    [autoit]


    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _ExcelReadFormula
    ; Description ...: Read Formula from the active worksheet of the specified Excel object.
    ; Syntax.........: _ExcelReadFormula($oExcel, $sRangeOrRow[, $iColumn = 1])
    ; Parameters ....: $oExcel - Excel object opened by a preceding call to _ExcelBookOpen() or _ExcelBookNew()
    ; $sRangeOrRow - Either an A1 range, or an integer row number to read from if using R1C1
    ; $iColumn - The column to read from if using R1C1 (default = 1)
    ; Return values .: Success - Returns the data from the specified cell
    ; Failure - Returns 0 and sets @error on errors:
    ; |@error=1 - Specified object does not exist
    ; |@error=2 - Specified parameter is incorrect
    ; |@extended=0 - Row out of valid range
    ; |@extended=1 - Column out of valid range
    ; Author ........: SEO <locodarwin at yahoo dot com>
    ; Modified.......: litlmike, Bastel123
    ; Remarks .......: This function will only read one cell per call - if the specified range spans
    ; multiple cells, only the content of the top left cell will be returned.
    ; Related .......:
    ; Link ..........:
    ; Example .......: Yes
    ; ===============================================================================================================================
    Func _ExcelReadFormula($oExcel, $sRangeOrRow, $iColumn = 1)
    If Not IsObj($oExcel) Then Return SetError(1, 0, 0)
    If Not StringRegExp($sRangeOrRow, "[A-Z,a-z]", 0) Then
    If $sRangeOrRow < 1 Then Return SetError(2, 0, 0)
    If $iColumn < 1 Then Return SetError(2, 1, 0)
    Return $oExcel.Activesheet.Cells($sRangeOrRow, $iColumn).Formula
    Else
    Return $oExcel.Activesheet.Range($sRangeOrRow).Formula
    EndIf
    EndFunc ;==>_ExcelReadFormula

    [/autoit] [autoit][/autoit] [autoit][/autoit]
  • Prima Funktion.
    Aber noch eine Rückfrage: Wenn ich den Rückgabewert in ein array, z.B. $ar_testarray[$counter][1] schreiben will, scheint das nicht zu funktionieren.
    Wenn ich den Rückgabewert in eine normale Variable schreibe, funktioniert es hingegen gut, hilft mir nur gerade nicht..

    Was kann ich da tun?

    Danke

    Einmal editiert, zuletzt von amathar (17. Februar 2012 um 11:44)

  • array ist zuvor angelegt dimensoniert?
    Falls ja sollte arrayadd dann passen.

    Achtung Anfänger! :whistling:

    Betrachten des Quellcodes auf eigene Gefahr, bei Übelkeit,Erbrechen,Kopfschmerzen übernehme ich keine Haftung. 8o

  • Jo, da war der Fehler. Dimensioniert schon, aber ein Element zu wenig :S Array um eine Element vergrößert und schon rennt es :D

    Danke