zoukankan      html  css  js  c++  java
  • delphi中TStringGrid数据的导出

    没什么好说的,就是一个导出Excel的功能,代码如下:

    function TExportToExcel.Export(SGrid_List: TStringGrid;filename:string;out Errstr:string): Boolean;
    var
      excelapp:Variant;
      page:Variant;
      i,j:Integer;
      savedialog:TSaveDialog;
      strsavefile:string;
    begin
      try
        result := false;
        savedialog := TSaveDialog.Create(self);
        try
          savedialog.FileName := filename;
          savedialog.Filter := '*.xls';
          if not savedialog.Execute() then
            exit;
          strsavefile := savedialog.FileName;
          Screen.Cursor:=crhourglass; //屏幕指针形状
          excelapp := CreateOleObject('excel.application');
          excelapp.workbooks.add;
          excelapp.workbooks[1].worksheets[1].name:=filename;
          page:=excelapp.workbooks[1].worksheets[filename];
          for i:= 0 to SGrid_List.RowCount-2 do
          begin
            //第一列没有数据,不用
            for j:=1 to SGrid_List.ColCount-1 do
            begin
              page.cells[i+1,j]:= SGrid_List.Cells[j,i];
            end;
          end;
          excelapp.activeworkbook.saveas(strsavefile);
          Application.ProcessMessages;
          excelapp.application.quit;
          result := true;
        finally
          savedialog.Free;
          Screen.Cursor:=crDefault;
        end;
      except
        on E:Exception do
        begin
          Errstr := e.Message;
          result := false;
        end;
      end;
    end;
  • 相关阅读:
    盘的转——使用缓动函数完成动画
    espnet环境配置(window)
    2021.9.8 Hadoop集群
    2021.9.7 开学第一课
    RS-422与RS-485
    70 进程创建的优化设计 下
    RGB液晶接口
    matlab2018a安装激活教程
    sed初级教程
    centos无法添加默认网关
  • 原文地址:https://www.cnblogs.com/jinshizuofei/p/3373150.html
Copyright © 2011-2022 走看看