• StringGrid存储为Excel文档


    function SaveAsExcelFile(StringGrid: TStringGrid; FileName: string):
    boolean;
    const
      xlWBATWorksheet = -4167;
    var
      Row, Col:     integer;
      GridPrevFile: string;
      XLApp, Sheet: OLEVariant;
    begin
      Result := false;
      XLApp := CreateOleObject('Excel.Application');
      try
        XLApp.Visible := False;
        XLApp.Workbooks.Add(xlWBatWorkSheet);
        Sheet      := XLApp.Workbooks[1].WorkSheets[1];
        Sheet.Name := 'My Sheet Name';
        for col := 0 to StringGrid.ColCount - 1 do
          for row := 0 to StringGrid.RowCount - 1 do
            Sheet.Cells[row + 1,col + 1] := StringGrid.Cells[col, row];
        try
          XLApp.Workbooks[1].SaveAs(FileName);
          Result := True;
        except
        end;
      finally
        if not VarIsEmpty(XLApp) then
        begin
          XLApp.DisplayAlerts := False;
          XLApp.Quit;
          XLAPP := Unassigned;
          Sheet := Unassigned;
        end;
      end;
    end;
  • 相关阅读:
    62-函数的调用
    40-字符串类型内置方法
    47-Python进阶小结
    44-集合的内置方法
    45-数据类型分类
    43-字典类型内置方法
    42-元组类型内置方法
    41-列表类型内置方法
    es6 Reflect对象详解
    微信小程序之公共组件写法
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/2940857.html
Copyright © 2020-2023  润新知