TTMSFNCDataGridExcelIO exports collapsed groups as expanded (migration from TTMSFNCGrid)

Hello,

We are currently migrating our project from TTMSFNCGrid to the newer TTMSFNCDataGrid.

In our previous implementation using TTMSFNCGrid combined with TTMSFNCGridExcelIO, we were able to export grouped grids successfully. The exported Excel files correctly respected the state of the grid, meaning collapsed groups remained collapsed (only visible rows were exported/visible in the generated file).

However, after switching to TTMSFNCDataGrid and using TTMSFNCDataGridExcelIO, we noticed a different behavior:

  • Regardless of whether the groups are collapsed or expanded in the active TTMSFNCDataGrid, the generated Excel file always has all groups fully expanded.

  • The export process does not seem to respect the current collapsed/expanded state of the grid groups.

Is there a specific property or a workaround we can use in TTMSFNCDataGridExcelIO (or during the export process) to make sure the exported file matches the visual state (collapsed/expanded) of the grid?

Thank you in advance for your help!

Best regards,
Lília Ferreira

Hello Lília,

In the current TTMSFNCDataGridExcelIO implementation there isn't a public property that exports the Excel outline collapsed/expanded state.

The closest built-in workaround is to make sure hidden/collapsed child rows are exported with their row height:

TMSFNCDataGridExcelIO1.Options.ExportCellSizes := True;
TMSFNCDataGridExcelIO1.XLSExport('export.xlsx');

If the collapsed state was set manually through RowNodeState, also hide the child rows before export:

for r := 0 to Grid.RowCount - 1 do
  if Grid.IsRowNode(r) and (Grid.RowNodeState[r] = grnsCollapsed) then
    for i := r + 1 to r + Grid.RowNodeChildCount[r] do
      Grid.HiddenRows[i] := True;

Then export with ExportCellSizes = True. This should make those rows invisible in Excel, although the rows may still exist in the file with height 0.

For a true “export only what is visually shown” result, the safer workaround is to export from a temporary TTMSFNCDataGrid (or TTMSFNCDataGridRenderer) containing only the currently visible rows, then call TTMSFNCDataGridExcelIO.XLSExport on that temporary grid.

So: no dedicated property at the moment; use ExportCellSizes plus temporary hiding, or build a visible-rows-only temporary grid for an exact visual export.

An alternative might also be the new renderer source feature: For more information on renderer sources, you can check here: Renderer source | TMS Software Documentation

Aqui tens uma versão mais simples, curta e direta ao ponto:

Hello Pieter,

Thank you for the detailed response!

We implemented the suggested workaround using a temporary grid to export only the visible rows, and it works perfectly.

Thanks again for your help!

Best regards,

Lília