var
FileName, s: String;
i,n:integer;
excelapp:Variant;
Temp_Worksheet: _WorkSheet;
begin
excelapp := CreateOleObject('excel.application');
excelapp.Visible := true;
excelapp.Caption := '临床路径每天执行情况表';
ExcelApp.WorkBooks.Add;
ExcelApp.WorkSheets[2].Activate;
//导出
if Self.qry_pat.RecordCount = 0 then
begin
s := '没有导出数据...';
Application.MessageBox(PChar(s), PChar(Application.Title),
MB_OK or MB_ICONERROR);
Exit;
end;
Application.ProcessMessages;
excelapp.Range['a1', 'a'+inttostr(qry_pat.RecordCount)].ColumnWidth := 20;
excelapp.cells.Item[1,1] := qry_pat.Fields[1].FieldName;
excelapp.Cells.Item[1,1].Font.name := '宋体';
excelapp.Cells.Item[1,1].Font.bold := true;
excelapp.Cells.Item[1,1].orientation := xlhorizontal;
excelapp.Cells.Item[1,1].verticalAlignment := xlTop;
excelapp.Cells.Item[1,1].font.size := 11;
excelapp.cells.Item[1,2] := qry_pat.Fields[2].FieldName;
excelapp.Cells.Item[1,2].Font.name := '宋体';
excelapp.Cells.Item[1,2].Font.bold := true;
excelapp.Cells.Item[1,2].orientation := xlhorizontal;
excelapp.Cells.Item[1,2].verticalAlignment := xlTop;
excelapp.Cells.Item[1,2].font.size := 11;
excelapp.cells.Item[1,3] := qry_pat.Fields[3].FieldName;
excelapp.Cells.Item[1,3].Font.name := '宋体';
excelapp.Cells.Item[1,3].Font.bold := true;
excelapp.Cells.Item[1,3].orientation := xlhorizontal;
excelapp.Cells.Item[1,3].verticalAlignment := xlTop;
excelapp.Cells.Item[1,3].font.size := 11;
excelapp.cells.Item[1,4] := qry_pat.Fields[4].FieldName;
excelapp.Cells.Item[1,4].Font.name := '宋体';
excelapp.Cells.Item[1,4].Font.bold := true;
excelapp.Cells.Item[1,4].orientation := xlhorizontal;
excelapp.Cells.Item[1,4].verticalAlignment := xlTop;
excelapp.Cells.Item[1,4].font.size := 11;
excelapp.cells.Item[1,5] := qry_pat.Fields[5].FieldName;
excelapp.Cells.Item[1,5].Font.name := '宋体';
excelapp.Cells.Item[1,5].Font.bold := true;
excelapp.Cells.Item[1,5].orientation := xlhorizontal;
excelapp.Cells.Item[1,5].verticalAlignment := xlTop;
excelapp.Cells.Item[1,5].font.size := 11;
excelapp.cells.Item[1,6] := qry_pat.Fields[6].FieldName;
excelapp.Cells.Item[1,6].Font.name := '宋体';
excelapp.Cells.Item[1,6].Font.bold := true;
excelapp.Cells.Item[1,6].orientation := xlhorizontal;
excelapp.Cells.Item[1,6].verticalAlignment := xlTop;
excelapp.Cells.Item[1,6].font.size := 11;
excelapp.cells.Item[1,7] := qry_pat.Fields[7].FieldName;
excelapp.Cells.Item[1,7].Font.name := '宋体';
excelapp.Cells.Item[1,7].Font.bold := true;
excelapp.Cells.Item[1,7].orientation := xlhorizontal;
excelapp.Cells.Item[1,7].verticalAlignment := xlTop;
excelapp.Cells.Item[1,7].font.size := 11;
excelapp.cells.Item[1,8] := qry_pat.Fields[8].FieldName;
excelapp.Cells.Item[1,8].Font.name := '宋体';
excelapp.Cells.Item[1,8].Font.bold := true;
excelapp.Cells.Item[1,8].orientation := xlhorizontal;
excelapp.Cells.Item[1,8].verticalAlignment := xlTop;
excelapp.Cells.Item[1,8].font.size := 11;
excelapp.cells.Item[1,9] := qry_pat.Fields[9].FieldName;
excelapp.Cells.Item[1,9].Font.name := '宋体';
excelapp.Cells.Item[1,9].Font.bold := true;
excelapp.Cells.Item[1,9].orientation := xlhorizontal;
excelapp.Cells.Item[1,9].verticalAlignment := xlTop;
excelapp.Cells.Item[1,9].font.size := 11;
qry_pat.First;
n := 2;
while not qry_pat.eof do
begin
excelapp.cells.Item[n,1] := qry_pat.Fields[1].AsString;
excelapp.Cells.Item[n,1].Font.name := '宋体';
excelapp.Cells.Item[n,1].Font.bold := true;
excelapp.Cells.Item[n,1].orientation := xlhorizontal;
excelapp.Cells.Item[n,1].verticalAlignment := xlTop;
excelapp.Cells.Item[n,1].font.size := 11;
excelapp.Cells.Item[n,1].wraptext := true;
excelapp.cells.Item[n,2] := qry_pat.Fields[2].AsString;
excelapp.Cells.Item[n,2].Font.name := '宋体';
excelapp.Cells.Item[n,2].Font.bold := true;
excelapp.Cells.Item[n,2].orientation := xlhorizontal;
excelapp.Cells.Item[n,2].verticalAlignment := xlTop;
excelapp.Cells.Item[n,2].font.size := 11;
excelapp.Cells.Item[n,2].wraptext := true;
excelapp.cells.Item[n,3] := qry_pat.Fields[3].AsString;
excelapp.Cells.Item[n,3].Font.name := '宋体';
excelapp.Cells.Item[n,3].Font.bold := true;
excelapp.Cells.Item[n,3].orientation := xlhorizontal;
excelapp.Cells.Item[n,3].verticalAlignment := xlTop;
excelapp.Cells.Item[n,3].font.size := 11;
excelapp.Cells.Item[n,3].wraptext := true;
excelapp.cells.Item[n,4] := qry_pat.Fields[4].AsString;
excelapp.Cells.Item[n,4].Font.name := '宋体';
excelapp.Cells.Item[n,4].Font.bold := true;
excelapp.Cells.Item[n,4].orientation := xlhorizontal;
excelapp.Cells.Item[n,4].verticalAlignment := xlTop;
excelapp.Cells.Item[n,4].font.size := 11;
excelapp.Cells.Item[n,4].wraptext := true;
excelapp.cells.Item[n,5] := qry_pat.Fields[5].AsString;
excelapp.Cells.Item[n,5].Font.name := '宋体';
excelapp.Cells.Item[n,5].Font.bold := true;
excelapp.Cells.Item[n,5].orientation := xlhorizontal;
excelapp.Cells.Item[n,5].verticalAlignment := xlTop;
excelapp.Cells.Item[n,5].font.size := 11;
excelapp.Cells.Item[n,5].wraptext := true;
excelapp.cells.Item[n,6] := qry_pat.Fields[6].AsString;
excelapp.Cells.Item[n,6].Font.name := '宋体';
excelapp.Cells.Item[n,6].Font.bold := true;
excelapp.Cells.Item[n,6].orientation := xlhorizontal;
excelapp.Cells.Item[n,6].verticalAlignment := xlTop;
excelapp.Cells.Item[n,6].font.size := 11;
excelapp.Cells.Item[n,6].wraptext := true;
excelapp.cells.Item[n,7] := qry_pat.Fields[7].AsString;
excelapp.Cells.Item[n,7].Font.name := '宋体';
excelapp.Cells.Item[n,7].Font.bold := true;
excelapp.Cells.Item[n,7].orientation := xlhorizontal;
excelapp.Cells.Item[n,7].verticalAlignment := xlTop;
excelapp.Cells.Item[n,7].font.size := 11;
excelapp.Cells.Item[n,7].wraptext := true;
excelapp.cells.Item[n,8] := qry_pat.Fields[8].AsString;
excelapp.Cells.Item[n,8].Font.name := '宋体';
excelapp.Cells.Item[n,8].Font.bold := true;
excelapp.Cells.Item[n,8].orientation := xlhorizontal;
excelapp.Cells.Item[n,8].verticalAlignment := xlTop;
excelapp.Cells.Item[n,8].font.size := 11;
excelapp.Cells.Item[n,8].wraptext := true;
excelapp.cells.Item[n,9] := qry_pat.Fields[9].AsString;
excelapp.Cells.Item[n,9].Font.name := '宋体';
excelapp.Cells.Item[n,9].Font.bold := true;
excelapp.Cells.Item[n,9].orientation := xlhorizontal;
excelapp.Cells.Item[n,9].verticalAlignment := xlTop;
excelapp.Cells.Item[n,9].font.size := 11;
excelapp.Cells.Item[n,9].wraptext := true;
inc(n);
qry_pat.Next;
end;
// xlWorksheet.cells.Item[n+qry_medicalorder.recordcount,1] := '';
SaveDialogExport.Filter := 'Excel文件 (*.xls)';
SaveDialogExport.Title := '导出为';
if excelapp.activeworkbook.saved then
begin
ExcelApp.ActiveSheet.PrintPreview;
ExcelApp.WorkBooks.Close;
ExcelApp.Quit;
Screen.Cursor := crDefault;
// Application.ProcessMessages;
s := '导出完成...';
Application.MessageBox(PChar(s), PChar(Application.Title),
MB_OK or MB_IconInformation);
FileName, s: String;
i,n:integer;
excelapp:Variant;
Temp_Worksheet: _WorkSheet;
begin
excelapp := CreateOleObject('excel.application');
excelapp.Visible := true;
excelapp.Caption := '临床路径每天执行情况表';
ExcelApp.WorkBooks.Add;
ExcelApp.WorkSheets[2].Activate;
//导出
if Self.qry_pat.RecordCount = 0 then
begin
s := '没有导出数据...';
Application.MessageBox(PChar(s), PChar(Application.Title),
MB_OK or MB_ICONERROR);
Exit;
end;
Application.ProcessMessages;
excelapp.Range['a1', 'a'+inttostr(qry_pat.RecordCount)].ColumnWidth := 20;
excelapp.cells.Item[1,1] := qry_pat.Fields[1].FieldName;
excelapp.Cells.Item[1,1].Font.name := '宋体';
excelapp.Cells.Item[1,1].Font.bold := true;
excelapp.Cells.Item[1,1].orientation := xlhorizontal;
excelapp.Cells.Item[1,1].verticalAlignment := xlTop;
excelapp.Cells.Item[1,1].font.size := 11;
excelapp.cells.Item[1,2] := qry_pat.Fields[2].FieldName;
excelapp.Cells.Item[1,2].Font.name := '宋体';
excelapp.Cells.Item[1,2].Font.bold := true;
excelapp.Cells.Item[1,2].orientation := xlhorizontal;
excelapp.Cells.Item[1,2].verticalAlignment := xlTop;
excelapp.Cells.Item[1,2].font.size := 11;
excelapp.cells.Item[1,3] := qry_pat.Fields[3].FieldName;
excelapp.Cells.Item[1,3].Font.name := '宋体';
excelapp.Cells.Item[1,3].Font.bold := true;
excelapp.Cells.Item[1,3].orientation := xlhorizontal;
excelapp.Cells.Item[1,3].verticalAlignment := xlTop;
excelapp.Cells.Item[1,3].font.size := 11;
excelapp.cells.Item[1,4] := qry_pat.Fields[4].FieldName;
excelapp.Cells.Item[1,4].Font.name := '宋体';
excelapp.Cells.Item[1,4].Font.bold := true;
excelapp.Cells.Item[1,4].orientation := xlhorizontal;
excelapp.Cells.Item[1,4].verticalAlignment := xlTop;
excelapp.Cells.Item[1,4].font.size := 11;
excelapp.cells.Item[1,5] := qry_pat.Fields[5].FieldName;
excelapp.Cells.Item[1,5].Font.name := '宋体';
excelapp.Cells.Item[1,5].Font.bold := true;
excelapp.Cells.Item[1,5].orientation := xlhorizontal;
excelapp.Cells.Item[1,5].verticalAlignment := xlTop;
excelapp.Cells.Item[1,5].font.size := 11;
excelapp.cells.Item[1,6] := qry_pat.Fields[6].FieldName;
excelapp.Cells.Item[1,6].Font.name := '宋体';
excelapp.Cells.Item[1,6].Font.bold := true;
excelapp.Cells.Item[1,6].orientation := xlhorizontal;
excelapp.Cells.Item[1,6].verticalAlignment := xlTop;
excelapp.Cells.Item[1,6].font.size := 11;
excelapp.cells.Item[1,7] := qry_pat.Fields[7].FieldName;
excelapp.Cells.Item[1,7].Font.name := '宋体';
excelapp.Cells.Item[1,7].Font.bold := true;
excelapp.Cells.Item[1,7].orientation := xlhorizontal;
excelapp.Cells.Item[1,7].verticalAlignment := xlTop;
excelapp.Cells.Item[1,7].font.size := 11;
excelapp.cells.Item[1,8] := qry_pat.Fields[8].FieldName;
excelapp.Cells.Item[1,8].Font.name := '宋体';
excelapp.Cells.Item[1,8].Font.bold := true;
excelapp.Cells.Item[1,8].orientation := xlhorizontal;
excelapp.Cells.Item[1,8].verticalAlignment := xlTop;
excelapp.Cells.Item[1,8].font.size := 11;
excelapp.cells.Item[1,9] := qry_pat.Fields[9].FieldName;
excelapp.Cells.Item[1,9].Font.name := '宋体';
excelapp.Cells.Item[1,9].Font.bold := true;
excelapp.Cells.Item[1,9].orientation := xlhorizontal;
excelapp.Cells.Item[1,9].verticalAlignment := xlTop;
excelapp.Cells.Item[1,9].font.size := 11;
qry_pat.First;
n := 2;
while not qry_pat.eof do
begin
excelapp.cells.Item[n,1] := qry_pat.Fields[1].AsString;
excelapp.Cells.Item[n,1].Font.name := '宋体';
excelapp.Cells.Item[n,1].Font.bold := true;
excelapp.Cells.Item[n,1].orientation := xlhorizontal;
excelapp.Cells.Item[n,1].verticalAlignment := xlTop;
excelapp.Cells.Item[n,1].font.size := 11;
excelapp.Cells.Item[n,1].wraptext := true;
excelapp.cells.Item[n,2] := qry_pat.Fields[2].AsString;
excelapp.Cells.Item[n,2].Font.name := '宋体';
excelapp.Cells.Item[n,2].Font.bold := true;
excelapp.Cells.Item[n,2].orientation := xlhorizontal;
excelapp.Cells.Item[n,2].verticalAlignment := xlTop;
excelapp.Cells.Item[n,2].font.size := 11;
excelapp.Cells.Item[n,2].wraptext := true;
excelapp.cells.Item[n,3] := qry_pat.Fields[3].AsString;
excelapp.Cells.Item[n,3].Font.name := '宋体';
excelapp.Cells.Item[n,3].Font.bold := true;
excelapp.Cells.Item[n,3].orientation := xlhorizontal;
excelapp.Cells.Item[n,3].verticalAlignment := xlTop;
excelapp.Cells.Item[n,3].font.size := 11;
excelapp.Cells.Item[n,3].wraptext := true;
excelapp.cells.Item[n,4] := qry_pat.Fields[4].AsString;
excelapp.Cells.Item[n,4].Font.name := '宋体';
excelapp.Cells.Item[n,4].Font.bold := true;
excelapp.Cells.Item[n,4].orientation := xlhorizontal;
excelapp.Cells.Item[n,4].verticalAlignment := xlTop;
excelapp.Cells.Item[n,4].font.size := 11;
excelapp.Cells.Item[n,4].wraptext := true;
excelapp.cells.Item[n,5] := qry_pat.Fields[5].AsString;
excelapp.Cells.Item[n,5].Font.name := '宋体';
excelapp.Cells.Item[n,5].Font.bold := true;
excelapp.Cells.Item[n,5].orientation := xlhorizontal;
excelapp.Cells.Item[n,5].verticalAlignment := xlTop;
excelapp.Cells.Item[n,5].font.size := 11;
excelapp.Cells.Item[n,5].wraptext := true;
excelapp.cells.Item[n,6] := qry_pat.Fields[6].AsString;
excelapp.Cells.Item[n,6].Font.name := '宋体';
excelapp.Cells.Item[n,6].Font.bold := true;
excelapp.Cells.Item[n,6].orientation := xlhorizontal;
excelapp.Cells.Item[n,6].verticalAlignment := xlTop;
excelapp.Cells.Item[n,6].font.size := 11;
excelapp.Cells.Item[n,6].wraptext := true;
excelapp.cells.Item[n,7] := qry_pat.Fields[7].AsString;
excelapp.Cells.Item[n,7].Font.name := '宋体';
excelapp.Cells.Item[n,7].Font.bold := true;
excelapp.Cells.Item[n,7].orientation := xlhorizontal;
excelapp.Cells.Item[n,7].verticalAlignment := xlTop;
excelapp.Cells.Item[n,7].font.size := 11;
excelapp.Cells.Item[n,7].wraptext := true;
excelapp.cells.Item[n,8] := qry_pat.Fields[8].AsString;
excelapp.Cells.Item[n,8].Font.name := '宋体';
excelapp.Cells.Item[n,8].Font.bold := true;
excelapp.Cells.Item[n,8].orientation := xlhorizontal;
excelapp.Cells.Item[n,8].verticalAlignment := xlTop;
excelapp.Cells.Item[n,8].font.size := 11;
excelapp.Cells.Item[n,8].wraptext := true;
excelapp.cells.Item[n,9] := qry_pat.Fields[9].AsString;
excelapp.Cells.Item[n,9].Font.name := '宋体';
excelapp.Cells.Item[n,9].Font.bold := true;
excelapp.Cells.Item[n,9].orientation := xlhorizontal;
excelapp.Cells.Item[n,9].verticalAlignment := xlTop;
excelapp.Cells.Item[n,9].font.size := 11;
excelapp.Cells.Item[n,9].wraptext := true;
inc(n);
qry_pat.Next;
end;
// xlWorksheet.cells.Item[n+qry_medicalorder.recordcount,1] := '';
SaveDialogExport.Filter := 'Excel文件 (*.xls)';
SaveDialogExport.Title := '导出为';
if excelapp.activeworkbook.saved then
begin
ExcelApp.ActiveSheet.PrintPreview;
ExcelApp.WorkBooks.Close;
ExcelApp.Quit;
Screen.Cursor := crDefault;
// Application.ProcessMessages;
s := '导出完成...';
Application.MessageBox(PChar(s), PChar(Application.Title),
MB_OK or MB_IconInformation);
end;
本文转自鹅倌51CTO博客,原文链接:http://blog.51cto.com/kaixinbuliao/1119516 ,如需转载请自行联系原作者