首先在你的单元里面定义如下常数
{Excle线型}
xlMedium = $FFFFEFD6;
xlThick = $00000004;
xlThin = $00000002;
xlContinuous = $00000001;
{Excel的对齐方式}
xlCenter = $FFFFEFF4;
xlLeft = $FFFFEFDD;
xlRight = $FFFFEFC8;
xlTop = $FFFFEFC0;
xlBottom = $FFFFEFF5;
下面的代码,是从我写过的导出Excel当中两个过程 Copy过来的,您自己看吧!
function TExcelExport.GerCellSection(SRow, SColumn, ERow,
EColumn: Integer): Variant;
var
SCell, ECell: string;
begin
//GetRowsFlag 函数是通过数字返回对应的字母的函数,在这里我没有列出源码
//比如 GetRowsFlag(1)的Result是 A
SCell := GetRowsFlag(SColumn - 1) + IntToStr(SRow);
ECell := GetRowsFlag(EColumn - 1) + IntToStr(ERow);
FExcelApp.Worksheets[FWorkSheetNO].Range[SCell, ECell].Select;
Result := FExcelApp.Selection;
end;
procedure TExcelExport.ExcelTitleBar;
var
SelectedCell: Variant;
ColumnCount: Integer;
begin
ColumnCount := TLine(FPrintList.Last).FCellList.Count;
SelectedCell := GerCellSection(1, 1, 1, ColumnCount); //第一行
SelectedCell.HorizontalAlignment := xlCenter;
SelectedCell.VerticalAlignment := xlCenter;
SelectedCell.Font.Size := FLayOut.TitleFont.Size;
SelectedCell := GerCellSection(2, 1, 2, ColumnCount); //第二行
SelectedCell.HorizontalAlignment := xlLeft;
SelectedCell.VerticalAlignment := xlCenter;
SelectedCell.Font.Size := FLayOut.CaptionFont.Size;
SelectedCell := GerCellSection(3, 1, FFieldLineCount, ColumnCount); //字段行
SelectedCell.HorizontalAlignment := xlCenter;
SelectedCell.VerticalAlignment := xlCenter;
SelectedCell.Font.Size := FLayOut.FieldFont.Size;
ExcleTitleArea; //数据区域部分
end;