AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Markierter Bereich in Excel

Ein Thema von DevilsCamp · begonnen am 22. Feb 2006 · letzter Beitrag vom 22. Feb 2006
Antwort Antwort
DevilsCamp
(Gast)

n/a Beiträge
 
#1

Markierter Bereich in Excel

  Alt 22. Feb 2006, 16:10
Wie ich Daten aus Excel bekomme weiß ich.

Allerdings bin ich am verzweifeln, wie ich es schaffe, nur den markierten Bereich in einer Excel-Tabelle auszulesen.
Da dieser ja dynamisch, zur Compilierzeit ja nicht bekannt ist, stehe ich da z.Z. vor einem Problem.

Ich hoffe, mir kann da jemand helfen.
  Mit Zitat antworten Zitat
Ferber

Registriert seit: 9. Mär 2005
Ort: Wien Umgebung
155 Beiträge
 
Delphi 2006 Architect
 
#2

Re: Markierter Bereich in Excel

  Alt 22. Feb 2006, 17:20
Hi !

Hier ein komplettes Demo.

Delphi-Quellcode:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    FExcelApp:Variant;
    function GetApplication:Variant;
    function GetSelection: Variant;
    function GetActiveSheet: Variant;
  public
    property XlsApp:Variant read GetApplication;
    property ActiveSheet:Variant read GetActiveSheet;
    property Selection:Variant read GetSelection;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

function TForm1.GetApplication:Variant;
begin
  if VarType(FExcelApp)=varEmpty then
  try
    FExcelApp:=GetActiveOleObject('Excel.Application');
    FExcelApp.Visible:=True;
  except
    FExcelApp:= CreateOleObject('Excel.Application');
    FExcelApp.Visible:=True;
  end;
  Result:=FExcelApp;
end;

function TForm1.GetSelection: Variant;
begin
  Result:=XlsApp.Selection;
end;

function TForm1.GetActiveSheet: Variant;
begin
  Result:=XlsApp.ActiveSheet;
end;

procedure TForm1.Button1Click(Sender: TObject);
var Sel:Variant;
    r,c,r1,c1,r2,c2:Integer;
    s:String;
begin
  Sel:=Selection;
  r1:=Sel.Row;
  c1:=Sel.Column;
  r2:=Sel.Rows.Count;
  c2:=Sel.Columns.Count;
  for r:=r1 to r1+r2-1 do
    for c:=c1 to c1+c2-1 do
      begin
        s:=ActiveSheet.Cells[r,c].Value;
        Memo1.Lines.Add('Cell('+IntToStr(r)+','+IntToStr(c)+').Value='+s);
      end;
end;

end.
Excel ist IMHO auch sehr gut zum Drucken von Formularen.
In Excel Namen einfügen, die findet man aus Delphi mit:

Delphi-Quellcode:
procedure TExcel.RCofName(aName: String; var r, c: Integer);
begin
  XlsApp.Goto(aName);
  r:=Selection.Row;
  c:=Selection.Column;
end;
Mit freundlichen Grüssen vom 'Ferber'
Otto
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 18:30 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