ADO与EXECL文件连接(50分)

  • 主题发起人 主题发起人 ABA
  • 开始时间 开始时间
A

ABA

Unregistered / Unconfirmed
GUEST, unregistred user!
我用DELPHI6+SP2,看了李维的例子,我却不能连接EXEC文件,为什么呢!谢谢大家!
SP2为DELPHI6的升级包2
 
你是想做报表吧/
俺把以前做报表时的一个DEMO给你看看,非常实用。
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,ComObj, StdCtrls, Excel2000, OleServer, AxCtrls, OleCtrls, VCF1;

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Edit1: TEdit;
Button4: TButton;
a: TExcelWorksheet;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
ExcelApp,Esheet1,Echart, Erange:variant;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
ExcelApp := CreateOleObject( 'Excel.Application' ); // 创建EXCEL对象
ExcelApp.Visible := True; //显示当前窗口
ExcelApp.Caption := '应用程序调用 Microsoft Excel'; //更改 Excel 标题栏
ExcelApp.WorkBooks.Add; //添加新工作簿
ExcelApp.Workbooks[1].Sheets[1].name:='Chinese';
ExcelApp.ActiveSheet.Range['A1:E2'].Merge(); //合并单元格
excelapp.cells[1,1].value:='天天向上';
excelapp.Cells[1,1].Font.Color :=clBlue;
{ ExcelApp.WorkBooks.Open( 'f:/Excel/Demo.xls' ); // 打开已存在的工作簿
ExcelApp.WorkSheets[2].Activate; //设置第2个工作表为活动工作表 ExcelApp.WorksSheets[ 'Sheet2' ].Activate;
ExcelApp.Cells[1,4].Value := '第一行第四列'; //给单元格赋值
ExcelApp.ActiveSheet.Columns[1].ColumnsWidth := 5; //设置指定列的宽度(单位:字符个数),以第一列为例:
ExcelApp.ActiveSheet.Rows[2].RowHeight := 1/0.035; //设置指定行的高度(单位:磅)(1磅=0.035厘米),以第二行为例: 1厘米
ExcelApp.WorkSheets[1].Rows[8].PageBreak := 1; //在第8行之前插入分页符:
ExcelApp.ActiveSheet.Columns[4].PageBreak := 0; //在第8列之前删除分页符
ExcelApp.ActiveSheet.Range[ 'B3:D4' ].Borders[2].Weight := 3;//11) 指定边框线宽度:1-左 2-右 3-顶 4-底 5-斜( / ) 6-斜( / )
ExcelApp.ActiveSheet.Cells[1,4].ClearContents; //清除第一行第四列单元格公式:
ExcelApp.ActiveSheet.Rows[1].Font.Name := '隶书'; //13) 设置第一行字体属性:
ExcelApp.ActiveSheet.Rows[1].Font.Color := clBlue;
ExcelApp.ActiveSheet.Rows[1].Font.Bold := True;
ExcelApp.ActiveSheet.Rows[1].Font.UnderLine := True;
//进行页面设置
ExcelApp.ActiveSheet.PageSetup.CenterHeader := '报表演示'; //页眉
ExcelApp.ActiveSheet.PageSetup.CenterFooter := '第&P页'; //页脚
ExcelApp.ActiveSheet.PageSetup.HeaderMargin := 2/0.035; //页眉到顶端边距2cm
ExcelApp.ActiveSheet.PageSetup.HeaderMargin := 3/0.035; //页脚到底端边距3cm
ExcelApp.ActiveSheet.PageSetup.TopMargin := 2/0.035; //顶边距2cm
ExcelApp.ActiveSheet.PageSetup.BottomMargin := 2/0.035; //底边距2cm
ExcelApp.ActiveSheet.PageSetup.LeftMargin := 2/0.035; //左边距2cm
ExcelApp.ActiveSheet.PageSetup.RightMargin := 2/0.035; //右边距2cm
ExcelApp.ActiveSheet.PageSetup.CenterHorizontally := 2/0.035; //页面水平居中
ExcelApp.ActiveSheet.PageSetup.CenterVertically := 2/0.035; //页面垂直居中
ExcelApp.ActiveSheet.PageSetup.PrintGridLines := True; //打印单元格网线
//拷贝操作
ExcelApp.ActiveSheet.Used.Range.Copy; //拷贝整个工作表
ExcelApp.ActiveSheet.Range['A1:E2'].Copy; //拷贝指定区域:
ExcelApp.ActiveSheet.Range['A1'].PasteSpecial; //从A1位置开始粘贴
ExcelApp.ActiveSheet.Range.PasteSpecial; //从文件尾部开始粘贴
ExcelApp.ActiveSheet.Rows[2].Insert; //插入一行或一列
ExcelApp.ActiveSheet.Columns[1].Insert;
ExcelApp.ActiveSheet.Rows[2].Delete; //删除一行或一列
ExcelApp.ActiveSheet.Columns[1].Delete;
ExcelApp.ActiveSheet.PrintPreview; //打印预览工作表
ExcelApp.ActiveSheet.PrintOut; //打印输出工作表
if not ExcelApp.ActiveWorkBook.Saved then //工作表保存
ExcelApp.ActiveSheet.PrintPreview;
ExcelApp.SaveAs( 'C:/Excel/Demo1.xls' ); //工作表另存为
ExcelApp.ActiveWorkBook.Saved := True; //放弃存盘
ExcelApp.WorkBooks.Close; //关闭工作簿
ExcelApp.Quit; //退出 Excel}
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
end;

//使用Delphi 控制Excle二维图
//在Form中分别放入ExcelApplication, ExcelWorkbook和ExcelWorksheet

procedure TForm1.Button2Click(Sender: TObject);
begin
{ zExcelApplication:=CreateOleObject('Excel.Application');
zExcelApplication.Visible:=True;
zExcelWorkBook:=zExcelApplication.WorkBooks.add();
zExcelWorkSheet:=zExcelWorkBook.Sheets['Sheet1'];
zExcelChart:=zExcelApplication.charts.add;
zExcelWorkSheet.Range['D7:F14'].Value:='222';
zExcelChart.Name:='Chart name';
zExcelChart.SetSourceData(zExcelWorkSheet.Range['D7:F14'],'Chart name');
}

{ Esheet1:=ExcelApp.Workbooks[1].Worksheets[1]; //选择当第一个工作薄第一个工作表
Echart:=Esheet1.chartobjects.add(100,100,200,200); //增加一个二维图
Echart.chart.charttype:=4; //选择二维图的形态
ExcelApp.series:=Echart.chart.seriescollection; //给二维图赋值
// ExcelApp.Erange:=ExcelApp.sheet1.r2c3:r3c9;
ExcelApp.series.add(ExcelApp.range,true);
Echart.Chart.HasTitle:=True; //加上二维图的标题
Echart.Chart.ChartTitle.Characters.Text:='Excle二维图';
achart.Chart.ChartTitle.Font.size:=6; //改变二维图的标题字体大小
achart.Chart.Axes(xlCategory, xlPrimary).HasTitle := True; //给二维图加下标说明
achart.Chart.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text := '下标说明';
achart.Chart.Axes(xlValue, xlPrimary).HasTitle := True; //给二维图加左标说明
achart.Chart.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text := '左标说明';
achart.Chart.Axes(xlValue, xlSecondary).HasTitle := True; //给二维图加右标说明
achart.Chart.Axes(xlValue, xlSecondary).AxisTitle.Characters.Text := '右标说明';
achart.Chart.PlotArea.Left := 5; //改变二维图的显示区大小
achart.Chart.PlotArea.Width := 223;
achart.Chart.PlotArea.Height := 108;
achart.chart.seriescollection[1].NAME:='坐标轴说明'; //给二维图坐标轴加上说明}
end;
procedure TForm1.Button3Click(Sender: TObject);
var
ExcelApplication:variant;
begin
excelapplication:=CreateOleObject('excel.application');
excelapplication.visible:=true;
excelapplication.caption:='sdfjsdlkfj;s';
excelapplication.workbooks.add;
end;

procedure TForm1.Button4Click(Sender: TObject);
var
ExcelAppl:Variant;
i:integer;
a,b:string;
const
//Parse VBA variants;
xlContinuous:Integer=1;
xlMedium:Integer=-4138;
xlThin:Integer=2;
xlAutomatic:Integer=-4105;
xlSolid:Integer=1;
xlCenter:Integer=-4108;
xlTop:Integer=-4160;

xlEdgeLeft:Integer=7;
xlEdgeTop:Integer=8;
xlEdgeBottom:Integer=9;
xlEdgeRight:Integer=10;

xlInsideVertical:Integer=11;
xlInsideHorizontal:Integer=12;

xlLandscape:Integer=2;
xlLocationAsObject:Integer=2;
xlColumns:Integer=2;
xlLineMarkers:Integer=65;
//Custom constant;
zStartRow:Integer=6;
zStartColumn:Integer=Ord('A');

begin
ExcelAppl:=CreateOleObject('Excel.Application');
ExcelAppl.Visible:=true;
ExcelAppl.WorkBooks.Add;
ExcelAppl.Caption:='地市VDN接入统计表';




ExcelAppl.Workbooks[1].Sheets[1].name:='Chinese';
a:='A2';
b:='M2';
ExcelAppl.ActiveSheet.Range[a+':'+b].Merge();
ExcelAppl.Cells[2,1].Value:='地市VDN接入统计表';


// ExcelAppl.WorkSheets[1].Rows[IntToStr(i)].wraptext:=true;
// ExcelAppl.WorkSheets[1].Rows[IntToStr(i)].textDegrees:=10;
// ExcelAppl.Cells[2,1].font.Degrees:=10;


ExcelAppl.Cells[2,1].Font.Color :=clBlack;
ExcelAppl.Cells[2,1].Font.Name:='宋体';
ExcelAppl.Cells[2,1].Font.Size:=22;
ExcelAppl.Cells[2,1].Font.Bold :=fsBold;
ExcelAppl.cells[2,1].HorizontalAlignment:=-4108;
ExcelAppl.cells[2,1].VerticalAlignment:=-4108;

ExcelAppl.Activesheet.Range['B3:D3'].Merge();
ExcelAppl.cells[3,2].Value:='填报单位:山西联通客户服务中心';
ExcelAppl.Activesheet.Range['J3:L3'].Merge();
ExcelAppl.cells[3,10].Value:='制报单位:省分市场营销部';
ExcelAppl.worksheets[1].Range['A3:M3'].Font.Color:=ClBlack;
ExcelAppl.worksheets[1].Range['A3:M3'].Font.Name:='宋体';
ExcelAppl.worksheets[1].Range['A3:M3'].Font.Size:=10;

ExcelAppl.worksheets[1].Columns[1].ColumnWidth := 6;
ExcelAppl.worksheets[1].Rows[1].RowHeight := 10;

ExcelAppl.ActiveSheet.Range['B5:E5'].Merge();

ExcelAppl.worksheets[1].Range['A5:M5'].Font.Name:='宋体';
ExcelAppl.worksheets[1].Range['A5:M5'].Font.Size:=10;
ExcelAppl.Cells[5,2].Value:='时间:'+DateTimeToStr(Date+Time)+' 到 '+DateTimeToStr(Date+Time);

ExcelAppl.worksheets[1].Range['A6:M6'].Font.Name:='宋体';
ExcelAppl.worksheets[1].Range['A6:M6'].Font.Size:=10;
ExcelAppl.worksheets[1].Range['A6:M6'].Font.Bold:=fsBold;

ExcelAppl.worksheets[1].Rows[6].RowHeight := 30;
ExcelAppl.worksheets[1].Rows[6].HorizontalAlignment:=-4108;
ExcelAppl.worksheets[1].Rows[6].VerticalAlignment:=-4108;
ExcelAppl.WorkSheets[1].Rows[6].wraptext:=true;

// ExcelApp.Range['A5:B5'].Borders[xlInsideHorizontal].LineStyle:=xlContinuous;
ExcelAppl.Cells[6,2].Value:='地市';
ExcelAppl.Cells[6,3].Value:='呼入量';
ExcelAppl.Cells[6,4].Value:='服务水平';
ExcelAppl.Cells[6,5].Value:='应答量';
ExcelAppl.Cells[6,6].Value:='平均应答时间';
ExcelAppl.Cells[6,7].Value:='放弃量';
ExcelAppl.Cells[6,8].Value:='平均放弃时间';
ExcelAppl.Cells[6,9].Value:='溢出量';
ExcelAppl.Cells[6,10].Value:='平均通话时间';
ExcelAppl.Cells[6,11].Value:='事后处理时间';
ExcelAppl.Cells[6,12].Value:='平均值班人员';
ExcelAppl.Range['B6:L6'].interior.colorindex:=15;

ExcelAppl.Cells[7,2].value:='太原';
ExcelAppl.Cells[8,2].value:='大同';
ExcelAppl.Range['B8:L8'].interior.colorindex:=15;

ExcelAppl.Cells[9,2].value:='临汾';
ExcelAppl.Cells[10,2].value:='运城';
ExcelAppl.Range['B10:L10'].interior.colorindex:=15;

ExcelAppl.Cells[11,2].value:='晋城';
ExcelAppl.Cells[12,2].value:='长治';
ExcelAppl.Range['B12:L12'].interior.colorindex:=15;

ExcelAppl.Cells[13,2].value:='晋中';
ExcelAppl.Cells[14,2].value:='阳泉';
ExcelAppl.Range['B14:L14'].interior.colorindex:=15;

ExcelAppl.Cells[15,2].value:='忻州';
ExcelAppl.Cells[16,2].value:='朔州';
ExcelAppl.Range['B16:L16'].interior.colorindex:=15;

ExcelAppl.Cells[17,2].value:='吕梁';


ExcelAppl.Ranges['A20:L20'].Borders[3].LineStyle:=xlContinuous; 1
ExcelAppl.Ranges['A20:L20'].Borders[3].Weight:=xlMedium; -4138
ExcelAppl.Ranges['A20:L20'].Borders[3].ColorIndex:=14;

ExcelAppl.Range['B6:L6'].Borders[xlEdgetop].LineStyle:=xlContinuous;
ExcelAppl.Range['B6:L6'].Borders[xlEdgetop].Weight:=xlMedium;
ExcelAppl.Range['B6:L6'].Borders[xlEdgetop].ColorIndex:=14;

ExcelAppl.Range['B6:L6'].Borders[xlEdgeBottom].LineStyle:=xlContinuous;
ExcelAppl.Range['B6:L6'].Borders[xlEdgeBottom].Weight:=xlMedium;
ExcelAppl.Range['B6:L6'].Borders[xlEdgeBottom].ColorIndex:=14;

ExcelAppl.Range['B17:L17'].Borders[xlEdgeBottom].LineStyle:=xlContinuous;
ExcelAppl.Range['B17:L17'].Borders[xlEdgeBottom].Weight:=xlMedium;
ExcelAppl.Range['B17:L17'].Borders[xlEdgeBottom].ColorIndex:=14;

ExcelAppl.Range['B6,B7,B8,B9,B10,B11,B12,B13,B14,B15,B16,B17'].Borders[xlEdgeleft].LineStyle:=xlContinuous;
ExcelAppl.Range['B6,B7,B8,B9,B10,B11,B12,B13,B14,B15,B16,B17'].Borders[xlEdgeleft].Weight:=xlMedium;
ExcelAppl.Range['B6,B7,B8,B9,B10,B11,B12,B13,B14,B15,B16,B17'].Borders[xlEdgeleft].ColorIndex:=14;

ExcelAppl.Range['L6,L7,L8,L9,L10,L11,L12,L13,L14,L15,L16,L17'].Borders[xlEdgeright].LineStyle:=xlContinuous;
ExcelAppl.Range['L6,L7,L8,L9,L10,L11,L12,L13,L14,L15,L16,L17'].Borders[xlEdgeright].Weight:=xlMedium;
ExcelAppl.Range['L6,L7,L8,L9,L10,L11,L12,L13,L14,L15,L16,L17'].Borders[xlEdgeright].ColorIndex:=14;


ExcelAppl.Range['B6,C6,D6,E6,F6,G6,H6,I6,J6,K6'].Borders[xlEdgeright].LineStyle:=xlContinuous;
ExcelAppl.Range['B6,C6,D6,E6,F6,G6,H6,I6,J6,K6'].Borders[xlEdgeright].Weight:=xlThin;
ExcelAppl.Range['B6,C6,D6,E6,F6,G6,H6,I6,J6,K6'].Borders[xlEdgeright].ColorIndex:=14;

ExcelAppl.Range['B7,C7,D7,E7,F7,G7,H7,I7,J7,K7'].Borders[xlEdgeright].LineStyle:=xlContinuous;
ExcelAppl.Range['B7,C7,D7,E7,F7,G7,H7,I7,J7,K7'].Borders[xlEdgeright].Weight:=xlThin;
ExcelAppl.Range['B7,C7,D7,E7,F7,G7,H7,I7,J7,K7'].Borders[xlEdgeright].ColorIndex:=14;

ExcelAppl.Range['B8,C8,D8,E8,F8,G8,H8,I8,J8,K8'].Borders[xlEdgeright].LineStyle:=xlContinuous;
ExcelAppl.Range['B8,C8,D8,E8,F8,G8,H8,I8,J8,K8'].Borders[xlEdgeright].Weight:=xlThin;
ExcelAppl.Range['B8,C8,D8,E8,F8,G8,H8,I8,J8,K8'].Borders[xlEdgeright].ColorIndex:=14;

ExcelAppl.Range['B9,C9,D9,E9,F9,G9,H9,I9,J9,K9'].Borders[xlEdgeright].LineStyle:=xlContinuous;
ExcelAppl.Range['B9,C9,D9,E9,F9,G9,H9,I9,J9,K9'].Borders[xlEdgeright].Weight:=xlThin;
ExcelAppl.Range['B9,C9,D9,E9,F9,G9,H9,I9,J9,K9'].Borders[xlEdgeright].ColorIndex:=14;

ExcelAppl.Range['B10,C10,D10,E10,F10,G10,H10,I10,J10,K10'].Borders[xlEdgeright].LineStyle:=xlContinuous;
ExcelAppl.Range['B10,C10,D10,E10,F10,G10,H10,I10,J10,K10'].Borders[xlEdgeright].Weight:=xlThin;
ExcelAppl.Range['B10,C10,D10,E10,F10,G10,H10,I10,J10,K10'].Borders[xlEdgeright].ColorIndex:=14;

ExcelAppl.Range['B11,C11,D11,E11,F11,G11,H11,I11,J11,K11'].Borders[xlEdgeright].LineStyle:=xlContinuous;
ExcelAppl.Range['B11,C11,D11,E11,F11,G11,H11,I11,J11,K11'].Borders[xlEdgeright].Weight:=xlThin;
ExcelAppl.Range['B11,C11,D11,E11,F11,G11,H11,I11,J11,K11'].Borders[xlEdgeright].ColorIndex:=14;

ExcelAppl.Range['B12,C12,D12,E12,F12,G12,H12,I12,J12,K12'].Borders[xlEdgeright].LineStyle:=xlContinuous;
ExcelAppl.Range['B12,C12,D12,E12,F12,G12,H12,I12,J12,K12'].Borders[xlEdgeright].Weight:=xlThin;
ExcelAppl.Range['B12,C12,D12,E12,F12,G12,H12,I12,J12,K12'].Borders[xlEdgeright].ColorIndex:=14;

ExcelAppl.Range['B13,C13,D13,E13,F13,G13,H13,I13,J13,K13'].Borders[xlEdgeright].LineStyle:=xlContinuous;
ExcelAppl.Range['B13,C13,D13,E13,F13,G13,H13,I13,J13,K13'].Borders[xlEdgeright].Weight:=xlThin;
ExcelAppl.Range['B13,C13,D13,E13,F13,G13,H13,I13,J13,K13'].Borders[xlEdgeright].ColorIndex:=14;

ExcelAppl.Range['B14,C14,D14,E14,F14,G14,H14,I14,J14,K14'].Borders[xlEdgeright].LineStyle:=xlContinuous;
ExcelAppl.Range['B14,C14,D14,E14,F14,G14,H14,I14,J14,K14'].Borders[xlEdgeright].Weight:=xlThin;
ExcelAppl.Range['B14,C14,D14,E14,F14,G14,H14,I14,J14,K14'].Borders[xlEdgeright].ColorIndex:=14;

ExcelAppl.Range['B15,C15,D15,E15,F15,G15,H15,I15,J15,K15'].Borders[xlEdgeright].LineStyle:=xlContinuous;
ExcelAppl.Range['B15,C15,D15,E15,F15,G15,H15,I15,J15,K15'].Borders[xlEdgeright].Weight:=xlThin;
ExcelAppl.Range['B15,C15,D15,E15,F15,G15,H15,I15,J15,K15'].Borders[xlEdgeright].ColorIndex:=14;

ExcelAppl.Range['B16,C16,D16,E16,F16,G16,H16,I16,J16,K16'].Borders[xlEdgeright].LineStyle:=xlContinuous;
ExcelAppl.Range['B16,C16,D16,E16,F16,G16,H16,I16,J16,K16'].Borders[xlEdgeright].Weight:=xlThin;
ExcelAppl.Range['B16,C16,D16,E16,F16,G16,H16,I16,J16,K16'].Borders[xlEdgeright].ColorIndex:=14;

ExcelAppl.Range['B17,C17,D17,E17,F17,G17,H17,I17,J17,K17'].Borders[xlEdgeright].LineStyle:=xlContinuous;
ExcelAppl.Range['B17,C17,D17,E17,F17,G17,H17,I17,J17,K17'].Borders[xlEdgeright].Weight:=xlThin;
ExcelAppl.Range['B17,C17,D17,E17,F17,G17,H17,I17,J17,K17'].Borders[xlEdgeright].ColorIndex:=14;

ExcelAppl.Range['B8:L8'].Borders[xlEdgetop].LineStyle:=xlContinuous;
ExcelAppl.Range['B8:L8'].Borders[xlEdgetop].Weight:=xlThin;
ExcelAppl.Range['B8:L8'].Borders[xlEdgetop].ColorIndex:=14;

ExcelAppl.Range['B9:L9'].Borders[xlEdgetop].LineStyle:=xlContinuous;
ExcelAppl.Range['B9:L9'].Borders[xlEdgetop].Weight:=xlThin;
ExcelAppl.Range['B9:L9'].Borders[xlEdgetop].ColorIndex:=14;

ExcelAppl.Range['B10:L10'].Borders[xlEdgetop].LineStyle:=xlContinuous;
ExcelAppl.Range['B10:L10'].Borders[xlEdgetop].Weight:=xlThin;
ExcelAppl.Range['B10:L10'].Borders[xlEdgetop].ColorIndex:=14;

ExcelAppl.Range['B11:L11'].Borders[xlEdgetop].LineStyle:=xlContinuous;
ExcelAppl.Range['B11:L11'].Borders[xlEdgetop].Weight:=xlThin;
ExcelAppl.Range['B11:L11'].Borders[xlEdgetop].ColorIndex:=14;

ExcelAppl.Range['B12:L12'].Borders[xlEdgetop].LineStyle:=xlContinuous;
ExcelAppl.Range['B12:L12'].Borders[xlEdgetop].Weight:=xlThin;
ExcelAppl.Range['B12:L12'].Borders[xlEdgetop].ColorIndex:=14;

ExcelAppl.Range['B13:L13'].Borders[xlEdgetop].LineStyle:=xlContinuous;
ExcelAppl.Range['B13:L13'].Borders[xlEdgetop].Weight:=xlThin;
ExcelAppl.Range['B13:L13'].Borders[xlEdgetop].ColorIndex:=14;

ExcelAppl.Range['B13:L13'].Borders[xlEdgetop].LineStyle:=xlContinuous;
ExcelAppl.Range['B13:L13'].Borders[xlEdgetop].Weight:=xlThin;
ExcelAppl.Range['B13:L13'].Borders[xlEdgetop].ColorIndex:=14;

ExcelAppl.Range['B14:L14'].Borders[xlEdgetop].LineStyle:=xlContinuous;
ExcelAppl.Range['B14:L14'].Borders[xlEdgetop].Weight:=xlThin;
ExcelAppl.Range['B14:L14'].Borders[xlEdgetop].ColorIndex:=14;

ExcelAppl.Range['B15:L15'].Borders[xlEdgetop].LineStyle:=xlContinuous;
ExcelAppl.Range['B15:L15'].Borders[xlEdgetop].Weight:=xlThin;
ExcelAppl.Range['B15:L15'].Borders[xlEdgetop].ColorIndex:=14;

ExcelAppl.Range['B16:L16'].Borders[xlEdgetop].LineStyle:=xlContinuous;
ExcelAppl.Range['B16:L16'].Borders[xlEdgetop].Weight:=xlThin;
ExcelAppl.Range['B16:L16'].Borders[xlEdgetop].ColorIndex:=14;

ExcelAppl.Range['B17:L17'].Borders[xlEdgetop].LineStyle:=xlContinuous;
ExcelAppl.Range['B17:L17'].Borders[xlEdgetop].Weight:=xlThin;
ExcelAppl.Range['B17:L17'].Borders[xlEdgetop].ColorIndex:=14;

for i:=7 to 17 do
begin
ExcelAppl.worksheets[1].Rows[IntToStr(i)].RowHeight := 15;
ExcelAppl.worksheets[1].Rows[IntToStr(i)].HorizontalAlignment:=-4108;
ExcelAppl.worksheets[1].Rows[IntToStr(i)].VerticalAlignment:=-4108;
ExcelAppl.WorkSheets[1].Rows[IntToStr(i)].wraptext:=true;
end;
ExcelAppl.worksheets[1].Range['B6,B7,B8,B9,B10,B11,B12,B13,B14,B15,B16,B17'].Font.Name:='宋体';
ExcelAppl.worksheets[1].Range['B6,B7,B8,B9,B10,B11,B12,B13,B14,B15,B16,B17'].Font.Size:=10;
// ExcelAppl.worksheets[1].Range['B6,B7,B8,B9,B10,B11,B12,B13,B14,B15,B16,B17'].Font.Bold:=fsBold;


// ExcelAppl.Range['A6:B6'].Borders[xlEdgeleft].LineStyle:=xlContinuous;
// ExcelAppl.Range['A6:B6'].Borders[xlEdgeleft].Weight:=xlMedium;
// ExcelAppl.Range['A6:B6'].Borders[xlEdgeleft].ColorIndex:=14;

// ExcelAppl.Range['A6:B6'].Borders[xlEdgeRight].LineStyle:=xlContinuous;
// ExcelAppl.Range['A6:B6'].Borders[xlEdgeRight].Weight:=xlMedium;
// ExcelAppl.Range['A6:B6'].Borders[xlEdgeRight].ColorIndex:=14;

ExcelAppL.Range['A6:c6'].Borders[xlInsideVertical].LineStyle:=xlContinuous;
ExcelAppL.Range['A6:c6'].Borders[xlInsideVertical].Weight:=xlThin;
ExcelAppL.Range['A6:c6'].Borders[xlInsideVertical].ColorIndex:=14;

ExcelAppL.Range['A6:c7'].Borders[xlInsideHorizontal].LineStyle:=xlContinuous;
ExcelAppL.Range['A6:c7'].Borders[xlInsideHorizontal].Weight:=xlThin;
ExcelAppL.Range['A6:c7'].Borders[xlInsideHorizontal].ColorIndex:=14;
// ExcelAppL.Quit;

end;

end.
 
给你个例子:
procedure TFrmMain.OperateExcel;
var
r: integer;
begin
//把EXCEL表做为数据表导入DBGRID中显示出来。
try
if adoconnection1.Connected then adoconnection1.Connected := False;
adoconnection1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;'
+ 'Data Source=' + Filepaths + ';Mode=Share Deny None;Extended Properties=excel 8.0;'
+ 'Jet OLEDB:System database="";Jet OLEDB:Registry Path="";Jet OLEDB:Database Password="";'
+ 'Jet OLEDB:Engine Type=35;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;'
+ 'Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="";Jet OLEDB:Create System Database=False;'
+ 'Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don' + #39 + 't Copy Locale on Compact=False;'
+ 'Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False';
// showmessage(adoconnection3.ConnectionString);
adoconnection1.Connected := True;
except
Application.MessageBox('连接Excel文件失败,请退出重试!', '提示信息', mb_ok or mb_iconwarning);
Exit;
end;
with adoquery1 do
begin
close;
sql.Text := 'select * from [sheet1$]';
open;
end;
with dbgrid2 do
begin
for r := 0 to columns.Count - 1 do
columns[r].Width := 100;
end;
Flag := 'excel';
E2.SetFocus;
end;
 
后退
顶部