Einzelnen Beitrag anzeigen

gandime
(Gast)

n/a Beiträge
 
#6

Re: Excel export Zelle formatieren?

  Alt 9. Aug 2009, 18:39
@Chemiker:
Danke für die Seite!
Das hat mir einen ersten EInblick verschafft!

Gerade zu etwas anderem von dir^^
bei deiner XLSDateiUnit solltest du bei der
function DatenInXLSDateiUebertragen(const XLS_LWPathDateiName: string; DatenStringGrid: TStringGrid): boolean; eine abfrage machen beevor du die Zelle eintragen lässt.
if inhalt<>'then damit keine Leeren Felder hinzugefügt werden. (Kann bei längerem Zelleninhalt dazu führen das es nicht komplett sichtbar ist)


Mit hilfe von SwissDelphiCenter.ch und Delphi-Forum.de
habe ich jetzt einen funktionierenden Excel export mit Zellenformation.

was wie folgt aussieht:
Delphi-Quellcode:
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;
  xlEdgeLeft=7;
  xlEdgeTop=8;
  xlEdgeBottom=9;
  xlEdgeRight=10;
  xlInsideVertical=11;
  xlInsideHorizontal=12;

var
  ExcelApp:Variant;

begin
  try
    ExcelApp := GetActiveOleObject('Excel.Application');
  except
    try
      ExcelApp := CreateOleObject('Excel.Application');
    except
      ShowMessage('Cannot start Excel/Excel not installed ?');
      Exit;
    end;
  end;
  ExcelApp.Workbooks.Add(xlWBatWorkSheet);
  ExcelApp.Cells[1,1].Value := 'Delphi-Praxis';
  ExcelApp.Cells[2,1].Value := 'http://www.delphipraxis.net';
  ExcelApp.Cells[1,1].Font.size:=10;
  ExcelApp.Cells[2,1].Font.Bold:=true;
  ExcelApp.Cells[2,1].Font.underline:=true;
  ExcelApp.Cells[3,1].Borders[xlEdgeBottom].Weight := xlThin;
  ExcelApp.ActiveWorkBook.Close(SaveChanges := True, Filename := Directory);
end;
  Mit Zitat antworten Zitat