Thursday, 22 November 2012

How To Use Delphi with Excel - Formating MS. Excel

//a part of TExcelApplication use

var fnt: ExcelXP.Font;
    wb: ExcelWorkbook;
    ws: ExcelWorksheet;
    rng: ExcelRange;

Begin
  ExcelApplication1.Connect;
    wb := ExcelApplication1.Workbooks.Open('D:\MyTestProjects\EE\Excel\bin\test.xlsx', 0, False, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, 0);
    WS:= ExcelApplication1.Worksheets.Item['Blad1'] as _Worksheet;
    rng := ws.Range['A2', 'A2'];
    fnt := rng.Characters[1, 14].Font;
    fnt.Name := 'Arial';
    fnt.FontStyle := 'Bold';
    fnt.Size := 9;
    fnt.Strikethrough := False;
    fnt.Superscript := False;
    fnt.Subscript := False;
    fnt.OutlineFont := False;
    fnt.Shadow := False;
    fnt.Underline := xlUnderlineStyleNone;
    fnt.ColorIndex := xlAutomatic;
    rng := ws.Range['A2', 'A2'];
    fnt := rng.Characters[15, 24].Font;
    fnt.Name := 'Arial';
    fnt.FontStyle := 'Bold';
    fnt.Size := 9;
    fnt.Strikethrough := False;
    fnt.Superscript := False;
    fnt.Subscript := False;
    fnt.OutlineFont := False;
    fnt.Shadow := False;
    fnt.Underline := xlUnderlineStyleSingle;
    fnt.ColorIndex := xlAutomatic;
    ExcelApplication1.Visible[0] := True;

end;

No comments:

Post a Comment