⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uxlsbaserecordlists.pas

📁 TMS Component Pack Pro v4.2
💻 PAS
📖 第 1 页 / 共 2 页
字号:
  Result := inherited Items[Index] as TRowRecord;
  if Result=nil then raise Exception.CreateFmt(ErrRowMissing,[Index]);
end;

function TRowRecordList.HasRow(const Index: integer): boolean;
begin
 Result:= (Index>=0) and(Index<Count) and (inherited Items[Index]<>nil);
end;

procedure TRowRecordList.DeleteRows(const aRow, aRowCount: word; const SheetInfo: TSheetInfo);
var
  i, Max: integer;
begin
  Max:=aRow+aRowCount ; if Max>Count then Max:= Count;
  for i:= Max-1 downto aRow do Delete(i);
  //Delete the cells. we can look only for those below arow
  for i:=aRow to Count-1 do if HasRow(i) then Items[i].ArrangeInsertRowsAndCols(aRow, -aRowCount, 0, 0, SheetInfo);

end;


procedure TRowRecordList.InsertAndCopyRows(const FirstRow, LastRow,
  DestRow, aCount: integer; const SheetInfo: TSheetInfo);
var
  i, k, z, CopyOffs, MyDestRow: integer;
  aRecord: TRowRecord;
begin
  //Insert the cells. we can look only for those below destrow
  for i:=DestRow to Count-1 do if HasRow(i) then Items[i].ArrangeInsertRowsAndCols(DestRow, aCount*(LastRow-FirstRow+1), 0, 0, SheetInfo);

  //Copy the cells
  MyDestRow:=DestRow;
  CopyOffs:=0;
  for k:=1 to aCount do
    for i:=FirstRow to LastRow do
    begin
      aRecord:=nil;
      try
        if (i+CopyOffs<Count) and HasRow(i+CopyOffs) then
        begin
          aRecord:=Items[i+CopyOffs].CopyTo as TRowRecord;
          aRecord.ArrangeCopyRowsAndCols(MyDestRow-aRecord.Row,0);
        end;
        for z:= Count to MyDestRow-1 do Add(nil);
        Insert(MyDestRow, aRecord);
        aRecord:=nil;
      finally
        FreeAndNil(aRecord);
      end; //finally
      Inc(MyDestRow);
      if FirstRow>=DestRow then Inc(CopyOffs);
    end;
end;

procedure TRowRecordList.SetItems(index: integer; const Value: TRowRecord);
begin
  inherited Items[Index] := Value;
end;

procedure TRowRecordList.AddRow(const Index: word);
var
  aRecord: TRowRecord;
begin
  if HasRow(Index) then exit;
  aRecord:= TRowRecord.CreateStandard(Index);
  AddRecord(aRecord);
end;

function TRowRecordList.RowHeight(const aRow: integer): integer;
begin
  if not HasRow(aRow) then Result:=0 else Result:=Items[aRow].Height;
end;

procedure TRowRecordList.SetRowHeight(const aRow: integer; const Height: word);
begin
  AddRow(aRow);
  Items[aRow].Height:=Height;
  Items[aRow].ManualHeight;
end;

procedure TRowRecordList.AutoRowHeight(const aRow: integer;const Value: boolean);
begin
  if HasRow(aRow) then
    if Value then Items[aRow].AutoHeight else Items[aRow].ManualHeight;
end;


function TRowRecordList.IsAutoRowHeight(const aRow: integer): boolean;
begin
  if HasRow(aRow) then
    Result:= Items[aRow].IsAutoHeight else Result:=True;
end;

function TRowRecordList.TotalRangeSize(const CellRange: TXlsCellRange): int64;
var
  i: integer;
begin
  Result:=0;
  for i:= CellRange.Top to CellRange.Bottom do Result:=Result+Items[i].TotalSize;
end;

procedure TRowRecordList.CalcGuts(const Guts: TGutsRecord);
var
  MaxGutsLevel: integer;
  GutsLevel: integer;
  i: integer;
begin
  MaxGutsLevel:=0;
  for i:=0 to Count-1 do
  begin
    if HasRow(i) then
    begin
      GutsLevel:=items[i].Options and $07;
      if GutsLevel>MaxGutsLevel then MaxGutsLevel:=GutsLevel;
    end;
  end;
  Guts.RowLevel:=MaxGutsLevel;
end;

{ TBoundSheetRecordList }

function TBoundSheetRecordList.GetSheetName(index: integer): widestring;
begin
  Result:= Items[index].SheetName;
end;

function TBoundSheetRecordList.GetSheetVisible(index: integer): TXlsSheetVisible;
begin
  //Wrong docs? the byte to hide a sheet is the low, not the high on grbit
  case Lo(Items[index].OptionFlags) and $3 of
    1: Result:=sv_Hidden;
    2: Result:=sv_VeryHidden;
    else Result:=sv_Visible;
  end; //case
end;

procedure TBoundSheetRecordList.SetSheetName(index: integer;
  const Value: widestring);
var
  OldSize: integer;
begin
  OldSize:=Items[index].TotalSize;
  Items[index].SheetName:=Value;
  AdaptSize(Items[index].TotalSize-OldSize);
end;

procedure TBoundSheetRecordList.SetSheetVisible(index: integer;
  const Value: TXlsSheetVisible);
var
  w: word;
  p: PArrayOfByte;
begin
  //Wrong docs? the byte to hide a sheet is the low, not the high on grbit

  w:=Items[index].OptionFlags;
  p:=@w;
  p[0]:=p[0] and ($FF-$3); //clear the 2 first bytes;
  case Value of
    sv_Hidden: p[0]:=p[0] or $1;
    sv_VeryHidden: p[0]:=p[0] or $2;
  end; //case
  Items[index].OptionFlags:=w;
end;

{ TCellRecordList }

procedure TCellRecordList.GoNext(var i: integer; const aCount: integer;
  var it: TCellRecord; var NextRec: TCellRecord);
begin
  it:=NextRec;
  inc(i);
  if (i<aCount) then NextRec:=Items[i] else NextRec:=nil;
end;

function TCellRecordList.SaveAndCalcRange(const DataStream: TStream;
  const CellRange: TXlsCellRange): int64;
var
  aCount: integer;
  it, it2: TCellRecord;
  NextRec, NextRec2: TCellRecord;
  i, c, i2: integer;
  JoinSize: integer;
begin
  Result:=0;
  aCount:=Count;
  if  (aCount<=0) or ((Items[0].Row<CellRange.Top) or (Items[0].Row>CellRange.Bottom)) then exit;
  if (aCount<=0) then exit;

  NextRec:=Items[0];
  it:=nil;
  i:=0;
  while (i<aCount) do
  begin
    GoNext(i, aCount, it, NextRec);
    if (it<>nil) then
    begin
      c:=it.Column;
      if ((c>=CellRange.Left) and (c<=CellRange.Right)) then
      begin
        //Search for MulRecords. We need 2 blanks together for this to work.
        if (it.CanJoinNext(NextRec, CellRange.Right)) then
        begin
          //Calc Total.
          i2:=i; it2:=it; NextRec2:=NextRec;
          JoinSize:=it2.TotalSizeFirst;
          GoNext(i2, aCount, it2, NextRec2);

          while (it2.CanJoinNext(NextRec2, CellRange.Right)) do
          begin
            inc(JoinSize, it2.TotalSizeMid);
            GoNext(i2, aCount, it2, NextRec2);
          end;
          inc(JoinSize, it2.TotalSizeLast);
          inc(Result, JoinSize);

          if (DataStream <> nil) then
          begin
            it.SaveFirstMul(DataStream, JoinSize);
            GoNext(i, aCount, it, NextRec);

            while (it.CanJoinNext(NextRec, CellRange.Right)) do
            begin
              it.SaveMidMul(DataStream);
              GoNext(i, aCount, it, NextRec);
            end;
            it.SaveLastMul(DataStream);
          end else
          begin
            i:=i2;
            it:=it2;
            NextRec:=NextRec2;
          end;
        end
          else
          begin
            if (DataStream <> nil) then it.SaveToStream(DataStream);
            inc(Result, it.TotalSize);
          end;
      end;
    end;
  end;
end;

procedure TCellRecordList.SaveToStream(const DataStream: TStream);
const
  CellRange: TXlsCellRange=(Left: 0; Top: 0; Right: Max_Columns; Bottom: Max_Rows);
begin
  SaveRangeToStream (DataStream, CellRange);
end;

function TCellRecordList.TotalRangeSize(
  const CellRange: TXlsCellRange): int64;
begin
  Result:=SaveAndCalcRange(nil, CellRange);
end;

function TCellRecordList.GetTotalSize: int64;
const
  CellRange: TXlsCellRange=(Left: 0; Top: 0; Right: Max_Columns; Bottom: Max_Rows);
begin
  Result:= TotalRangeSize(CellRange);
end;

procedure TCellRecordList.SaveRangeToStream(const DataStream: TStream;
  const CellRange: TXlsCellRange);
begin
  SaveAndCalcRange(DataStream, CellRange);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -