Thema: Delphi Excel-Export formatieren

Einzelnen Beitrag anzeigen

Tim Henford

Registriert seit: 14. Sep 2006
169 Beiträge
 
#3

Re: Excel-Export formatieren

  Alt 2. Sep 2008, 08:44
Ok, dankeschön mit OLE klappt das doch wie gewünscht.
Nun habe ich folgenden Code, aber das Programm bleibt beim Beenden noch offen, also im Taskmanager. Fenster sind alle geschlossen:

Delphi-Quellcode:
procedure excelFormat;
const
  // SheetType
  xlChart = -4109;
  xlWorksheet = -4167;
  // WBATemplate
  xlWBATWorksheet = -4167;
  xlWBATChart = -4109;
  // Page Setup
  xlPortrait = 1;
  xlLandscape = 2;
  xlPaperA4 = 9;
  // Format Cells
  xlBottom = -4107;
  xlLeft = -4131;
  xlRight = -4152;
  xlTop = -4160;
  // Text Alignment
  xlHAlignCenter = -4108;
  xlVAlignCenter = -4108;
  // Cell Borders
  xlThick = 4;
  xlThin = 2;
var
  ColumnRange: OleVariant;

  // function to get the number of Rows in a certain column
  function GetLastLine(AColumn: Integer): Integer;
  const
    xlUp = 3;
  begin
    Result := ExcelApp.Range[Char(96 + AColumn) + IntToStr(65536)].end[xlUp].Rows.Row;
  end;
begin
  { Start Excel 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
      Application.MessageBox (PChar ('Excel kann nicht gestartet werden!'+#13#10+
          'Wurde Excel installiert?'),'Excel nicht gefunden', mb_iconWarning+ MB_SETFOREGROUND + MB_SYSTEMMODAL);
      Exit;
    end;
  end;

  // Arbeitsmappe öffnen
  ExcelApp.Workbooks.Open('export.xls');

  // Change the Column Width.
  ColumnRange:= ExcelApp.Workbooks[1].WorkSheets[1].Columns;
  ColumnRange.Columns[1].ColumnWidth := 20;
  ColumnRange.Columns[2].ColumnWidth := 20;
  ColumnRange.Columns[3].ColumnWidth := 20;
  ColumnRange.Columns[4].ColumnWidth := 20;
  ColumnRange.Columns[5].ColumnWidth := 20;

  // Fettdruck in den Zellen
  ExcelApp.Range['A1:Z1'].Font.Bold := True;

  // Zoom
  ExcelApp.ActiveSheet.PageSetup.Zoom := 95;

  // Show Excel:
  ExcelApp.Visible := True;
end;
Woran liegt das hier? Muss man da noch irgendetwas wieder freigeben?

Außerdem hab ich das Problem mit dem Hochkommas und den Datentyp noch nicht lösen können.

Dankeschön Tim
  Mit Zitat antworten Zitat