zoukankan      html  css  js  c++  java
  • Delphi编程保存数据到Excel文件(4):使用NativeExcel2控件

      这个控件非常好,非常的简捷,尤其是Range对象操作使用起来非常方便,值得推荐。

        代码片断如下:

    procedure TForm1.Button1Click(Sender: TObject); Var Book: IXLSWorkbook;            //申明工作薄     ws: IXLSWorksheet;             //申明工作表     i, j: integer; begin   //Create workbook    创建工作薄   Book := TXLSWorkbook.Create;   //Add new sheet      在工作薄中加一个新的工作表   ws := Book.Sheets.Add;   ws.Name := 'Ten times table(乘法表)';   //给工作表命名

      //General settings   常规的格式设置   With ws.Range['B2', 'M14'] do begin      Font.Size := 12;      Font.Bold := true;      ColumnWidth := 5.71;      Interior.ColorIndex := 45;      Borders.ColorIndex := xlColorIndexAutomatic;      HorizontalAlignment := xlHAlignCenter;   end;

      //Title   标题   With ws.Range['B2', 'M2'] do begin     Merge(false);     Font.Size := 14;     Value := 'Ten Times Table(乘法表)';   end;

      //columns header    列头   With ws.Range['C3', 'M3'] do begin      Interior.ColorIndex := 53;      Font.Color := clWhite;   end;

      //rows header     行头   With ws.Range['B4', 'B14'] do begin      Interior.ColorIndex := 53;      Font.Color := clWhite;   end;

      //Table values    表内值   for i := 0 to 10 do begin     //column header    列头     ws.Cells.Item[3, i + 3].Value := i;     //row header       行头     ws.Cells.Item[i + 4, 2].Value := i;     //time table       表内值     for j := 0 to 10 do begin    //先行后列        ws.Range['C4', 'M14'].Item[i + 1, j + 1].Value := i * j;     end;   end;

      Book.SaveAs('TenTimesTable.xls');   //保存到文件   MessageDlg('TenTimesTable.xls is created', mtInformation, [mbOk], 0);

    end;

  • 相关阅读:
    Android复习(一)基础知识
    iOS Xcode真机调试包下载地址
    使用AndroidStudio开发cocos2d-x,以及可能会出现的问题
    浅析为什么用高阶组件代替 Mixins
    github readme 添加图片预览
    vue打包多页报错webpackJsonp is not defined
    MegaPixImage插件代码(new MegaPixImage)
    【react学习二】create-react-app 接入antd 并按需加载组件
    canvas 计算文字宽度(常用于文字换行)
    【react学习一】首先先create-react-app 配置less、sass
  • 原文地址:https://www.cnblogs.com/hssbsw/p/2802001.html
Copyright © 2011-2022 走看看