procedure
TForm1
.
Button1Click(Sender: TObject);
//先定義線型常量,,也可以不定義,定義是為了便于記憶與代碼易讀
const
xlInsideHorizontal =
$0000000C
;
xlInsideVertical =
$0000000B
;
xlDiagonalDown =
$00000005
;
xlDiagonalUp =
$00000006
;
xlEdgeBottom =
$00000009
;
xlEdgeLeft =
$00000007
;
xlEdgeRight =
$0000000A
;
xlEdgeTop =
$00000008
;
xlContinuous =
1
;
xlDash = -
4115
;
xlDashDot =
4
;
xlDashDotDot =
5
;
xlDot = -
4118
;
xlDouble = -
4119
;
xlSlantDashDot = -
4142
;
xlLineStyleNone =
13
;
var
ExcelApp: Variant;
begin
ExcelApp := CreateOleObject(
'Excel.Application'
);
//建立 Excel 聯(lián)系
ExcelApp
.
Visible :=
True
;
//顯示 excel 窗口
ExcelApp
.
WorkBooks
.
Open(
'd:\Demo.xls'
);
//打開指定的 excel 文件
//設(shè)置表格中指定單元格的上邊框
ExcelApp
.
ActiveSheet
.
Range[
'A2:H7'
].Borders[xlEdgeTop].LineStyle := xlDouble;
ExcelApp
.
ActiveSheet
.
Range[
'A2:H7'
].Borders[xlEdgeTop].Color := clRed;
ExcelApp
.
ActiveSheet
.
Range[
'A2:H7'
].Borders[xlEdgeTop].Weight :=
4
;
//設(shè)置表格中指定單元格的底邊框
ExcelApp
.
ActiveSheet
.
Range[
'A2:H7'
].Borders[xlEdgeBottom].LineStyle := xlDouble;
ExcelApp
.
ActiveSheet
.
Range[
'A2:H7'
].Borders[xlEdgeBottom].Color := clRed;
ExcelApp
.
ActiveSheet
.
Range[
'A2:H7'
].Borders[xlEdgeBottom].Weight :=
4
;
//設(shè)置表格中指定單元格的左邊框
ExcelApp
.
ActiveSheet
.
Range[
'A2:H7'
].Borders[xlEdgeLeft].LineStyle := xlDouble;
ExcelApp
.
ActiveSheet
.
Range[
'A2:H7'
].Borders[xlEdgeLeft].Color := clRed;
ExcelApp
.
ActiveSheet
.
Range[
'A2:H7'
].Borders[xlEdgeLeft].Weight :=
4
;
//設(shè)置表格中指定單元格的右邊框
ExcelApp
.
ActiveSheet
.
Range[
'A2:H7'
].Borders[xlEdgeRight].LineStyle := xlDouble;
ExcelApp
.
ActiveSheet
.
Range[
'A2:H7'
].Borders[xlEdgeRight].Color := clRed;
ExcelApp
.
ActiveSheet
.
Range[
'A2:H7'
].Borders[xlEdgeRight].Weight :=
4
;
//設(shè)置表格中間所有橫線
ExcelApp
.
ActiveSheet
.
Range[
'A2:H7'
].Borders[xlInsideHorizontal].LineStyle := xlContinuous;
ExcelApp
.
ActiveSheet
.
Range[
'A2:H7'
].Borders[xlInsideHorizontal].Color := clBlue;
ExcelApp
.
ActiveSheet
.
Range[
'A2:H7'
].Borders[xlInsideHorizontal].Weight :=
2
;
//設(shè)置表格中間所有縱線
ExcelApp
.
ActiveSheet
.
Range[
'A2:H7'
].Borders[xlInsideVertical].LineStyle := xlContinuous;
ExcelApp
.
ActiveSheet
.
Range[
'A2:H7'
].Borders[xlInsideVertical].Color := clBlue;
ExcelApp
.
ActiveSheet
.
Range[
'A2:H7'
].Borders[xlInsideVertical].Weight :=
2
;
end
;