最好是范例啊~~谢谢~~~~
解决方案 »
- delphi DirectX3D 实现摄像机旋转
- 安装了DevExpress_ExpressQuantumGrid4.5的版本,在安装4.11的就不行了,怎么删除啊?
- 一次性把tiff格式的图像文件转换为gif格式,求救
- 雅虎1.2亿美元收购 3721 (3721 一路好走)
- TIDHttp控件在那里有?我看帮助里有但控件页上没有?
- 求在delphi里面更新的语句!!!在线等待!!!!
- 横向打印问题
- 阿劳,阿弟,快点来帮帮忙!!
- 实用程序???
- delphi的帮助应该怎么阅读?我怎么找不到头绪,另外sdk什么意思??
- SOS,请各位高手如何通过程序控制扫描仪啊?
- 菜鸟问题,太简单了,各位帮忙啊!
MakeDataSource: TDataSource; makeDBGrid: TDBGrid);
var
xlApp, xlSheet, szValue: Variant;
ARow, iLoop: word;
begin
xlApp := CreateOleObject('Excel.Application');
try
xlSheet := CreateOleObject('Excel.Sheet');
xlSheet := xlApp.WorkBooks.Add;
// 主标题
xlSheet.WorkSheets[1].Cells[1,1] := TitleCaption;
// 表格标题
for iLoop := 0 to makeDBGridEh.Columns.Count - 1 do
xlSheet.WorkSheets[1].Cells[2, iLoop+1] := makeDBGridEh.Columns[iLoop].Title.Caption; // 数据
ARow := 3;
with MakeDataSource.DataSet do
begin
DisableControls;
First;
while not Eof do
begin
for iLoop := 0 to Fields.Count - 1 do
begin
szValue := Fields[iLoop].Value;
xlSheet.WorkSheets[1].Cells[ARow, iLoop+1] := szValue;
end;
Inc(ARow);
Next;
end;
First;
EnableControls;
end; try
xlSheet.SaveAs(FileName);
Application.MessageBox('导出完毕!', '提示', MB_IconExclamation);
finally
xlSheet.Close;
xlApp.Quit;
xlApp := UnAssigned;
end;
except
MessageBox(handle, '本机没有安装Excel.', '提示',MB_IconExclamation);
end;end;
var
i,row:integer;
j:Int64;
Excel:variant;
begin
If (Query1.Active = False) or (Query1.RecordCount = 0) Then Exit; Excel:=UnAssigned;
Try
Excel:=CreateOleObject('Excel.Application');
Except
Application.MessageBox('Excel应用程序没有找到,系统不能将数据导入Excel!','错误',MB_OK + MB_ICONERROR);
Exit;
End;
Excel.Visible:=True;
Excel.DisplayAlerts:=false;
Excel.WorkBooks.Add;
// RefreshInfo;
SetForegroundWindow(Handle);
Excel.Caption:='考勤日报';
Excel.Cells[1,1]:=P_gsid;
Excel.Cells[2,1]:='考勤日报';
For I:=0 to DbGrid1.Columns.Count - 1 do
// ExcelWorksheet1.Cells.Item[5,I+1]:=DbGrid1.Columns[I].Title.Caption;
Excel.Cells[5,I+1]:=DbGrid1.Columns[I].Title.Caption;
Row:=6;
Query1.First;
While Not Query1.Eof do
begin
Application.ProcessMessages;
For I:=0 to DbGrid1.Columns.Count - 1 do
Excel.Cells[Row,I+1]:=''''+Query1.FieldByName(DbGrid1.Columns[I].FieldName).AsString;
Query1.Next;
Row:=Row+1;
end;
end;