Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Excel Tabelle mit Diagramm erstellen??? D3 Prof. (https://www.delphipraxis.net/71520-excel-tabelle-mit-diagramm-erstellen-d3-prof.html)

EDatabaseError 16. Jun 2006 09:46


Excel Tabelle mit Diagramm erstellen??? D3 Prof.
 
Also...ich will aus Delphi eine Excel Tabelle mit Diagramm erzeugen. Geht das???

Um grundlegendes zu erstellen hab ich das gefunden:
Delphi-Quellcode:
unit main;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Xls;

type
  TfrmMain = class(TForm)
    btnMakeXls: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    procedure btnMakeXlsClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmMain: TfrmMain;

implementation

{$R *.DFM}

procedure TfrmMain.btnMakeXlsClick(Sender: TObject);
Var
  FileHandle : Integer;
  FileNameStr : String;
begin
  FileNameStr := ExtractFilePath(Application.ExeName) + 'Delphi.xls';
  FileHandle := Xls_Create(FileNameStr);

  Xls_SetFormat(FileHandle,'yyyy-mm-dd hh:mm:ss'); // user defined additional format 21

  // Xls_SetProtection(FileHandle, True); // protect entire worksheet
  // Xls_SetAttributeByte1(True, True); // Hidden, Locked -> only works if sheet is protected

  // some titles in the first column
  Xls_SetString(FileHandle, 0, 0, 'A random string :)');
  Xls_SetString(FileHandle, 1, 0, 'A lucky integer');
  Xls_SetString(FileHandle, 2, 0, 'Pi (in a box) - yuk :)');
  Xls_SetString(FileHandle, 3, 0, 'Today :');

  Xls_SetString(FileHandle, 0, 1, 'Hello World'); // couldn't resist the temptation
  Xls_SetInteger(FileHandle, 1, 1, 13); // integer : lucky 13

  Xls_SetAttributeByte3(False, True, True, True, True, 0); // show all borders
  Xls_SetDouble(FileHandle, 2, 1, Pi); // pi = double = 3.141572...
  Xls_SetAttributeByte3(False, False, False, False, False, 0); // reset

  Xls_SetAttributeByte2(0, 21); // use user defined format 21
  Xls_SetDouble(FileHandle, 3, 1, Now); // datetime
  Xls_SetAttributeByte2(0, 0); // reset

  Xls_SetColWidth(FileHandle, 0, 17);   // set column width
  Xls_SetColWidth(FileHandle, 1, 25);   // set column width

  Xls_Close (FileHandle); // closing stuff

  ShowMessage('done');
end;

end.
Mfg
Tobi

EDatabaseError 16. Jun 2006 17:38

Re: Excel Tabelle mit Diagramm erstellen??? D3 Prof.
 
*push* ;-)

Das was da oben ist läuft nur mit D2005 auf meinem D3 kennt er die Unit Xls nicht.

mkinzler 16. Jun 2006 17:55

Re: Excel Tabelle mit Diagramm erstellen??? D3 Prof.
 
Späte Bindung der com-Objekte funktioniert aber auf jedenfall, man muß halt auf die Autovervollständigung der IDE verzichten.
Delphi-Quellcode:
var
    excel: OleVariant;
..
begin
   ...
   excel := CreateOleObject( 'Excel.Application');

EDatabaseError 16. Jun 2006 17:58

Re: Excel Tabelle mit Diagramm erstellen??? D3 Prof.
 
:wiejetzt: :gruebel: sry aber versteh ich nicht...


Alle Zeitangaben in WEZ +1. Es ist jetzt 18:10 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz