AGB  ·  Datenschutz  ·  Impressum  







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

OLE Excel

Ein Thema von hmbg · begonnen am 7. Sep 2006 · letzter Beitrag vom 28. Sep 2006
 
hmbg

Registriert seit: 28. Jul 2004
Ort: Hamburg
61 Beiträge
 
Delphi 7 Professional
 
#5

Re: OLE Excel

  Alt 27. Sep 2006, 19:13
Delphi-Quellcode:
procedure TForm1.ProceedButtonClick(Sender: TObject);
var i, RowCount, ORowCount:integer;

begin
  i:=1;

  // By using GetActiveOleObject, you use an instance of Word that's already running,
  // if there is one.
  try
    ExcelApp := GetActiveOleObject('Excel.Application');
  except
    try
      // If no instance of Word is running, try to Create a new Excel Object
      ExcelApp := CreateOleObject('Excel.Application');
    except
      ShowMessage('Excel - Modul kann nicht gestartet werden! Möglicherweise ist es nicht installiert?');
      //Exit;
    end;
  end;

  // Open a Workbook
  ExcelApp.Workbooks.Open('c:\'+AktenZeichen+'.xls');

  repeat
    i:=i+1;
  until ExcelApp.Cells[i, 1].Value='';

  ORowCount:=i;

  ExcelApp.Cells[ORowCount, 2].Value:=DateToStr(Datum.Date);
  ExcelApp.Cells[ORowCount, 3].Value:=StundenBeschreib.Lines.Text;

  RowCount:=ORowCount;

      for i:=0 to KostenUebers.Items.Count-1 do
        begin
          RowCount:=RowCount+1;
          ExcelApp.Cells[RowCount, 3].Value:=KostenUebers.Items.Strings[i];
          ExcelApp.Cells[RowCount, 6].Value:=FloatToStr(EinzelKosten[i+1]);
        end;

      try
      for i:=0 to Data.Count-1 do
        begin
          RowCount:=RowCount+1;
          Data.Strings[i]:=AnsiMidStr(Data.Strings[i],0,Length(Data.Strings[i])-12);
          if MB = 'Sachverständigerthen
            begin
              ExcelApp.Cells[RowCount, 3].Value:=Data.Strings[i];
              ExcelApp.Cells[RowCount, 4].Value:=' -';
              ExcelApp.Cells[RowCount, 5].Value:=' -';
            end;

          if MB = 'Hilfskraftthen
            begin
              ExcelApp.Cells[RowCount, 4].Value:=Data.Strings[i];
              ExcelApp.Cells[RowCount, 3].Value:=' -';
              ExcelApp.Cells[RowCount, 5].Value:=' -';
            end;

          if MB = 'Schreibkraftthen
            begin
              ExcelApp.Cells[RowCount, 5].Value:=Data.Strings[i];
              ExcelApp.Cells[RowCount, 4].Value:=' -';
              ExcelApp.Cells[RowCount, 3].Value:=' -';
            end;
        end;
        except
        end;

      if MB = 'Sachverständigerthen
        begin
         ExcelApp.Cells[ORowCount, 4].Value:=StundenEdit.Text;
         ExcelApp.Cells[ORowCount, 5].Value:=' -';
         ExcelApp.Cells[ORowCount, 6].Value:=' -';
        end;

      if MB = 'Hilfskraftthen
        begin
         ExcelApp.Cells[ORowCount, 5].Value:=StundenEdit.Text;
         ExcelApp.Cells[ORowCount, 4].Value:=' -';
         ExcelApp.Cells[ORowCount, 6].Value:=' -';
        end;

      if MB = 'Schreibkraftthen
        begin
         ExcelApp.Cells[ORowCount, 6].Value:=StundenEdit.Text;
         ExcelApp.Cells[ORowCount, 4].Value:=' -';
         ExcelApp.Cells[ORowCount, 5].Value:=' -';
        end;

      for i:=ORowCount to RowCount do
      ExcelApp.Cells[i, 1].Value:=inttostr(i);
      
      // Save the active Workbook:
      ExcelApp.ActiveWorkBook.Save;//As('c:\'+AktenZeichen+'.xls');
      ExcelApp.ActiveWorkBook.Close;
      ShowMessage('File Saved');
      ExcelApp.Quit;
end;
So, da ist bestimmt einiges überflüssig da dran, aber ich beschäftige mich ja auch noch nicht lange damit

Das ist jetzt die ganze procedure, wo die Daten, die vorher eingegeben werden in die Tabelle geschrieben werden.

Zuerst hat das Programm auch noch gut funktioniert, ich weiß aber nicht ab welchem Schritt die Probleme anfingen

nya, mfg hmbg
Come on Head, work with me!
  Mit Zitat antworten Zitat
 


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 05:21 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz