Position from comments after insertion

Questions and answers on how to use XLSReadWriteII 5.
Post Reply
TinyTina
Posts: 2
Joined: Wed Apr 20, 2016 9:45 am

Position from comments after insertion

Post by TinyTina »

Hi there,

I have a sheet with comments. When I insert rows, the position of the comments doesn't change. What can I do to change the positions of the comments relative to the insertion?
An example:
There's a comment in cell B5. I insert a row between row 3 and row 4 and everything in the sheet upwards row 4 moves about one row. The comment should be in cell B6 now, but it stays in B5.
TinyTina
Posts: 2
Joined: Wed Apr 20, 2016 9:45 am

Re: Position from comments after insertion

Post by TinyTina »

I am using a similar method like Josef Gschwendtner wrote in his post:
viewtopic.php?f=16&t=2430&p=5985&hilit= ... b91a#p5985
I think he deletes all comments after reading, but I want to preserve some comments. So they have to move relative to the insertion of rows and columns. I think it's a bug and I hope this is fixed in coming versions.

I am using this workaround (only for rows, columns is analogue):

Code: Select all

procedure insertRowsMoveComment(sheet: TXLSWorksheet; aRow, aRowCount: Integer);
var
  comment:TXLSComment;
   i:Integer;
begin
  sheet.InsertRows(aRow, aRowCount);
  for i:=0 to  XLS[0].comments.count-1 do
    begin
      comment:=XLS[0].comments[i];
      if comment.Row>=aRow then
          moveComment(comment,sheet, 0,aRowCount);
    end;
end;

procedure moveComment(comment: TXlSComment; sheet: TXLSWorksheet; aCol, aRow: Integer);
var
  newCol, newRow:Integer;
begin
   newCol:=comment.Col+aCol;
   newRow:=comment.Row+aRow;

       if (newCol>=0) and (newRow>=0) then
        begin
           comment.Col:=newCol;
           comment.Row:=newRow;
        end;
end;
Post Reply