delphi使用ado导出excel(2)

简介:
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);

  end;














本文转自鹅倌51CTO博客,原文链接:http://blog.51cto.com/kaixinbuliao/1119516 ,如需转载请自行联系原作者



相关文章
|
7天前
|
文字识别 BI
【图片型PDF】批量识别扫描件PDF指定区域局部位置内容,将识别内容导出Excel表格或批量改名文件,基于阿里云OCR对图片型PDF识别改名案例实现
在医疗和政务等领域,图片型PDF文件(如病历、报告、公文扫描件)的处理需求广泛。通过OCR技术识别这些文件中的文字信息,提取关键内容并保存为表格,极大提高了信息管理和利用效率。本文介绍一款工具——咕嘎批量OCR系统,帮助用户快速处理图片型PDF文件,支持区域识别、内容提取、导出表格及批量改名等功能。下载工具后,按步骤选择处理模式、进行区域采样、批量处理文件,几分钟内即可高效完成数百个文件的处理。
49 8
|
3月前
|
前端开发
实现Excel文件和其他文件导出为压缩包,并导入
实现Excel文件和其他文件导出为压缩包,并导入
50 1
|
3月前
|
数据格式 UED
记录一次NPOI库导出Excel遇到的小问题解决方案
【11月更文挑战第16天】本文记录了使用 NPOI 库导出 Excel 过程中遇到的三个主要问题及其解决方案:单元格数据格式错误、日期格式不正确以及合并单元格边框缺失。通过自定义单元格样式、设置数据格式和手动添加边框,有效解决了这些问题,提升了导出文件的质量和用户体验。
328 3
|
3月前
|
Java API Apache
|
3月前
|
存储 Java API
Java实现导出多个excel表打包到zip文件中,供客户端另存为窗口下载
Java实现导出多个excel表打包到zip文件中,供客户端另存为窗口下载
172 4
|
2月前
|
存储 Java easyexcel
招行面试:100万级别数据的Excel,如何秒级导入到数据库?
本文由40岁老架构师尼恩撰写,分享了应对招商银行Java后端面试绝命12题的经验。文章详细介绍了如何通过系统化准备,在面试中展示强大的技术实力。针对百万级数据的Excel导入难题,尼恩推荐使用阿里巴巴开源的EasyExcel框架,并结合高性能分片读取、Disruptor队列缓冲和高并发批量写入的架构方案,实现高效的数据处理。此外,文章还提供了完整的代码示例和配置说明,帮助读者快速掌握相关技能。建议读者参考《尼恩Java面试宝典PDF》进行系统化刷题,提升面试竞争力。关注公众号【技术自由圈】可获取更多技术资源和指导。
|
2月前
|
数据采集 数据可视化 数据挖掘
利用Python自动化处理Excel数据:从基础到进阶####
本文旨在为读者提供一个全面的指南,通过Python编程语言实现Excel数据的自动化处理。无论你是初学者还是有经验的开发者,本文都将帮助你掌握Pandas和openpyxl这两个强大的库,从而提升数据处理的效率和准确性。我们将从环境设置开始,逐步深入到数据读取、清洗、分析和可视化等各个环节,最终实现一个实际的自动化项目案例。 ####
305 10
|
4月前
|
数据处理 Python
Python实用记录(十):获取excel数据并通过列表的形式保存为txt文档、xlsx文档、csv文档
这篇文章介绍了如何使用Python读取Excel文件中的数据,处理后将其保存为txt、xlsx和csv格式的文件。
268 3
Python实用记录(十):获取excel数据并通过列表的形式保存为txt文档、xlsx文档、csv文档
|
4月前
|
easyexcel Java UED
SpringBoot中大量数据导出方案:使用EasyExcel并行导出多个excel文件并压缩zip后下载
在SpringBoot环境中,为了优化大量数据的Excel导出体验,可采用异步方式处理。具体做法是将数据拆分后利用`CompletableFuture`与`ThreadPoolTaskExecutor`并行导出,并使用EasyExcel生成多个Excel文件,最终将其压缩成ZIP文件供下载。此方案提升了导出效率,改善了用户体验。代码示例展示了如何实现这一过程,包括多线程处理、模板导出及资源清理等关键步骤。
|
4月前
|
数据采集 存储 JavaScript
自动化数据处理:使用Selenium与Excel打造的数据爬取管道
本文介绍了一种使用Selenium和Excel结合代理IP技术从WIPO品牌数据库(branddb.wipo.int)自动化爬取专利信息的方法。通过Selenium模拟用户操作,处理JavaScript动态加载页面,利用代理IP避免IP封禁,确保数据爬取稳定性和隐私性。爬取的数据将存储在Excel中,便于后续分析。此外,文章还详细介绍了Selenium的基本设置、代理IP配置及使用技巧,并探讨了未来可能采用的更多防反爬策略,以提升爬虫效率和稳定性。
260 4

热门文章

最新文章