Thema: Delphi OLE Excel

Einzelnen Beitrag anzeigen

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