using AutofitRow

I am trying to use AutofitRow, but the results are not as I expected. First, this is the code snippet:

      FillCell(rowIdx, 1, FPPMDisclaimer, taCenter, [fsBold]);
      fmt := XLS.GetCellVisibleFormatDef(rowIdx, 1);
      fmt.WrapText := True;
      XLS.SetCellFormat(rowIdx, 1, XLS.AddFormat(fmt));
      XLS.MergeCells(rowIdx, 1, rowIdx, 10);
      XLS.AutofitRow(1, 1, False, True, 1.0);

Two questions come to mind.
1. As whatever solution I use must be compatible with Excel Viewer, is the AutofitRow going to be the right answer?
2. In merging the cells, does the format I applied to the first cell become the format for the merged cells?

It is clear enough that I am doing something wrong, but not yet clear what the error is.

Thanks.

Update:


Part of the problem was my own oversight. My apologies.

But is there a way to insert a row, and I have not found it? Or must I do MoveRange to accomplish that result?
Hi,
To insert a row at say row 10, you would use something like
xls.InsertAndCopyRange(TXlsCellRange.Create(1, 1, 1, 1),  10, 1, 1, TFlxInsertMode.ShiftRowDown, TRangeCopyMode.None);

InsertAndCopyRange is a really overloaded and powerful method.
The name InsertAndCopyRange maybe it isn't 100% descriptive, but this method can Insert, Copy or InsertAndCopy ranges of cells, rows or columns, from a sheet to the same sheet, to another sheet or to another file. The name is like this because it is one of the "founding methods" of FlexCel: When I created the first version of FlexCel like a hundred years ago, it was all about FlexCelReports. There wasn't even a public API to create files by hand, it was all done with templates and replacing tags from datasets. And to do the reports, I needed to InsertAndCopyRows in the template to fill them with values.

But over the years, instead of having a thousand methods to manipulate cells: InsertRows, CopyRows, InsertAndCopyRows, CopyColumns, etc, I preferred to keep everything in InsertAndCopyRange. So to manipulate stuff, there aren't a hundred methods but just 5:

InsertAndCopyRange
DeleteRange
MoveRange
InsertAndCopySheets
DeleteSheet

Just rememebring those methods you should be able to do most stuff. And most of it is with InsertAndCopyRange, which as said is one of the fundamental methods in FlexCel.

About moving or copying row heights, this depends in if you copy or move the full row or not. If you are moving a range of cells say from column A to D, then the row height won't move, because you can't move the row height for the columns A to D. But if you are moving or copying the full row (using TFlxInsertMode.ShiftRowDown or selecting the full range of columns), then it should move or copy the row heights too.

A final note: TFlxInsertMode.ShiftRowDown is the same as selecting the full range of columns. But it is easier to just use a single cell range and tell FlexCel to use the full row, than to use a range which goes from column 1 to the last column in excel (which is also different for xls than for xlsx)



Adrian,


  Thanks! Now that I see your approach, I am sure it will be simpler to deal with than non-overloaded approaches might have been.

  In old code, I used a row insert to put in the sheet header, which is variable in its use of rows. That was simple and logical. Because I did not find that in FlexCel, I have used MoveRange. But I will change that now, to use the InsertAndCopyRange, since that will yield a design with fewer dependencies.