CHR(i) nach Excel [erledigt]

Nutzung, Komponenten, .NET

Moderator: Moderatoren

Antworten
Benutzeravatar
AUGE_OHR
Marvin
Marvin
Beiträge: 12903
Registriert: Do, 16. Mär 2006 7:55
Wohnort: Hamburg
Hat sich bedankt: 19 Mal
Danksagung erhalten: 44 Mal

CHR(i) nach Excel [erledigt]

Beitrag von AUGE_OHR »

moin,

ich wollte mir eine "Zeichen Tabelle" in Excel erstellen.

Code: Alles auswählen

   FOR i := 1 TO 255
?     cName := REPLICATE(CHR(i),10)
      AADD(aExcel,cName)
   NEXT
gibt mir doch alle Zeichen (10x) von CHR(1) bis CHR(255).

nun übergebe ich das Array an Excel, egal auf was für einem OS()

Code: Alles auswählen

#PRAGMA LIBRARY( "ASCOM10.LIB" )

PROCEDURE MAIN
LOCAL aExcel := {}
LOCAL i
LOCAL cName
LOCAL ZPATH := LEFT( AppName( .t. ), LEN( AppName( .t. ) ) - LEN(AppName( .f. ) ) )

   SET CHARSET TO OEM // oder ANSI ist hier egal ???

   CLS
   SET ALTER TO CHR2EXCE.TXT
   SET ALTER ON
   FOR i := 1 TO 255
?     cName := REPLICATE(CHR(i),10)
      AADD(aExcel,cName)
   NEXT
   SET ALTER OFF
   SET ALTER TO
   WAIT
   ShowExcel(aExcel,ZPATH)

RETURN

PROCEDURE ShowExcel(aExcel,ZPATH )
LOCAL oExcel
LOCAL oWorkBook
LOCAL oSheet
LOCAL oError
LOCAL bSaveError

   // save Errorblock
   bSaveError := ErrorBlock()

   // set new Errorblock
   ErrorBlock( {|e| Break(e)} )

   BEGIN SEQUENCE
      // Start Excel
      oExcel := CreateObject( "Excel.Application" )
      IF NIL == oExcel
         // Excel.Application could not be created.
         MSGBOX( "Excel Verbindung konnte nicht erstellt werden" )
         * ? "Error: ", ComLastError()
         * ? "Description:"
         * ? ComLastMessage()
         BREAK
      ELSE

         oExcel:visible := .T.                   // visible

      // If there is a problem, don't let excel pop up messages
         oExcel:Application:DisplayAlerts := .F.

      // Create a workbook from scratch
         oExcel:Application:Workbooks:new()
         oExcel:Application:Workbooks:add()

      // Office 97 Excel creates 3 worksheets by default
      // Delete 2 of them
*        oExcel:Application:Worksheets(3):delete()
*        oExcel:Application:Worksheets(2):delete()

      // Make the first one active
         oWorkBook := oExcel:activeWorkBook
         oExcel:Application:Worksheets( 1 ):activate()

      // Rename the sheet
         oExcel:Application:Worksheets( 1 ):name := "ID_USER"

      // Speed things up by creating an object containing the cells
         oSheet := oExcel:Worksheets( 1 ):cells

         oSheet:range( "A1:A255" ):value      := aExcel

      // Save the workbook
      // If you don't put a path, the file will be somewhere in
      // My Documents or some other Excel default directory
         oWorkBook:saveas(ZPATH+"TESTI")

      // Quit Excel
         oExcel:Quit()

      // destroy the reference
         oExcel:destroy()
         IF ComLastError() > 0
            MSGBOX( "Error: " + STR( ComLastError() ) + CHR( 13 ) + CHR( 10 ) + "Description:" + ComLastMessage() )
            * ? "Error: ", ComLastError()
            * ? "Description:"
            * ? ComLastMessage()
            BREAK
         ENDIF
     ENDIF

   RECOVER USING oError
      // restore Errorblock
      ErrorBlock( bSaveError )

      * ? "Error: ", ComLastError()
      * ? "Description:"
      * ? ComLastMessage()
      IF ComLastError() > 0
         MSGBOX( "Error: " + STR( ComLastError() ) + CHR( 13 ) + CHR( 10 ) + "Description:" + ComLastMessage() )
      ENDIF
      IF VALTYPE( oExcel ) = 'O'
         IF VALTYPE( oSheet ) = 'O'
            oSheet := NIL
         ENDIF
         oExcel:Quit()
         oExcel:Destroy()
      ENDIF
   END SEQUENCE
   // restore Errorblock
   ErrorBlock( bSaveError )
RETURN
und was kommt raus :angry4:

hab ich da irgendwo einen "Denkfehler" :-k

Die Datei TESTI.XLS liegt im selben Verzeichniss wo ihr das Demo startet.


Nachtrag : wenn ich AADD(aExcel,cName) auf ein 2-Dim erweitere AADD(aExcel,{i,cName})
und entsprechend oSheet:range( "A1:B255" ):value := aExcel angebe dann geht es ... #-o

mag Excel 1-Dim Array nicht ?
gruss by OHR
Jimmy
Benutzeravatar
brandelh
Foren-Moderator
Foren-Moderator
Beiträge: 15689
Registriert: Mo, 23. Jan 2006 20:54
Wohnort: Germersheim
Hat sich bedankt: 65 Mal
Danksagung erhalten: 33 Mal
Kontaktdaten:

Re: CHR(i) nach Excel [erledigt]

Beitrag von brandelh »

Hi,

ich würde nicht unter chr(32) = Blank gehen, Steuerzeichen bekommen dem System eventuell nicht ;-)
Gruß
Hubert
Antworten