home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 January / Chip_2003-01_cd1.bin / zkuste / delphi / kolekce / d567 / FLEXCEL.ZIP / XLSAdapter / UXlsSheet.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2002-10-10  |  19.2 KB  |  595 lines

  1. unit UXlsSheet;
  2.  
  3. interface
  4. uses Classes, SysUtils, UXlsBaseRecords, UXlsBaseRecordLists, UXlsOtherRecords, UXlsChart,
  5.      UXlsSST, XlsMessages, UXlsSections, UXlsCondFmt, UXlsRowColEntries, UXlsEscher,
  6.      UXlsRangeRecords, UEscherRecords, UXlsWorkbookGlobals, UXlsNotes, UXlsBaseList,
  7.      UFlxMessages, UXlsCellRecords, UXlsFormula, UXlsPageBreaks, UXlsColInfo;
  8.  
  9. type
  10.   TSheet= class (TBaseSection)
  11.   private
  12.     function GetShowGridLines: boolean;
  13.     procedure SetShowGridLines(const Value: boolean);
  14.   protected
  15.     FWorkbookGlobals: TWorkbookGlobals;
  16.     FWindow2: TWindow2Record;
  17.     function GetSelected: boolean;
  18.     procedure SetSelected(const Value: boolean);
  19.   public
  20.     function CopyTo: TSheet; //This method can't be virtual
  21.     function DoCopyTo: TSheet; virtual;
  22.     procedure InsertAndCopyRows(const FirstRow, LastRow, DestRow, aCount: integer; const SheetInfo: TSheetInfo; const OnlyFormulas: boolean);virtual;abstract;
  23.     procedure DeleteRows(const aRow, aCount: word;const SheetInfo: TSheetInfo);virtual; abstract;
  24.     procedure ArrangeInsert(const InsPos, InsCount: integer ; const SheetInfo: TSheetInfo);virtual;abstract;
  25.     procedure ArrangeCopySheet(const SheetInfo: TSheetInfo); virtual;
  26.  
  27.     procedure InsertPageBreak(const aRow: word);virtual;
  28.  
  29.     constructor Create(const aWorkbookGlobals: TWorkbookGlobals);virtual;
  30.  
  31.     property Selected: boolean read GetSelected write SetSelected;
  32.     property ShowGridLines: boolean read GetShowGridLines write SetShowGridLines;
  33.   end;
  34.  
  35.   ClassOfTSheet= Class of TSheet;
  36.  
  37.   TChart = class (TSheet)
  38.   private
  39.     FChartRecords: TChartRecordList;
  40.   public
  41.  
  42.     constructor Create(const aWorkbookGlobals: TWorkbookGlobals);override;
  43.     destructor Destroy;override;
  44.     function DoCopyTo: TSheet; override;
  45.  
  46.     function TotalSize:int64; override;
  47.     procedure LoadFromStream( const DataStream: TStream; const First: TBOFRecord; const SST: TSST);override;
  48.     procedure SaveToStream(const DataStream: TStream);override;
  49.     procedure Clear; override;
  50.     procedure ArrangeCopySheet(const SheetInfo: TSheetInfo);override;
  51.     procedure ArrangeInsert(const InsPos, InsCount: integer; const SheetInfo: TSheetInfo);override;
  52.     procedure InsertAndCopyRows(const FirstRow, LastRow, DestRow, aCount: integer; const SheetInfo: TSheetInfo; const OnlyFormulas: boolean);override;
  53.     procedure DeleteRows(const aRow, aCount: word; const SheetInfo: TSheetInfo);override;
  54.  
  55.   end;
  56.  
  57.   TChartList = class(TBaseList) //records are TChart
  58.     {$INCLUDE TChartListHdr.inc}
  59.     procedure SaveToStream(const DataStream: TStream);
  60.     procedure ArrangeInsert(const InsPos, InsCount: integer; const SheetInfo: TSheetInfo);
  61.   end;
  62.  
  63.  
  64.   TWorkSheet = class (TSheet)
  65.   private
  66.     FMiscRecords1: TBaseRecordList;
  67.     FMiscRecords2: TBaseRecordList;
  68.     FPageBreaks: TPageBreakList;
  69.     FDrawing: TDrawing;
  70.     FCells: TCells;
  71.     FRanges: TRangeList;
  72.     FNotes: TNoteList;
  73.     FColumns: TColInfoList;
  74.  
  75.     FDefRowHeight: Longint;
  76.     FDefColWidth:  integer;
  77.  
  78.     function GetDrawingRow(index: integer): integer;
  79.     function GetDrawingName(index: integer): widestring;
  80.   public
  81.     constructor Create(const aWorkbookGlobals: TWorkbookGlobals);override;
  82.     destructor Destroy;override;
  83.     function DoCopyTo: TSheet; override;
  84.  
  85.     function TotalSize:int64; override;
  86.     procedure LoadFromStream( const DataStream: TStream; const First: TBOFRecord; const SST: TSST);override;
  87.     procedure SaveToStream(const DataStream: TStream); override;
  88.     procedure Clear; override;
  89.  
  90.     procedure InsertAndCopyRows(const FirstRow, LastRow, DestRow, aCount: integer; const SheetInfo: TSheetInfo; const OnlyFormulas: boolean);override;
  91.     procedure DeleteRows(const aRow, aCount: word; const SheetInfo: TSheetInfo);override;
  92.  
  93.     procedure ArrangeInsert(const InsPos, InsCount: integer; const SheetInfo: TSheetInfo);override;
  94.     procedure ArrangeCopySheet(const SheetInfo: TSheetInfo); override;
  95.  
  96.     property Notes: TNoteList read FNotes;
  97.     property Cells: TCells read FCells;
  98.  
  99.     function DrawingCount: integer;
  100.     procedure AssignDrawing(const Index: integer; const Data: string; const DataType: TXlsImgTypes);
  101.     procedure GetDrawingFromStream(const Index: integer; const Data: TStream; var DataType: TXlsImgTypes);
  102.     property DrawingRow[index: integer]: integer read GetDrawingRow;
  103.     property DrawingName[index: integer]: widestring read GetDrawingName;
  104.     function GetAnchor(const Index: integer): TClientAnchor;
  105.  
  106.     procedure InsertPageBreak(const aRow: word);override;
  107.  
  108.     function GetRowHeight(const aRow: integer): integer;
  109.     function GetColWidth(const aCol: Word): integer;
  110.     procedure SetRowHeight(const aRow: integer; const Value: integer);
  111.     procedure SetColWidth(const aCol: Word; const Value: integer);
  112.  
  113.     property DefRowHeight: Longint read FDefRowHeight;
  114.     property DefColWidth:  integer read FDefColWidth;
  115.  
  116.     function GetRowFormat(const aRow: integer): integer;
  117.     function GetColFormat(const aCol: integer): integer;
  118.     procedure SetRowFormat(const aRow: integer; const Value: integer);
  119.     procedure SetColFormat(const aCol: integer; const Value: integer);
  120.  
  121.     function CellMergedBounds(const aRow, aCol: integer): TXlsCellRange;
  122.  
  123.   end;
  124.  
  125. implementation
  126.  
  127. { TSheet }
  128.  
  129. function TSheet.CopyTo: TSheet;
  130. begin
  131.   if Self= nil then Result:=nil else Result:= DoCopyTo;
  132. end;
  133.  
  134. constructor TSheet.Create(const aWorkbookGlobals: TWorkbookGlobals);
  135. begin
  136.   FWorkbookGlobals:=aWorkbookGlobals;
  137. end;
  138.  
  139. function TSheet.DoCopyTo: TSheet;
  140. begin
  141.   Result:= ClassOfTSheet(ClassType).Create(FWorkbookGlobals);
  142.   Result.BOF:= BOF.CopyTo as TBOFRecord;
  143.   Result.EOF:= EOF.CopyTo as TEOFRecord;
  144. end;
  145.  
  146. function TSheet.GetSelected: boolean;
  147. begin
  148.   if (FWindow2<>nil) then Result:=FWindow2.Selected else Result:=false;
  149. end;
  150.  
  151. procedure TSheet.SetSelected(const Value: boolean);
  152. begin
  153.   if (FWindow2<>nil) then FWindow2.Selected:=value;
  154. end;
  155.  
  156. procedure TSheet.InsertPageBreak(const aRow: word);
  157. begin
  158.   //Nothing in TSheet
  159. end;
  160.  
  161. procedure TSheet.ArrangeCopySheet(const SheetInfo: TSheetInfo);
  162. begin
  163.   //Nothing in TSheet
  164. end;
  165.  
  166. function TSheet.GetShowGridLines: boolean;
  167. begin
  168.   if (FWindow2<>nil) then Result:=FWindow2.ShowGridLines else Result:=true;
  169. end;
  170.  
  171. procedure TSheet.SetShowGridLines(const Value: boolean);
  172. begin
  173.   if (FWindow2<>nil) then FWindow2.ShowGridLines:=value;
  174. end;
  175.  
  176. { TChart }
  177.  
  178. procedure TChart.ArrangeCopySheet(const SheetInfo: TSheetInfo);
  179. begin
  180.   FChartRecords.ArrangeCopySheet(SheetInfo);
  181. end;
  182.  
  183. procedure TChart.InsertAndCopyRows(const FirstRow, LastRow, DestRow,
  184.   aCount: integer; const SheetInfo: TSheetInfo; const OnlyFormulas: boolean);
  185. begin
  186.   //Nothing, we never insert rows in a chart sheet
  187. end;
  188.  
  189. procedure TChart.DeleteRows(const aRow, aCount: word; const SheetInfo: TSheetInfo);
  190. begin
  191.   //Nothing, we never delete rows in a chart sheet
  192. end;
  193.  
  194. procedure TChart.Clear;
  195. begin
  196.   inherited;
  197.   if FChartRecords<>nil then FChartRecords.Clear;
  198. end;
  199.  
  200. function TChart.DoCopyTo: TSheet;
  201. begin
  202.   Result:= inherited DoCopyTo;
  203.   (Result as TChart).FChartRecords.CopyFrom(FChartRecords);
  204. end;
  205.  
  206. constructor TChart.Create(const aWorkbookGlobals: TWorkbookGlobals);
  207. begin
  208.   inherited;
  209.   FChartRecords:= TChartRecordList.Create;
  210. end;
  211.  
  212. destructor TChart.Destroy;
  213. begin
  214.   FreeAndNil(FChartRecords);
  215.   inherited;
  216. end;
  217.  
  218. procedure TChart.LoadFromStream(const DataStream: TStream;
  219.   const First: TBOFRecord; const SST: TSST);
  220. var
  221.   RecordHeader: TRecordHeader;
  222.   R: TBaseRecord;
  223. begin
  224.   Clear;
  225.   repeat
  226.     if (DataStream.Read(RecordHeader, sizeof(RecordHeader)) <> sizeof(RecordHeader)) then
  227.       raise Exception.Create(ErrExcelInvalid);
  228.  
  229.     R:=LoadRecord(DataStream, RecordHeader);
  230.     try
  231.       if RecordHeader.Id=xlr_WINDOW2 then FWindow2:=R as TWindow2Record;
  232.       if (R is TLabelSSTRecord) then (R as TLabelSSTRecord).AttachToSST(SST);
  233.       if (R is TBofRecord) then raise Exception.Create(ErrExcelInvalid)
  234.       else if (R is TIgnoreRecord) then FreeAndNil(R)
  235.       else if (R is TEOFRecord) then EOF:=(R as TEOFRecord)
  236.       else FChartRecords.Add(R) ;
  237.     except
  238.       FreeAndNil(R);
  239.       Raise;
  240.     end; //Finally
  241.  
  242.   until RecordHeader.id = xlr_EOF;
  243.   BOF:=First; //Last statement
  244. end;
  245.  
  246. procedure TChart.SaveToStream(const DataStream: TStream);
  247. begin
  248.   if (BOF=nil)or(EOF=nil) then raise Exception.Create(ErrSectionNotLoaded);
  249.   BOF.SaveToStream(DataStream);
  250.   FChartRecords.SaveToStream(DataStream);
  251.   EOF.SaveToStream(DataStream);
  252. end;
  253.  
  254. function TChart.TotalSize: int64;
  255. begin
  256.   Result:= inherited TotalSize+
  257.     FChartRecords.TotalSize;
  258. end;
  259.  
  260. procedure TChart.ArrangeInsert(const InsPos, InsCount: integer; const SheetInfo: TSheetInfo);
  261. begin
  262.   FChartRecords.ArrangeInsert( InsPos, InsCount, SheetInfo);
  263. end;
  264.  
  265. { TChartList }
  266.  
  267. {$INCLUDE TChartListImp.inc}
  268.  
  269. procedure TChartList.ArrangeInsert(const InsPos, InsCount: integer;
  270.   const SheetInfo: TSheetInfo);
  271. var
  272.   i: integer;
  273. begin
  274.   for i:=0 to Count -1 do Items[i].ArrangeInsert(InsPos, InsCount, SheetInfo);
  275. end;
  276.  
  277. procedure TChartList.SaveToStream(const DataStream: TStream);
  278. var
  279.   i:integer;
  280. begin
  281.   for i:=0 to Count-1 do Items[i].SaveToStream(DataStream);
  282. end;
  283.  
  284. { TWorkSheet }
  285.  
  286. procedure TWorkSheet.Clear;
  287. begin
  288.   inherited;
  289.   if FMiscRecords1<>nil then FMiscRecords1.Clear;
  290.   if FMiscRecords2<>nil then FMiscRecords2.Clear;
  291.   if FPageBreaks<>nil then FPageBreaks.Clear;
  292.   if FDrawing<>nil then FDrawing.Clear;
  293.   if FCells<>nil then FCells.Clear;
  294.   if FRanges<>nil then FRanges.Clear;
  295.   if FNotes<>nil then FNotes.Clear;
  296.   if FColumns<>nil then FColumns.Clear;
  297. end;
  298.  
  299. function TWorkSheet.DoCopyTo: TSheet;
  300. begin
  301.   Result:= inherited DoCopyTo;
  302.   (Result as TWorkSheet).FMiscRecords1.CopyFrom(FMiscRecords1);
  303.   (Result as TWorkSheet).FMiscRecords2.CopyFrom(FMiscRecords2);
  304.   (Result as TWorkSheet).FPageBreaks.CopyFrom(FPageBreaks);
  305.   (Result as TWorkSheet).FDrawing.CopyFrom(FDrawing);
  306.   (Result as TWorkSheet).FCells.CopyFrom(FCells);
  307.   (Result as TWorkSheet).FRanges.CopyFrom(FRanges);
  308.   (Result as TWorkSheet).FNotes.CopyFrom(FNotes);
  309.   (Result as TWorkSheet).FColumns.CopyFrom(FColumns);
  310.  
  311.   (Result as TWorkSheet).FNotes.FixDwgIds((Result as TWorkSheet).FDrawing);
  312.  
  313.   (Result as TWorkSheet).FDefColWidth:=FDefColWidth;
  314.   (Result as TWorkSheet).FDefRowHeight:=FDefRowHeight;
  315. end;
  316.  
  317. constructor TWorkSheet.Create(const aWorkbookGlobals: TWorkbookGlobals);
  318. begin
  319.   inherited;
  320.   FMiscRecords1:= TBaseRecordList.Create;
  321.   FMiscRecords2:= TBaseRecordList.Create;
  322.   FPageBreaks:=TPageBreakList.Create;
  323.   FDrawing:= TDrawing.Create(FWorkbookGlobals.DrawingGroup);
  324.   FColumns:= TColInfoList.Create;
  325.   FCells:= TCells.Create(aWorkbookGlobals.SST, FColumns);
  326.   FRanges :=TRangeList.Create;
  327.   FNotes:= TNoteList.Create;
  328.  
  329.   FDefRowHeight:=$FF;
  330.   FDefColWidth:=$0A*DefColWidthAdapt;
  331. end;
  332.  
  333. destructor TWorkSheet.Destroy;
  334. begin
  335.   FreeAndNil(FRanges);
  336.   FreeAndNil(FCells);
  337.   FreeAndNil(FNotes);
  338.   FreeAndNil(FColumns);
  339.   //FDrawing should be freed after notes
  340.   FreeAndNil(FDrawing);
  341.   FreeAndNil(FPageBreaks);
  342.   FreeAndNil(FMiscRecords1);
  343.   FreeAndNil(FMiscRecords2);
  344.   inherited;
  345. end;
  346.  
  347. procedure TWorkSheet.LoadFromStream(const DataStream: TStream;
  348.   const First: TBOFRecord; const SST: TSST);
  349. var
  350.   RecordHeader: TRecordHeader;
  351.   R: TBaseRecord;
  352.   MiscRecords: TBaseRecordList;
  353.   FShrFmlas: TShrFmlaRecordList;
  354.   LastFormula: TFormulaRecord;
  355. begin
  356.   Clear;
  357.   MiscRecords:=FMiscRecords1;
  358.   FShrFmlas:= TShrFmlaRecordList.Create;
  359.   LastFormula:=nil;
  360.   try
  361.     repeat
  362.       if (DataStream.Read(RecordHeader, sizeof(RecordHeader)) <> sizeof(RecordHeader)) then
  363.         raise Exception.Create(ErrExcelInvalid);
  364.  
  365.       R:=LoadRecord(DataStream, RecordHeader);
  366.       try
  367.         if RecordHeader.Id=xlr_WINDOW2 then
  368.         begin
  369.           MiscRecords:=FMiscRecords2;
  370.           FWindow2:=R as TWindow2Record;
  371.         end;
  372.         if (R is TFormulaRecord) then LastFormula:=R as TFormulaRecord;
  373.  
  374.         if (R is TDefColWidthRecord) then FDefColWidth:= (R as TDefColWidthRecord).Width*DefColWidthAdapt;
  375.         if (R is TDefRowHeightRecord) then FDefRowHeight:= (R as TDefRowHeightRecord).Height;
  376.  
  377.         if (R is TLabelSSTRecord) then (R as TLabelSSTRecord).AttachToSST(SST);
  378.         if (R is TBofRecord) then raise Exception.Create(ErrExcelInvalid)
  379.         else if (R is TDrawingRecord) then FDrawing.LoadFromStream(DataStream, R as TDrawingRecord, SST)
  380.         else if (R is TIgnoreRecord) then FreeAndNil(R)
  381.         else if (R is TNoteRecord) then FNotes.AddRecord(R as TNoteRecord, (R as TNoteRecord).Row)
  382.         else if (R is TColInfoRecord) then FColumns.AddRecord(R as TColInfoRecord)
  383.         else if (R is TCellRecord) then FCells.AddCell(R as TCellRecord, (R as TCellRecord).Row)
  384.         else if (R is TMultipleValueRecord) then begin FCells.AddMultipleCells(R as TMultipleValueRecord);FreeAndNil(R);end
  385.         else if (R is TRowRecord) then FCells.AddRow(R as TRowRecord)
  386.         else if (R is TCondFmtRecord) then FRanges[FRanges.Add(TCondFmt.Create)].LoadFromStream(DataStream, R as TCondFmtRecord)
  387.         else if (R is TCellMergingRecord) then FRanges[FRanges.Add(TMergedCells.Create)].LoadFromStream(DataStream, R as TCellMergingRecord)
  388.         else if (R is TShrFmlaRecord) then FShrFmlas.Add(R as TShrFmlaRecord)
  389.         else if (R is THPageBreakRecord) then FPageBreaks.AddRecord(R as THPageBreakRecord)
  390.         else if (R is TStringRecord) then begin if LastFormula=nil then raise Exception.Create(ErrExcelInvalid) else LastFormula.SetFormulaValue((R as TStringRecord).Value);FreeAndNil(R);end
  391.         else if (R is TEOFRecord) then EOF:=(R as TEOFRecord)
  392.         else MiscRecords.Add(R) ;
  393.  
  394.       except
  395.         FreeAndNil(R);
  396.         Raise;
  397.       end; //Finally
  398.  
  399.     until RecordHeader.id = xlr_EOF;
  400.  
  401.     FNotes.FixDwgIds(FDrawing);
  402.     FCells.CellList.FixFormulas(FShrFmlas);
  403.   finally
  404.     FreeAndNil(FShrFmlas);
  405.   end; //finally
  406.  
  407.   //this must be the last statment, so if there is an exception, we dont take First
  408.   BOF:= First;
  409. end;
  410.  
  411. procedure TWorkSheet.SaveToStream(const DataStream: TStream);
  412. begin
  413.   if (BOF=nil)or(EOF=nil) then raise Exception.Create(ErrSectionNotLoaded);
  414.   BOF.SaveToStream(DataStream);
  415.   FMiscRecords1.SaveToStream(DataStream);
  416.   FPageBreaks.SaveToStream(DataStream);
  417.   FColumns.SaveToStream(DataStream);
  418.   FCells.SaveToStream(DataStream);
  419.   FDrawing.SaveToStream(DataStream);
  420.   FNotes.SaveToStream(DataStream);
  421.   FMiscRecords2.SaveToStream(DataStream);
  422.   FRanges.SaveToStream(DataStream);
  423.   EOF.SaveToStream(DataStream);
  424. end;
  425.  
  426. function TWorkSheet.TotalSize: int64;
  427. begin
  428.   Result:= inherited TotalSize+
  429.     FMiscRecords1.TotalSize +
  430.     FPageBreaks.TotalSize +
  431.     FCells.TotalSize +
  432.     FRanges.TotalSize +
  433.     FDrawing.TotalSize +
  434.     FMiscRecords2.TotalSize+
  435.     FNotes.TotalSize+
  436.     FColumns.TotalSize;
  437. end;
  438.  
  439. procedure TWorkSheet.InsertAndCopyRows(const FirstRow, LastRow, DestRow, aCount: integer; const SheetInfo: TSheetInfo; const OnlyFormulas: boolean);
  440. begin
  441.    FCells.InsertAndCopyRows(FirstRow, LastRow, DestRow, aCount, SheetInfo, OnlyFormulas);
  442.    FDrawing.InsertAndCopyRows(FirstRow, LastRow, DestRow, aCount, SheetInfo);
  443.    FRanges.InsertAndCopyRows(FirstRow, LastRow, DestRow, aCount, SheetInfo);
  444.    FNotes.InsertAndCopyRows(FirstRow, LastRow, DestRow, aCount, SheetInfo, false);
  445.    FPageBreaks.InsertRows(DestRow, aCount);
  446. end;
  447.  
  448. procedure TWorkSheet.DeleteRows(const aRow, aCount: word; const SheetInfo: TSheetInfo);
  449. begin
  450.    FCells.DeleteRows(aRow, aCount, SheetInfo);
  451.    FDrawing.DeleteRows(aRow, aCount, SheetInfo);
  452.    FRanges.DeleteRows(aRow, aCount, SheetInfo);
  453.    FNotes.DeleteRows(aRow, aCount, SheetInfo);
  454.    FPageBreaks.DeleteRows(aRow, aCount);
  455. end;
  456.  
  457.  
  458. procedure TWorkSheet.ArrangeInsert(const InsPos, InsCount: integer; const SheetInfo: TSheetInfo);
  459. begin
  460.   //PENDING: Optimize this
  461.   FCells.ArrangeInsert(InsPos, InsCount, SheetInfo);
  462.   FDrawing.ArrangeInsert(InsPos, InsCount, SheetInfo);
  463. end;
  464.  
  465.  
  466.  
  467. procedure TWorkSheet.AssignDrawing(const Index: integer; const Data: string;
  468.   const DataType: TXlsImgTypes);
  469. begin
  470.   FDrawing.AssignDrawing( Index, Data, DataType);
  471. end;
  472.  
  473. procedure TWorkSheet.GetDrawingFromStream(const Index: integer; const Data: TStream;
  474.   var DataType: TXlsImgTypes);
  475. begin
  476.   FDrawing.GetDrawingFromStream( Index, Data, DataType);
  477. end;
  478.  
  479. function TWorkSheet.DrawingCount: integer;
  480. begin
  481.   Result:= FDrawing.DrawingCount;
  482. end;
  483.  
  484. function TWorkSheet.GetDrawingRow(index: integer): integer;
  485. begin
  486.   Result:= FDrawing.DrawingRow[index];
  487. end;
  488.  
  489. function TWorkSheet.GetDrawingName(index: integer): widestring;
  490. begin
  491.   Result:= FDrawing.DrawingName[index];
  492. end;
  493.  
  494. procedure TWorkSheet.InsertPageBreak(const aRow: word);
  495. begin
  496.   inherited;
  497.   FPageBreaks.AddBreak(aRow);
  498. end;
  499.  
  500. procedure TWorkSheet.ArrangeCopySheet(const SheetInfo: TSheetInfo);
  501. begin
  502.   inherited;
  503.   FDrawing.ArrangeCopySheet(SheetInfo);
  504. end;
  505.  
  506. function TWorkSheet.GetColWidth(const aCol: Word): integer;
  507. var
  508.   index: integer;
  509. begin
  510.   if not FColumns.Find(aCol, Index) then Result:=DefColWidth else Result:=FColumns[Index].Width;
  511. end;
  512.  
  513. function TWorkSheet.GetRowHeight(const aRow: integer): integer;
  514. begin
  515.   if not FCells.RowList.HasRow(aRow) then Result:=DefRowHeight else
  516.   Result:= FCells.RowList.RowHeight(aRow);
  517. end;
  518.  
  519. procedure TWorkSheet.SetColWidth(const aCol: Word; const Value: integer);
  520. var
  521.   Index: integer;
  522. begin
  523.   if FColumns.Find(aCol, Index) then
  524.     FColumns[Index].Width:=Value
  525.   else
  526.     FColumns.Insert(Index, TColInfo.Create(aCol, Value, 0, 0));
  527. end;
  528.  
  529. procedure TWorkSheet.SetRowHeight(const aRow, Value: integer);
  530. begin
  531.   FCells.RowList.SetRowHeight(aRow, Value);
  532. end;
  533.  
  534. function TWorkSheet.GetColFormat(const aCol: integer): integer;
  535. var
  536.   index: integer;
  537. begin
  538.   if not FColumns.Find(aCol, Index) then Result:=0 else Result:=FColumns[Index].XF;
  539. end;
  540.  
  541. function TWorkSheet.GetRowFormat(const aRow: integer): integer;
  542. begin
  543.   if not FCells.RowList.HasRow(aRow) then Result:=0 else
  544.   Result:= FCells.RowList[aRow].XF;
  545. end;
  546.  
  547. procedure TWorkSheet.SetColFormat(const aCol: integer; const Value: integer);
  548. var
  549.   Index: integer;
  550.   i: integer;
  551. begin
  552.   if FColumns.Find(aCol, Index) then
  553.     FColumns[Index].XF:=Value
  554.   else
  555.     FColumns.Insert(Index, TColInfo.Create(aCol, DefColWidth, Value, 0));
  556.  
  557.   //Reset all cells in column to format XF
  558.   for i:=0 to FCells.CellList.Count-1 do
  559.     if FCells.CellList[i].Find(aCol, Index) then FCells.CellList[i][Index].XF:=Value;
  560. end;
  561.  
  562. procedure TWorkSheet.SetRowFormat(const aRow, Value: integer);
  563. var
  564.   i: integer;
  565. begin
  566.   FCells.RowList.AddRow(aRow);
  567.   FCells.RowList[aRow].XF:= Value;
  568.  
  569.   //Reset all cells in column to format XF
  570.   if(aRow>=0) and (aRow<FCells.CellList.Count) then
  571.     for i:=0 to FCells.CellList[aRow].Count-1 do FCells.CellList[aRow][i].XF:=Value;
  572.  
  573. end;
  574.  
  575. function TWorkSheet.GetAnchor(const Index: integer): TClientAnchor;
  576. begin
  577.   Result:= FDrawing.GetAnchor(Index);
  578. end;
  579.  
  580. function TWorkSheet.CellMergedBounds(const aRow, aCol: integer): TXlsCellRange;
  581. var
  582.   i: integer;
  583. begin
  584.   //Find the cell into the MergedCells array
  585.   Result.Left:=aCol;
  586.   Result.Right:=aCol;
  587.   Result.Top:=aRow;
  588.   Result.Bottom:=aRow;
  589.   for i:=0 to FRanges.Count-1 do
  590.     if FRanges[i] is TMergedCells then
  591.       if (FRanges[i] as TMergedCells).CheckCell(aRow, aCol, Result) then exit;
  592. end;
  593.  
  594. end.
  595.