• NativeExcel3使用示例


    除了XLSReadWriteII5,还有个NativeExcel也是比较好的操作excel的组件,现将NativeExcel3的使用示例写一下,以下是代码和生成的excel表格的效果:

    procedure TForm1.Button2Click(Sender: TObject);
    var
      i, n: Integer;
      XLS: IXLSWorkbook; // 引用nExcel, ShellAPI
      ws: IXLSWorksheet;
    begin
      XLS := TXLSWorkbook.Create;
      try
        ws := XLS.Sheets.Add;
        ws.Name := '导出';
        // 注意NativeExcel是从1开始的,不是0开始
        for i := 1 to 10 do
          ws.Cells.Item[1, i].Value := '标题' + IntToStr(i);
        for i := 1 to 10 do
          for n := 2 to 20 do
            With ws.Cells.Item[n, i] do
            begin
              Value := IntToStr(i) + ':' + IntToStr(n - 1);
              if ColumnWidth < Length(AnsiString(Value)) then // 自动列宽
                ColumnWidth := Length(AnsiString(Value));
            end;
     
        for i := 1 to 10 do // 从第一列到最后一列
        begin
          for n := 1 to 20 do // 从第一行到最后一行
          begin
            With ws.Cells.Item[n, i] do
            begin
              Borders.LineStyle := xlContinuous;
              Borders.Color := clBlack;
              // 黑色#0
              if n = 1 then
              begin
                Interior.Color := clWebOrange; // RGB(255, 140, 0); // 橘黄#FF8000
                Font.Color := clWhite;
                HorizontalAlignment := xlHAlignCenter;
              end
              else
                Interior.Color := RGB(255, 248, 220); // 杏仁灰#FFFFCD
            end;
          end;
        end;
        XLS.SaveAs(ExtractFilePath(paramstr(0)) + 'temp.xls', xlOpenXMLWorkbook);
        ShellExecute(0, 'Open', PChar(ExtractFilePath(paramstr(0)) + 'temp.xls')
          , nil, nil, SW_SHOW);
      finally
        XLS.close;
      end;
    end;
     
  • 相关阅读:
    poj 3280 Cheapest Palindrome(区间DP)
    POJ 2392 Space Elevator(多重背包)
    HDU 1285 定比赛名次(拓扑排序)
    HDU 2680 Choose the best route(最短路)
    hdu 2899 Strange fuction (三分)
    HDU 4540 威威猫系列故事――打地鼠(DP)
    HDU 3485 Count 101(递推)
    POJ 1315 Don't Get Rooked(dfs)
    脱离eclipse,手动写一个servlet
    解析xml,几种方式
  • 原文地址:https://www.cnblogs.com/westsoft/p/10877194.html
Copyright © 2020-2023  润新知