home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 September / Chip_2001-09_cd1.bin / zkuste / delphi / kompon / d56 / EXPORTE.ZIP / scExcelExport.pas < prev   
Pascal/Delphi Source File  |  2001-06-21  |  40KB  |  1,105 lines

  1. {--------------------------------------------------------------------------------
  2. * Description : TscExcelExport : Export Delphi Dataset to MS Excel
  3. * Dates : February 2000 - June 2001
  4. * Version : 2.4 (Delphi 5.0 and 6.0)
  5.  
  6. * Author : Stefan Cruysberghs
  7. * Email : stefancr@yucom.be
  8. * Website : http://www.stefancr.yucom.be
  9. --------------------------------------------------------------------------------
  10. * $Archive: /Component Library/SC/scExcelExport.pas $
  11. * $Author: Administrator $
  12. * $Date: 12/05/01 11:12 $
  13. * $Modtime: 12/05/01 11:06 $
  14. * $Revision: 7 $
  15. --------------------------------------------------------------------------------
  16. This component is free of charge.
  17. The author doesn't give a warranty for error free running
  18. of this component and he doesn't give any support.
  19. Suggestions and bugs can be send by email.
  20. --------------------------------------------------------------------------------
  21. Version 1.2
  22.   - Improved connection to Excel
  23. Version 1.3
  24.   - Added Orientation of titles
  25.   - Added StyleColumnWidth
  26. Version 1.4
  27.   - Improved GetColumnCharacters
  28.   - Added Border properties and background colors for Titles, Data and Summary
  29.   - Added Summary properties (SummarySelection, SummaryFields, SummaryCalculation)
  30. Version 1.5
  31.   - Improved speed of exporting data
  32.   - Improved exporting string-fields
  33.   - Added ConnectTo property
  34. Version 1.6
  35.   - Suppression of reference to Dataset.RecordCount (thanks to GΘrard Beneteau)
  36.   - Added VisibleFieldsOnly property
  37. Version 1.7
  38.   - Notification when disconnecting dataset
  39.   - Very fast export by using a variant matrix (thanks to Frank van den Bergh)
  40. Version 1.8
  41.   - Bug in exporting titles (thanks to Roberto Parola)
  42.   - Setting format of cells before exporting data (thanks to Asbj°rn Heggvik)
  43.   - Added BlockOfRecords property : little bit faster and more control of memory
  44.   - Added properties to set begin row of titles and data
  45. Version 1.9
  46.   - Added properties (Orientation, WrapText, Alignment) to font (thanks to David Balick)
  47.     (property OrientationTitles is removed)
  48.   - Added HeaderText (thanks to David Balick)
  49.   - Improved some routines
  50. Version 2.0
  51.   - Added read only property with row number of last data row
  52.   - Added property with the Excel tabsheet so after the export
  53.     it is possible to access the cells in Excel
  54.   - Added event OnExportRecords
  55. Version 2.1
  56.   - Bugfixes
  57. Version 2.2
  58.   - Bugfix when exporting filtered dataset (thanks to Heinz Faerber)
  59.   - New column width styles : cwFieldDisplayWidth, cwFieldDataSize, cwEnhAutoFit (idea from Scott Stanek)
  60. Version 2.3
  61.   - Added properties begin column data/titles and header (idea from Knjazev Sergey)
  62.   - Added property ShowTitles
  63. Version 2.4
  64.   - Support for Delphi 6.0
  65. -------------------------------------------------------------------------------}
  66.  
  67. {
  68.   Example 1 : easiest way to export a dataset to Excel
  69.  
  70.   scExcelExport1.Dataset:=Table1;
  71.   scExcelExport1.ExportDataset;
  72.   scExcelExport1.Disconnect;
  73. }
  74.  
  75. {
  76.   Example 2 : use layout properties, add summary cells and save file
  77.  
  78.   scExcelExport1.WorksheetName := 'MyDataset';
  79.   scExcelExport1.Dataset:=Table1;
  80.   scExcelExport1.StyleColumnWidth:=cwOwnerWidth;
  81.   scExcelExport1.ColumnWidth := 20;
  82.   scExcelExport1.HeaderText.Text := 'Header';
  83.   scExcelExport1.BeginRowHeader := 2;
  84.   scExcelExport1.FontTitles := LabelTitle.Font;
  85.   scExcelExport1.FontTitles.Orientation := 45;
  86.   scExcelExport1.BorderTitles.BackColor := clYellow;
  87.   scExcelExport1.BorderTitles.BorderColor := clRed;
  88.   scExcelExport1.BorderTitles.LineStyle := blLine;
  89.   scExcelExport1.BeginRowTitles := 5;
  90.   scExcelExport1.BeginColumnData := 3;
  91.   scExcelExport1.FontData := LabelData.Font;
  92.   scExcelExport1.SummarySelection := ssValues;
  93.   scExcelExport1.SummaryCalculation := scMAX;
  94.   scExcelExport1.ExcelVisible:=False;
  95.   try
  96.     scExcelExport1.ExportDataset;
  97.  
  98.     if Assigned(scExcelExport1.ExcelWorkSheet) then
  99.       scExcelExport1.ExcelWorkSheet.Range['A1','A10'].Value := 'Delphi';
  100.  
  101.     scExcelExport1.SaveAs('c:\test.xls',ffXLS);
  102.   finally
  103.     scExcelExport1.Disconnect;
  104.   end;
  105. }
  106.  
  107. {
  108.   Example 3 : export more datasets 
  109.  
  110.   scExcelExport1.ExcelVisible:=True;
  111.  
  112.   try
  113.     scExcelExport1.Dataset:=Table1;
  114.     scExcelExport1.WorksheetName:='1';
  115.     scExcelExport1.ConnectTo := ctNewExcel;
  116.     scExcelExport1.ExportDataset;
  117.  
  118.     scExcelExport1.Dataset:=Table2;
  119.     scExcelExport1.WorksheetName:='2';
  120.     scExcelExport1.ConnectTo := ctNewWorkbook;
  121.     scExcelExport1.ExportDataset;
  122.  
  123.     scExcelExport1.Dataset:=Table3;
  124.     scExcelExport1.WorksheetName:='3';
  125.     scExcelExport1.ConnectTo := ctNewWorksheet;
  126.     scExcelExport1.ExportDataset;
  127.   finally
  128.     scExcelExport1.Disconnect;
  129.   end;
  130.  
  131. }
  132.  
  133. unit scExcelExport;
  134.  
  135. interface
  136.  
  137. uses
  138.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, DB,
  139.   StdCtrls,
  140.   OleServer, // used for TConnectKind
  141.   {$IFDEF VER140}
  142.   // Delphi 6.0
  143.     Excel2000,
  144.     Variants;
  145.   {$ELSE}
  146.   // Delphi 5.0
  147.     Excel97; // Excel97 or Excel2000
  148.   {$ENDIF}
  149.  
  150.   // Delphi 5.0 notes
  151.   // ----------------
  152.   // Delphi5 standard installation installs Excel97
  153.   // If you wants to use Excel2000 you need to apply the following modifications
  154.   // described in upd1rdme.txt coming with Delphi Update Pack 1
  155.   //
  156.   //   Office 2000 Components
  157.   //   ----------------------
  158.   //   To install the Office 2000 components package:
  159.   //
  160.   //   1. Select File | Close all
  161.   //   2. Select Component | Install package
  162.   //   3. Remove package DclAxServer50.bpl to avoid
  163.   //      name conflicts with Ofice 97 components.
  164.   //   4. Add package Dcloffice2k50.bpl, which contains
  165.   //      the Office 2000 components.
  166.  
  167. type
  168.   TFileFormat = (ffXLS, ffHTM, ffCSV, ffXL97);
  169.   TStyleColumnWidth = (cwDefault, cwOwnerWidth, cwAutoFit, cwFieldDisplayWidth, cwFieldDataSize, cwEnhAutoFit);
  170.     // cwOwnerWidth : width specified with property ColumnWidth
  171.     // cwAutoFit : Excel autofit
  172.     // cwFieldDisplayWidth : width of DisplayWidth of TField
  173.     // cwFieldDataSize : width of Datasize of TField
  174.     //    Datasize = amount of memory to store value, for datetime fields width is set to 16
  175.     // cwEnhAutoFit (enhanced autofit) : width of DisplayWidth of TField except when title is larger
  176.   TBorderWeight = (bwThin, bwMedium, bwThick);
  177.     // xlHairline, xlMedium, xlThick, xlThin
  178.   TBorderLineStyle = (blNone, blDash, blLine, blDoubleLine);
  179.     // xlContinuous, xlDash, xlDashDot, xlDashDotDot, xlDot, xlDouble, xlSlantDashDot, xlLineStyleNone
  180.   TSummarySelection = (ssNone, ssValues, ssGiven);
  181.   TSummaryCalculation = (scSUM, scMIN, scMAX);
  182.   THAlignment = (haGeneral, haLeft, haRight, haCenter);
  183.   TConnectTo = (ctNewExcel, ctNewWorkbook, ctNewWorksheet);
  184.  
  185.   TxlFont = class(TFont)
  186.   private
  187.     FAlignment: THAlignment;
  188.     FBlnWrapText: Boolean;
  189.     FIntOrientation: Integer;
  190.   published
  191.     property Alignment: THAlignment read FAlignment write FAlignment;
  192.     property WrapText: Boolean read FBlnWrapText write FBlnWrapText;
  193.     property Orientation: Integer read FIntOrientation write FIntOrientation;
  194.   end;
  195.  
  196.   TCellBorder = class(TPersistent)
  197.   private
  198.     FBackColor : TColor;
  199.     FBorderColor : TColor;
  200.     FBorderWeight : TBorderWeight;
  201.     FBorderLineStyle : TBorderLineStyle;
  202.   published
  203.     property BackColor : TColor read FBackColor write FBackColor default clWhite;
  204.     property BorderColor : TColor read FBorderColor write FBorderColor default clBlack;
  205.     property Weight : TBorderWeight read FBorderWeight write FBorderWeight default bwMedium;
  206.     property LineStyle : TBorderLineStyle read FBorderLineStyle write FBorderLineStyle default blNone;
  207.   end;
  208.  
  209.   TOnExportEvent = procedure(Sender : TObject; IntRecordNumber : Integer) of object;
  210.  
  211.   TscExcelExport = class(TComponent)
  212.   private
  213.     FDataset : TDataset;
  214.     FIntRecordNo : integer;
  215.     FIntTotRecNo: Integer;
  216.     FIntBeginRowHeader : Integer;
  217.     FIntBeginRowTitles : Integer;
  218.     FIntBeginRowData : Integer;
  219.     FIntBeginColumnData : Integer;
  220.     FIntBeginColumnHeader : Integer;
  221.  
  222.     FIntEndRowData : Integer;
  223.  
  224.     FExcelApplication : TExcelApplication;
  225.     FExcelWorkbook : TExcelWorkbook;
  226.     FExcelWorksheet : TExcelWorksheet;
  227.  
  228.     FFieldNames : TStrings;
  229.  
  230.     FBlnShowTitles : Boolean;
  231.     FBlnExcelVisible : Boolean;
  232.     FStrWorksheetName : String;
  233.     FIntColumnWidth : Integer;
  234.     FStyleColumnWidth : TStyleColumnWidth;
  235.     FConnectTo : TConnectTo;
  236.  
  237.     FFontHeader: TxlFont;
  238.     FBorderHeader : TCellBorder;
  239.     FStrHeaderText: TStrings;
  240.  
  241.     FFontTitles : TxlFont;
  242.     FBorderTitles : TCellBorder;
  243.  
  244.     FFontData : TxlFont;
  245.     FBorderData : TCellBorder;
  246.  
  247.     FFontSummary : TxlFont;
  248.     FBorderSummary : TCellBorder;
  249.     FSummarySelection : TSummarySelection;
  250.     FSummaryFields : TStrings;
  251.     FSummaryCalculation : TSummaryCalculation;
  252.  
  253.     FIntBlockOfRecords : Integer;
  254.  
  255.     FStrBeginColumnDataChar : String;
  256.  
  257.     LCID : Integer;
  258.     FVisibleFieldsOnly: Boolean;
  259.  
  260.     FOnExportRecords : TOnExportEvent;
  261.     procedure SetBeginColumnData(const Value: Integer);
  262.     procedure SetBeginColumnHeader(const Value: Integer);
  263.   protected
  264.     procedure SetFontHeader(const Value: TxlFont);
  265.     procedure SetHeaderText(const Value: TStrings);
  266.     procedure SetFontTitles(Value : TxlFont);
  267.     procedure SetFontData(Value : TxlFont);
  268.     procedure SetFontSummary(Value : TxlFont);
  269.     procedure SetSummaryFields(Value : TStrings);
  270.     procedure SetVisibleFieldsOnly(const Value: Boolean);
  271.     procedure SetBeginRowHeader(const Value: Integer);
  272.     procedure SetBeginRowTitles(const Value: Integer);
  273.     procedure SetBeginRowData(const Value: Integer);
  274.  
  275.     procedure SetColumnWidth;
  276.     function GetColumnCharacters(IntNumber : Integer) : String;
  277.     procedure SetFontAndBorderRange(DelphiFont : TxlFont; Border : TCellBorder; StrBeginCell, StrEndCell : String);
  278.     procedure SetFormat;
  279.  
  280.     function CanConvertFieldToCell(Field : TField) : Boolean;
  281.     function IsValueField(Field : TField) : Boolean;
  282.     function GetWidthFromDatasize(Field : TField) : Integer;
  283.  
  284.     procedure ExportHeader;
  285.     procedure ExportTitles;
  286.     procedure ExportFieldData;
  287.     procedure ExportSummary;
  288.   public
  289.     constructor Create(Owner: TComponent); override;
  290.     destructor Destroy; override;
  291.  
  292.     // Read-only properties
  293.     // Line number of last row of data is filled in after the export
  294.     property EndRowData : Integer read FIntEndRowData;
  295.     // Link to the Excel worksheet, can be used to add extra data after the export
  296.     property ExcelWorkSheet : TExcelWorksheet read FExcelWorksheet write FExcelWorksheet;
  297.  
  298.     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  299.  
  300.     procedure Disconnect; virtual;
  301.     procedure ExportDataset(BlnOpenedExcel : Boolean = False); virtual;
  302.     procedure SaveAs(const StrFileName : String; const FileFormat : TFileFormat); virtual;
  303.     procedure PrintPreview(const BlnPrintGridLines : Boolean); virtual;
  304.   published
  305.     // Show or hide excel (default True)
  306.     property ExcelVisible : Boolean read FBlnExcelVisible write FBlnExcelVisible default True;
  307.     // New instance of Excel application, new workbook or new worksheet (default is new instance of Excel)
  308.     property ConnectTo : TConnectTo read FConnectTo write FConnectTo default ctNewExcel;
  309.  
  310.     // Name of worksheet
  311.     property WorksheetName : String read FStrWorksheetName write FStrWorksheetName;
  312.     // Dataset which will be exported (TTable, TQuery, TClientDataset, TADODataset, ...)
  313.     property Dataset : TDataset read FDataset write FDataset;
  314.  
  315.     // Style of columnswidth : Excel default, width of property ColumnWidth, AutoFit
  316.     property StyleColumnWidth : TStyleColumnWidth read FStyleColumnWidth write FStyleColumnWidth;
  317.     property ColumnWidth : Integer read FIntColumnWidth write FIntColumnWidth;
  318.  
  319.     // Export only visible fields or all fields
  320.     property VisibleFieldsOnly : Boolean read FVisibleFieldsOnly write SetVisibleFieldsOnly default True;
  321.  
  322.     // Font and border of header
  323.     // Fill in header texts
  324.     property FontHeader: TxlFont read FFontHeader write SetFontHeader;
  325.     property HeaderText: TStrings read FStrHeaderText write SetHeaderText;
  326.     property BorderHeader : TCellBorder read FBorderHeader write FBorderHeader;
  327.  
  328.     // Font and border of titles
  329.     property ShowTitles : Boolean read FBlnShowTitles write FBlnShowTitles default True;
  330.     property FontTitles : TxlFont read FFontTitles write SetFontTitles;
  331.     property BorderTitles : TCellBorder read FBorderTitles write FBorderTitles;
  332.  
  333.     // Font and border of data
  334.     property FontData : TxlFont read FFontData write SetFontData;
  335.     property BorderData : TCellBorder read FBorderData write FBorderData;
  336.  
  337.     // Font and border of summary
  338.     property FontSummary : TxlFont read FFontSummary write SetFontSummary;
  339.     property BorderSummary : TCellBorder read FBorderSummary write FBorderSummary;
  340.     // Which fields will be summerized : all numeric fields, the fields of SummaryFields, none
  341.     property SummarySelection : TSummarySelection read FSummarySelection write FSummarySelection;
  342.     property SummaryFields : TStrings read FSummaryFields write SetSummaryFields;
  343.     // Calculation : SUM, MIN, MAX
  344.     property SummaryCalculation : TSummaryCalculation read FSummaryCalculation write FSummaryCalculation;
  345.  
  346.     // Number of records which will be exported in one variant matrix (default 20)
  347.     // Try to increase and decrease this property for the optimal speed
  348.     property BlockOfRecords : Integer read FIntBlockOfRecords write FIntBlockOfRecords default 20;
  349.  
  350.     // Begin row of titles and data
  351.     property BeginRowHeader : Integer read FIntBeginRowHeader write SetBeginRowHeader default 1;
  352.     property BeginRowTitles : Integer read FIntBeginRowTitles write SetBeginRowTitles default 1;
  353.     property BeginRowData : Integer read FIntBeginRowData write SetBeginRowData default 2;
  354.  
  355.     // Begin column header and data/titles
  356.     property BeginColumnHeader : Integer read FIntBeginColumnHeader write SetBeginColumnHeader default 1;
  357.     property BeginColumnData : Integer read FIntBeginColumnData write SetBeginColumnData default 1;
  358.  
  359.     // Event which is triggered after each export of a record
  360.     property OnExportRecords : TOnExportEvent read FOnExportRecords write FOnExportRecords;
  361.   end;
  362.  
  363. procedure Register;
  364.  
  365. implementation
  366.  
  367. uses ComObj; {, ActiveX;}
  368.  
  369. type
  370.   TOleEnum = type Integer; // Copied from ActiveX unit
  371.  
  372. procedure Register;
  373. begin
  374.   RegisterComponents('SC', [TscExcelExport]);
  375. end;
  376.  
  377. { $R scExcelExport.dcr }
  378.  
  379. //------------------------------------------------------------------------------
  380. constructor TscExcelExport.Create(Owner: TComponent);
  381. begin
  382.   inherited;
  383.   FStrHeaderText := TStringList.Create;
  384.  
  385.   FFontHeader := TxlFont.Create;
  386.   FFontTitles := TxlFont.Create;
  387.   FFontData := TxlFont.Create;
  388.   FFontSummary := TxlFont.Create;
  389.  
  390.   FBorderHeader := TCellBorder.Create;
  391.   FBorderTitles := TCellBorder.Create;
  392.   FBorderData := TCellBorder.Create;
  393.   FBorderSummary := TCellBorder.Create;
  394.  
  395.   FBorderTitles.FBackColor := clWhite;
  396.   FBorderTitles.FBorderColor := clBlack;
  397.   FBorderTitles.FBorderWeight := bwMedium;
  398.   FBorderTitles.FBorderLineStyle := blNone;
  399.  
  400.   FBorderData.FBackColor := clWhite;
  401.   FBorderData.FBorderColor := clBlack;
  402.   FBorderData.FBorderWeight := bwMedium;
  403.   FBorderData.FBorderLineStyle := blNone;
  404.  
  405.   FBorderSummary.FBackColor := clWhite;
  406.   FBorderSummary.FBorderColor := clBlack;
  407.   FBorderSummary.FBorderWeight := bwMedium;
  408.   FBorderSummary.FBorderLineStyle := blNone;
  409.  
  410.   FBlnExcelVisible := True;
  411.   FConnectTo := ctNewExcel;
  412.   FStrWorksheetName := '';
  413.   FStyleColumnWidth := cwDefault;
  414.   FVisibleFieldsOnly := True;
  415.   FBlnShowTitles := True;
  416.   FIntColumnWidth := 0;
  417.   FIntBlockOfRecords := 20;
  418.   FIntBeginRowHeader := 1;
  419.   FIntBeginRowTitles := 1;
  420.   FIntBeginRowData := 2;
  421.   FIntBeginColumnHeader := 1;
  422.   FIntBeginColumnData := 1;
  423.  
  424.   FExcelApplication := TExcelApplication.Create(Self);
  425.   FExcelWorkbook := TExcelWorkbook.Create(Self);
  426.   FExcelWorksheet := TExcelWorksheet.Create(Self);
  427.  
  428.   FFieldNames:=TStringList.Create;
  429.   FSummaryFields:=TStringList.Create;
  430. end;
  431.  
  432. //------------------------------------------------------------------------------
  433. destructor TscExcelExport.Destroy;
  434. begin
  435.   FStrHeaderText.Free;
  436.  
  437.   FFontHeader.Free;
  438.   FFontTitles.Free;
  439.   FFontData.Free;
  440.   FFontSummary.Free;
  441.  
  442.   FBorderHeader.Free;
  443.   FBorderTitles.Free;
  444.   FBorderData.Free;
  445.   FBorderSummary.Free;
  446.  
  447.   FExcelWorksheet.Free;
  448.   FExcelWorkbook.Free;
  449.   FExcelApplication.Free;
  450.  
  451.   FFieldNames.Free;
  452.   FSummaryFields.Free;
  453.  
  454.   inherited;
  455. end;
  456.  
  457. //------------------------------------------------------------------------------
  458. procedure TscExcelExport.Notification(AComponent: TComponent;
  459.   Operation: TOperation);
  460. begin
  461.   inherited;
  462.   if (Operation = opRemove) and (Assigned(FDataset)) and (AComponent = FDataset) then
  463.   begin
  464.     FDataset := nil;
  465.   end;
  466. end;
  467.  
  468. //------------------------------------------------------------------------------
  469. procedure TscExcelExport.SetHeaderText(const Value: TStrings);
  470. begin
  471.   FStrHeaderText.Assign(Value);
  472.  
  473.   if FStrHeaderText.Count = 0 then
  474.     FIntBeginRowHeader := 1;
  475.  
  476.   if FIntBeginRowTitles < FIntBeginRowHeader + FStrHeaderText.Count then
  477.     SetBeginRowTitles(FIntBeginRowHeader + FStrHeaderText.Count);
  478. end;
  479.  
  480. //------------------------------------------------------------------------------
  481. procedure TscExcelExport.SetFontHeader(const Value: TxlFont);
  482. begin
  483.   FFontHeader.Assign(Value);
  484. end;
  485.  
  486. //------------------------------------------------------------------------------
  487. procedure TscExcelExport.SetFontTitles(Value : TxlFont);
  488. begin
  489.   FFontTitles.Assign(Value);
  490. end;
  491.  
  492. //------------------------------------------------------------------------------
  493. procedure TscExcelExport.SetFontData(Value : TxlFont);
  494. begin
  495.   FFontData.Assign(Value);
  496. end;
  497.  
  498. //------------------------------------------------------------------------------
  499. procedure TscExcelExport.SetFontSummary(Value : TxlFont);
  500. begin
  501.   FFontSummary.Assign(Value);
  502. end;
  503.  
  504. //------------------------------------------------------------------------------
  505. procedure TscExcelExport.SetSummaryFields(Value : TStrings);
  506. begin
  507.   FSummaryFields.Assign(Value);
  508.   FSummaryFields.Text := UpperCase(FSummaryFields.Text);
  509. end;
  510.  
  511. //------------------------------------------------------------------------------
  512. procedure TscExcelExport.SetFontAndBorderRange(DelphiFont : TxlFont; Border : TCellBorder; StrBeginCell, StrEndCell : String);
  513. const
  514.   ALIGNARR: array[THAlignment] of Cardinal = (xlHAlignGeneral, xlHAlignLeft, xlHAlignRight, xlHAlignCenter);
  515. begin
  516.   // Convert Delphi font to the Excel font
  517.   with FExcelWorksheet.Range[StrBeginCell, StrEndCell].Font do
  518.   begin
  519.     Name := DelphiFont.Name;
  520.     Size := DelphiFont.Size;
  521.     Color := DelphiFont.Color;
  522.     Bold :=  fsBold in DelphiFont.Style;
  523.     Italic := fsItalic in DelphiFont.Style;
  524.     Underline := fsUnderline in DelphiFont.Style;
  525.   end;
  526.  
  527.   if Border.FBackColor <> clWhite then
  528.     FExcelWorksheet.Range[StrBeginCell, StrEndCell].Interior.Color := Border.FBackColor;
  529.  
  530.   if Border.LineStyle <> blNone then
  531.   begin
  532.     with FExcelWorksheet.Range[StrBeginCell, StrEndCell].Borders do
  533.     begin
  534.       Color := Border.BorderColor;
  535.       case Border.Weight of
  536.         // possible values xlHairline, xlMedium, xlThick, xlThin
  537.         // Abs to prevent warning 'Constant expression violates subrange bounds'
  538.         bwThin : Weight := Abs(xlThin);
  539.         bwMedium : Weight := Abs(xlMedium);
  540.         bwThick : Weight := Abs(xlThick);
  541.       end;
  542.  
  543.       case Border.LineStyle of
  544.         // possible values xlContinuous, xlDash, xlDashDot, xlDashDotDot, xlDot, xlDouble, xlSlantDashDot, xlLineStyleNone
  545.         blDash : LineStyle := Abs(xlDash);
  546.         blLine : LineStyle := Abs(xlContinuous);
  547.         blDoubleLine : LineStyle := Abs(xlDouble);
  548.       end;
  549.     end;
  550.   end;
  551.  
  552.   FExcelWorksheet.Range[StrBeginCell, StrEndCell].Orientation:=DelphiFont.Orientation;
  553.   FExcelWorksheet.Range[StrBeginCell, StrEndCell].WrapText := DelphiFont.WrapText;
  554.   FExcelWorksheet.Range[StrBeginCell, StrEndCell].HorizontalAlignment := TOleEnum(ALIGNARR[DelphiFont.Alignment]);
  555. end;
  556.  
  557. //------------------------------------------------------------------------------
  558. procedure TscExcelExport.SetColumnWidth;
  559. begin
  560.   if FStyleColumnWidth = cwOwnerWidth then
  561.     FExcelWorksheet.Range['A1',GetColumnCharacters(FFieldNames.Count)+'1'].ColumnWidth:=FIntColumnWidth
  562.   else
  563.     if FStyleColumnWidth = cwAutoFit then
  564.       FExcelWorksheet.Range['A1',GetColumnCharacters(FFieldNames.Count)+'1'].EntireColumn.Autofit;
  565.     // else cwFieldDisplayWidth, cwFieldDataSize and cwEnhAutoFit are set in ExportTitles
  566. end;
  567.  
  568. //------------------------------------------------------------------------------
  569. procedure TscExcelExport.SetFormat;
  570. var
  571.   IntColumn : Integer;
  572.   StrBeginCell, StrEndCell : String;
  573. begin
  574.   with Dataset do
  575.   begin
  576.     for IntColumn := 1 to FFieldNames.Count do
  577.     begin
  578.       if FieldByName(FFieldNames[IntColumn-1]).DataType = ftString then
  579.       begin
  580.         StrBeginCell := GetColumnCharacters(IntColumn)+IntToStr(FIntBeginRowData);
  581.         StrEndCell := GetColumnCharacters(IntColumn)+IntToStr(FIntTotRecNo + FIntBeginRowData - 1);
  582.         FExcelWorksheet.Range[StrBeginCell,StrEndCell].NumberFormat := '@' //other cases automatic 'general'
  583.       end;
  584.     end;
  585.   end;
  586. end;
  587.  
  588. //------------------------------------------------------------------------------
  589. function TscExcelExport.CanConvertFieldToCell(Field : TField) : Boolean;
  590. begin
  591.   if (Field.DataType = ftString) or
  592.     (Field.DataType = ftSmallint) or
  593.     (Field.DataType = ftInteger) or
  594.     (Field.DataType = ftWord) or
  595.     (Field.DataType = ftAutoInc) or
  596.     (Field.DataType = ftBoolean) or
  597.     (Field.DataType = ftFloat) or
  598.     (Field.DataType = ftCurrency) or
  599.     (Field.DataType = ftBCD) or
  600.     (Field.DataType = ftDate) or
  601.     (Field.DataType = ftTime) or
  602.     (Field.DataType = ftDateTime) or
  603.     (Field.DataType = ftLargeInt) or
  604.     (Field.DataType = ftWideString) or
  605.     (Field.DataType = ftVariant) then
  606.   begin
  607.     Result:=True;
  608.   end
  609.   else
  610.     Result:=False;
  611. end;
  612.  
  613. //------------------------------------------------------------------------------
  614. function TscExcelExport.IsValueField(Field : TField) : Boolean;
  615. begin
  616.   if (Field.DataType = ftSmallint) or
  617.     (Field.DataType = ftInteger) or
  618.     (Field.DataType = ftWord) or
  619.     (Field.DataType = ftFloat) or
  620.     (Field.DataType = ftCurrency) then
  621.   begin
  622.     Result:=True;
  623.   end
  624.   else
  625.     Result:=False;
  626. end;
  627.  
  628. //------------------------------------------------------------------------------
  629. function TscExcelExport.GetWidthFromDatasize(Field : TField) : Integer;
  630. begin
  631.   // Datasize for datetime is to small when also time is saved
  632.   if Field.DataType = ftDateTime then
  633.     Result := 16
  634.   else
  635.     // For all other fieldtypes, just use the datasize
  636.     // Datasize = amount of memory to store value
  637.     Result := Field.Datasize;
  638. end;
  639.  
  640. //------------------------------------------------------------------------------
  641. // Get Column-character for giving index
  642. //------------------------------------------------------------------------------
  643. function TscExcelExport.GetColumnCharacters(IntNumber : Integer) : String;
  644. begin
  645.   if IntNumber < 1 then
  646.     Result:='A'
  647.   else
  648.   begin
  649.     if IntNumber > 702 then
  650.       Result:='ZZ'
  651.     else
  652.     begin
  653.       if IntNumber > 26 then begin
  654.        if (IntNumber mod 26)=0 then
  655.         Result:=Chr(64 + (IntNumber div 26)-1)
  656.        else
  657.         Result:=Chr(64 + (IntNumber div 26));
  658.          if (IntNumber mod 26)=0 then
  659.           result:=result+chr(64+26)
  660.          else
  661.           result:=Result+Chr(64 + (IntNumber mod 26));
  662.       end
  663.       else
  664.         Result:=Chr(64 + IntNumber);
  665.     end;
  666.   end;
  667. end;
  668.  
  669. //------------------------------------------------------------------------------
  670. procedure TscExcelExport.Disconnect;
  671. begin
  672.   if not FExcelApplication.Visible[LCID] then
  673.   begin
  674.     FExcelApplication.DisplayAlerts[LCID] := False;
  675.     FExcelApplication.Quit;
  676.   end;
  677.   FExcelWorksheet.Disconnect;
  678.   FExcelWorkbook.Disconnect;
  679.   FExcelApplication.Disconnect;
  680. end;
  681.  
  682. //------------------------------------------------------------------------------
  683. procedure TscExcelExport.ExportDataset;
  684. var
  685.   CurPrev : TCursor;
  686. begin
  687.   CurPrev := Screen.Cursor;
  688.   Screen.Cursor := crHourGlass;
  689.   try
  690.     with FDataset do
  691.       if not Active then
  692.         Exit;
  693.  
  694.     LCID := LOCALE_USER_DEFAULT; //GetUserDefaultLCID;
  695.  
  696.     // Try to connect to Excel and create new Worksheet
  697.     try
  698.       if FConnectTo = ctNewExcel then
  699.       begin
  700.         FExcelApplication.ConnectKind := ckNewInstance;
  701.         FExcelApplication.Connect;
  702.         FExcelWorkbook.ConnectTo(FExcelApplication.Workbooks.Add(TOleEnum(xlWBATWorksheet), LCID));
  703.         FExcelWorksheet.ConnectTo(FExcelWorkbook.Worksheets[1] as _Worksheet);
  704.       end
  705.       else
  706.       begin
  707.         if FConnectTo = ctNewWorkbook then
  708.         begin
  709.           FExcelApplication.ConnectKind := ckRunningOrNew;
  710.           FExcelApplication.Connect;
  711.           FExcelWorkbook.ConnectTo(FExcelApplication.Workbooks.Add(TOleEnum(xlWBATWorksheet), LCID));
  712.           FExcelWorksheet.ConnectTo(FExcelWorkbook.Worksheets[1] as _Worksheet);
  713.         end
  714.         else
  715.         begin
  716.           FExcelApplication.ConnectKind := ckRunningOrNew;
  717.           FExcelApplication.Connect;
  718.           FExcelWorkbook.ConnectTo(FExcelApplication.ActiveWorkbook);
  719.           FExcelWorksheet.ConnectTo(FExcelWorkbook.Worksheets.Add(EmptyParam,EmptyParam,1,TOleEnum(xlWBATWorksheet),LCID) as _Worksheet);
  720.         end;
  721.       end;
  722.     except
  723.       Exit;
  724.     end;
  725.  
  726.     FExcelApplication.ScreenUpdating[LCID] := False;
  727.  
  728.     // If property worksheetname is not filled, worksheet will have name of dataset
  729.     if FStrWorksheetName <> '' then
  730.       FExcelWorksheet.Name := FStrWorksheetName
  731.     else
  732.       FExcelWorksheet.Name := FDataset.Name;
  733.  
  734.     // Export header
  735.     ExportHeader;
  736.  
  737.     // Export titels
  738.     ExportTitles;
  739.  
  740.     FIntTotRecNo := DataSet.RecordCount;
  741.     // Set format (for string fields) of cells before exporting data
  742.     SetFormat;
  743.     // Export data
  744.     ExportFieldData;
  745.  
  746.     // Calculate summary
  747.     if FSummarySelection <> ssNone then
  748.       ExportSummary;
  749.  
  750.     // Set width of columns
  751.     SetColumnWidth;
  752.  
  753.     FExcelWorksheet.Names.Add('naam',EmptyParam,True,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,'a1:b10',EmptyParam);
  754.  
  755.     FExcelApplication.ScreenUpdating[LCID] := FBlnExcelVisible;
  756.     FExcelApplication.Visible[LCID]:=FBlnExcelVisible;
  757.   finally
  758.     Screen.Cursor := CurPrev;
  759.   end;
  760. end;
  761.  
  762. //------------------------------------------------------------------------------
  763. procedure TscExcelExport.ExportHeader;
  764. var
  765.   i : Integer;
  766.   Matrix : Variant;
  767.   IntHeaderRows : Integer;
  768.   StrBeginColumnChar : String;
  769. begin
  770.   IntHeaderRows := FStrHeaderText.Count;
  771.  
  772.   if IntHeaderRows = 0 then
  773.     Exit;
  774.  
  775.   Matrix := VarArrayCreate([1, IntHeaderRows, 1, 1], varOleStr);
  776.  
  777.   for i := 1 to IntHeaderRows do
  778.     Matrix[i, 1] := FStrHeaderText[i - 1];
  779.  
  780.   // Get character corresponding with column index (A ... ZZZZ)
  781.   StrBeginColumnChar := GetColumnCharacters(FIntBeginColumnHeader);
  782.  
  783.   FExcelWorksheet.Range[
  784.     StrBeginColumnChar + IntToStr(FIntBeginRowHeader),
  785.     StrBeginColumnChar + IntToStr(FIntBeginRowHeader+IntHeaderRows-1)].Value := Matrix;
  786.   SetFontAndBorderRange(FFontHeader, FBorderHeader,
  787.     StrBeginColumnChar + IntToStr(FIntBeginRowHeader),
  788.     StrBeginColumnChar + IntToStr(FIntBeginRowHeader+IntHeaderRows-1));
  789. end;
  790.  
  791. //------------------------------------------------------------------------------
  792. procedure TscExcelExport.ExportTitles;
  793. var
  794.   IntColumn : Integer;
  795.   IntFieldIndex : Integer;
  796.   StrCell : String;
  797.   StrColumn : String;
  798.   StrTitle : String;
  799.   FltFontSizeFactor : Real;
  800.   FltTitleFontSizeFactor : Real;
  801. begin
  802.   with FDataset do
  803.   begin
  804.     FStrBeginColumnDataChar := GetColumnCharacters(FIntBeginColumnData);
  805.  
  806.     FFieldNames.Clear;
  807.  
  808.     if FBlnShowTitles then
  809.     begin
  810.       for IntColumn := FIntBeginColumnData to (Fields.Count + FIntBeginColumnData -1) do
  811.       begin
  812.         IntFieldIndex := IntColumn - FIntBeginColumnData;
  813.  
  814.         // Only export fields which are writable in an Excel cell
  815.         // Don't export non visible fields if VisibleFieldsOnly is True
  816.         // Add these fields to a list, so this list can be used when exporting data
  817.         if CanConvertFieldToCell(Fields[IntFieldIndex]) and
  818.            ((not VisibleFieldsOnly) or (VisibleFieldsOnly and Fields[IntFieldIndex].Visible))
  819.         then
  820.         begin
  821.           StrColumn := GetColumnCharacters(FFieldNames.Count + FIntBeginColumnData);
  822.           StrCell:=StrColumn+IntToStr(FIntBeginRowTitles);
  823.  
  824.           FFieldNames.Add(Fields[IntFieldIndex].FieldName);
  825.  
  826.           // Use DisplayName of column if this is filled in, otherwise use FieldName
  827.           if Fields[IntFieldIndex].DisplayName <> '' then
  828.             StrTitle := Fields[IntFieldIndex].DisplayName
  829.           else
  830.             StrTitle := Fields[IntFieldIndex].FieldName;
  831.  
  832.           FExcelWorksheet.Range[StrCell,StrCell].Value := StrTitle;
  833.  
  834.           // Use DisplayField of each field to set the column width
  835.           if FStyleColumnWidth = cwFieldDisplayWidth then
  836.           begin
  837.             // Value of datasize fits when font size = 10, so calculate factor when font size is larger
  838.             FltFontSizeFactor := FFontData.Size / 10;
  839.  
  840.             FExcelWorksheet.Range[StrCell,StrCell].ColumnWidth:=Integer(Round(Fields[IntFieldIndex].DisplayWidth * FltFontSizeFactor));
  841.           end
  842.           else
  843.           begin
  844.             // Use Datasize of each field to set the column width
  845.             if FStyleColumnWidth = cwFieldDataSize then
  846.             begin
  847.               // Value of datasize fits when font size = 10, so calculate factor when font size is larger
  848.               FltFontSizeFactor := FFontData.Size / 10;
  849.  
  850.               FExcelWorksheet.Range[StrCell,StrCell].ColumnWidth:=Integer(Round(GetWidthFromDatasize(Fields[IntFieldIndex]) * FltFontSizeFactor));
  851.             end
  852.             else
  853.             begin
  854.               // Style = adaptive -> use DisplayWidth of TField except when title of column is larger
  855.               if FStyleColumnWidth = cwEnhAutoFit then
  856.               begin
  857.                 // Value of datasize fits when font size = 10, so calculate factor when font size is larger
  858.                 FltFontSizeFactor := FFontData.Size / 10;
  859.                 FltTitleFontSizeFactor := FFontTitles.Size / 10;
  860.  
  861.                 if ((Length(StrTitle) + 1) * FltTitleFontSizeFactor) > (Fields[IntFieldIndex].DisplayWidth * FltFontSizeFactor) then
  862.                   FExcelWorksheet.Range[StrCell,StrCell].ColumnWidth:=Integer(Round((Length(StrTitle) + 1) * FltTitleFontSizeFactor) + 1)
  863.                 else
  864.                   FExcelWorksheet.Range[StrCell,StrCell].ColumnWidth:=Integer(Round(Fields[IntFieldIndex].DisplayWidth * FltFontSizeFactor));
  865.               end
  866.               // else cwDefault, cwOwnerWidth, cwAutoFit
  867.               // These columns widths are set after exporting all data in the procedure SetColumnWidth
  868.             end;
  869.           end;
  870.         end;
  871.       end;
  872.       SetFontAndBorderRange(FFontTitles, FBorderTitles, FStrBeginColumnDataChar+IntToStr(FIntBeginRowTitles),
  873.         GetColumnCharacters(FFieldNames.Count + FIntBeginColumnData -1)+IntToStr(FIntBeginRowTitles));
  874.     end
  875.     else
  876.     begin
  877.       // Titles will not be visible, but run through fields
  878.       for IntColumn := FIntBeginColumnData to (Fields.Count + FIntBeginColumnData -1) do
  879.       begin
  880.         IntFieldIndex := IntColumn - FIntBeginColumnData;
  881.  
  882.         // Only export fields which are writable in an Excel cell
  883.         // Don't export non visible fields if VisibleFieldsOnly is True
  884.         // Add these fields to a list, so this list can be used when exporting data
  885.         if CanConvertFieldToCell(Fields[IntFieldIndex]) and
  886.            ((not VisibleFieldsOnly) or (VisibleFieldsOnly and Fields[IntFieldIndex].Visible))
  887.         then
  888.         begin
  889.           StrColumn := GetColumnCharacters(FFieldNames.Count + FIntBeginColumnData);
  890.           FFieldNames.Add(Fields[IntFieldIndex].FieldName);
  891.         end;
  892.       end;
  893.     end;
  894.   end;
  895. end;
  896.  
  897. //------------------------------------------------------------------------------
  898. procedure TscExcelExport.ExportFieldData;
  899. var
  900.   IntColumn : Integer;
  901.   IntBeginRow, IntEndRow : Integer;
  902.   IntMatrixRow : Integer;
  903.   PtBookmark : TBookmark;
  904.   Matrix : Variant;
  905. begin
  906.   FIntRecordNo := 0;
  907.   with FDataset do
  908.   begin
  909.     DisableControls;
  910.     PtBookmark := GetBookmark;
  911.     try
  912.       // Create a matrix of variants
  913.       // -  Columns = number of fields
  914.       // -  Rows    = block of records (FIntBlockOfRecords)
  915.       Matrix := VarArrayCreate([1,FIntBlockOfRecords,1,FFieldNames.Count],varVariant);
  916.  
  917.       IntBeginRow := FIntBeginRowData;
  918.       IntEndRow := FIntBeginRowData + FIntBlockOfRecords-1 ;
  919.  
  920.       IntMatrixRow := 0;
  921.  
  922.       First;
  923.       while not EOF do
  924.       begin
  925.         Inc(FIntRecordNo);
  926.         Inc(IntMatrixRow);
  927.         if Assigned(FOnExportRecords) then
  928.           FOnExportRecords(Self,FIntRecordNo);
  929.  
  930.         for IntColumn := 1 to FFieldNames.Count do
  931.           Matrix[IntMatrixRow,IntColumn] := FieldByName(FFieldNames[IntColumn - 1]).AsVariant;
  932.  
  933.         // Create a new block of records to export to Excel
  934.         // Don't export all data to one variant matrix because memory has it limitations
  935.         // Property FIntBlockOfRecords is default 20 records
  936.  
  937.         // check if matrix is full, and if so, write the block to excel
  938.         if (FIntRecordNo mod FIntBlockOfRecords = 0) then
  939.         begin
  940.           FExcelWorksheet.Range[FStrBeginColumnDataChar+IntToStr(IntBeginRow),GetColumnCharacters(FFieldNames.Count + FIntBeginColumnData - 1)+IntToStr(IntEndRow)].Value := Matrix;
  941.           IntBeginRow := IntBeginRow + FIntBlockOfRecords;      // next insert starts here
  942.           IntEndRow := IntBeginRow   + FIntBlockOfRecords -1;   // next block ends here
  943.           IntMatrixRow := 0;                                    // reset index into matrix
  944.         end;
  945.  
  946.         Next;
  947.       end;
  948.  
  949.       // Now that EOF is true, so check if the matrix has remaining data to write
  950.       if (IntMatrixRow > 0) then
  951.       begin
  952.         // recalculate the block's end
  953.         IntEndRow := IntBeginRow + IntMatrixRow-1;
  954.         // Write remaining block
  955.         FExcelWorksheet.Range[FStrBeginColumnDataChar+IntToStr(IntBeginRow),GetColumnCharacters(FFieldNames.Count + FIntBeginColumnData - 1)+IntToStr(IntEndRow)].Value := Matrix;
  956.       end;
  957.  
  958.     finally
  959.       GotoBookmark(PtBookmark);
  960.       FreeBookmark(PtBookmark);
  961.       EnableControls;
  962.     end;
  963.   end;
  964.  
  965.   FIntEndRowData := IntEndRow;
  966.  
  967.   SetFontAndBorderRange(FFontData, FBorderData,FStrBeginColumnDataChar+IntToStr(FIntBeginRowData),
  968.     GetColumnCharacters(FFieldNames.Count + FIntBeginColumnData -1)+IntToStr(FIntEndRowData));
  969. end;
  970.  
  971. //------------------------------------------------------------------------------
  972. procedure TscExcelExport.ExportSummary;
  973. const
  974.   SUM_ARR: Array[TSummaryCalculation] of String = ('SUM', 'MIN', 'MAX');
  975. var
  976.   IntColumn : Integer;
  977.   StrCell : String;
  978.   StrCalc : String;
  979.   StrBeginCell, StrEndCell : String;
  980.  
  981.   function Summarized(aColumn: Integer): Boolean;
  982.   begin
  983.     case FSummarySelection of
  984.     ssValues:
  985.       Result := IsValueField(
  986.         FDataSet.FieldByName(FFieldNames[aColumn - 1]));
  987.     ssGiven:
  988.       Result := FSummaryFields.IndexOf(
  989.         UpperCase(FFieldNames[aColumn - 1])) > -1;
  990.     else
  991.       Result := False;
  992.     end;
  993.   end;
  994.  
  995. begin
  996.   with FDataset do
  997.   begin
  998.     for IntColumn := 1 to FFieldNames.Count do
  999.     begin
  1000.       if Summarized(IntColumn) then
  1001.       begin
  1002.         StrCell:=GetColumnCharacters(IntColumn)+IntToStr(FIntRecordNo + FIntBeginRowData);
  1003.         StrCalc := SUM_ARR[FSummaryCalculation];
  1004.  
  1005.         StrBeginCell := GetColumnCharacters(IntColumn)+IntToStr(FIntBeginRowData);
  1006.         StrEndCell := GetColumnCharacters(IntColumn)+IntToStr(FIntRecordNo + FIntBeginRowData - 1);
  1007.         FExcelWorksheet.Range[StrCell,StrCell].Value := Format('=%s(%s:%s)', [StrCalc, StrBeginCell, StrEndCell]);
  1008.       end;
  1009.     end;
  1010.   end;
  1011.   SetFontAndBorderRange(FFontSummary, FBorderSummary, 'A'+IntToStr(FIntRecordNo + FIntBeginRowData),
  1012.     GetColumnCharacters(FFieldNames.Count)+IntToStr(FIntRecordNo + FIntBeginRowData));
  1013. end;
  1014.  
  1015. //------------------------------------------------------------------------------
  1016. procedure TscExcelExport.SaveAs(const StrFileName : String; const FileFormat : TFileFormat);
  1017. begin
  1018.   FExcelApplication.DisplayAlerts[LCID] := False;
  1019.   // Export data to a file
  1020.   case FileFormat of
  1021.     ffXLS : FExcelWorksheet.SaveAs(StrFileName,TOleEnum(xlWorkbookNormal));
  1022.     // For 97 and 2000 compatible format
  1023.     ffXL97: FExcelWorksheet.SaveAs(StrFileName,TOleEnum(xlExcel9795));
  1024.     ffCSV : FExcelWorksheet.SaveAs(StrFileName,TOleEnum(xlCSV));
  1025. //    ffHTM : FExcelWorksheet.SaveAs(StrFileName,TOleEnum(xlHtml));  // Only works with Excel2000
  1026.   end;
  1027. end;
  1028.  
  1029. //------------------------------------------------------------------------------
  1030. procedure TscExcelExport.PrintPreview(const BlnPrintGridLines : Boolean);
  1031. begin
  1032.   // Show PrintPreview of Excel
  1033.   FExcelWorksheet.PageSetup.PrintGridlines:=BlnPrintGridLines;
  1034.   FExcelWorksheet.PageSetup.CenterHeader:=FExcelWorksheet.Name;
  1035.   FExcelApplication.ScreenUpdating[LCID] := True;
  1036.   FExcelApplication.Visible[LCID]:=True;
  1037.   FExcelWorksheet.PrintPreview;
  1038. end;
  1039.  
  1040. //------------------------------------------------------------------------------
  1041. procedure TscExcelExport.SetVisibleFieldsOnly(const Value: Boolean);
  1042. begin
  1043.   FVisibleFieldsOnly := Value;
  1044. end;
  1045.  
  1046. //------------------------------------------------------------------------------
  1047. procedure TscExcelExport.SetBeginRowHeader(const Value: Integer);
  1048. begin
  1049.   if FStrHeaderText.Count > 0 then
  1050.   begin
  1051.     if Value > 0 then
  1052.       FIntBeginRowHeader := Value
  1053.     else
  1054.       FIntBeginRowHeader := 1;
  1055.  
  1056.     if FIntBeginRowTitles < FIntBeginRowHeader + FStrHeaderText.Count - 1 then
  1057.       SetBeginRowTitles(FIntBeginRowHeader + FStrHeaderText.Count);
  1058.   end
  1059.   else
  1060.     FIntBeginRowHeader := 1;
  1061. end;
  1062.  
  1063. //------------------------------------------------------------------------------
  1064. procedure TscExcelExport.SetBeginRowTitles(const Value: Integer);
  1065. begin
  1066.   if Value < FIntBeginRowHeader + FStrHeaderText.Count then
  1067.     FIntBeginRowTitles := FIntBeginRowHeader + FStrHeaderText.Count
  1068.   else
  1069.     FIntBeginRowTitles := Value;
  1070.  
  1071.   if FIntBeginRowTitles >= FIntBeginRowData then
  1072.      SetBeginRowData(FIntBeginRowTitles + 1);
  1073. end;
  1074.  
  1075. //------------------------------------------------------------------------------
  1076. procedure TscExcelExport.SetBeginRowData(const Value: Integer);
  1077. begin
  1078.   if Value <= FIntBeginRowTitles then
  1079.     FIntBeginRowData := FIntBeginRowTitles + 1
  1080.   else
  1081.     FIntBeginRowData := Value;
  1082. end;
  1083.  
  1084. //------------------------------------------------------------------------------
  1085. procedure TscExcelExport.SetBeginColumnData(const Value: Integer);
  1086. begin
  1087.   if Value < 1 then
  1088.     FIntBeginColumnData := 1
  1089.   else
  1090.     FIntBeginColumnData := Value;
  1091. end;
  1092.  
  1093. //------------------------------------------------------------------------------
  1094. procedure TscExcelExport.SetBeginColumnHeader(const Value: Integer);
  1095. begin
  1096.   if Value < 1 then
  1097.     FIntBeginColumnHeader := 1
  1098.   else
  1099.     FIntBeginColumnHeader := Value;
  1100. end;
  1101.  
  1102. end.
  1103.  
  1104.  
  1105.