FNCData Grid Export XLSX

Hello,
I have a problem with FNCDataGrid and exporting to Excel using the TFlexCelVCL component. The export works great, but after the export, an exception occurs in the grid, and the previously selected row remains frozen. The Refreshdata(true) function allows you to bypass the exception and continue working, but the cell remains frozen. If no cell is previously selected, everything works fine. When I use the export function with TAdvStringGrid, it works without any problems. Therefore, I've ruled out the possibility that it's the export itself. What could be the cause? Thanks
Steffen Weiner

Hi,

Can you share the code you are using the export? Did you properly combine BeginUpdate/EndUpdate? Did you use ExportNotification during the export?

Hello,
this is the routine how I export the data. After exporting and as soon as the mouse cursor is moved to the grid the following error occurs. EAccessViolation in
0000000002D457FB 00000000024657FB 000000ABFC0FE858 IFProgressio.exe 00000000008E0000 VCL.TMSFNCDataGridCell.pas VCL.TMSFNCDataGridCell TTMSFNCDataGridCell GetDisplayValue 1589 4

thank you :slight_smile:
#This is my code
with IFRevenue do
begin
if FNCGrid.ColumnCount<8 then
Xls.MergeCells(1, 1, 1, 8)
else Xls.MergeCells(1, 1, 1, FNCGrid.ColumnCount-1);
fmt := Xls.GetDefaultFormat; //Always initialize the record with an existing format.
fmt.font.Size20:=250;
fmt.Font.Color := clblack;
fmt.FillPattern.Pattern := TFlxPatternStyle.Solid;
fmt.FillPattern.FgColor := $00FEC5BC;
fmt.FillPattern.BgColor := clWhite;
XF := Xls.AddFormat(fmt); //string
//kopf übernehmen
with FNCGrid do
begin
for i:=1 to columncount-1 do
begin
Xls.SetCellValue(4, i, cells[i,0].ToString);
Xls.SetCellFormat(4, i, XF);
end;
AdvStatusbar.Panels[2].Text:=' Bitte Geduld... Export erfolgt';
AdvStatusbar.Panels[1].Progress.Position:=0;
AdvStatusbar.Panels[1].Progress.Max:=(rowcount-1);
Application.ProcessMessages;
for i:=1 to rowcount-1 do
begin
AdvStatusbar.Panels[1].Progress.Position:=i;
if IsRowFiltered(i)=false then
begin
for j:=1 to columncount-1 do
begin
fmt := Xls.GetDefaultFormat;
fmt.font.Size20:=220;
if Layouts[j,i].Fill.Color<>CellAppearance.FocusedLayout.Fill.Color then
fmt.FillPattern.FgColor := Layouts[j,i].Fill.Color
else fmt.FillPattern.FgColor:=clwhite;
fmt.FillPattern.BgColor := clWhite;
fmt.Borders.Left.Color:=clsilver;
fmt.Borders.Left.Style := TFlxBorderStyle.Thin;
fmt.Borders.Right.Style := TFlxBorderStyle.Thin;
fmt.Borders.Right.Color:=clsilver;
fmt.Borders.Top.Style := TFlxBorderStyle.Thin;
fmt.Borders.Top.Color:=clsilver;
fmt.Borders.Bottom.Style := TFlxBorderStyle.Thin;
fmt.Borders.Bottom.Color:=clsilver;
fmt.FillPattern.Pattern := TFlxPatternStyle.Solid;
XF := Xls.AddFormat(fmt); //standard
fmt.Format:='0';
XF_I := Xls.AddFormat(fmt); //integer
fmt.Format:='0000000';
XF_Projekt := Xls.AddFormat(fmt);
fmt.Format:='dd.mm.yyyy';
XF_D := Xls.AddFormat(fmt); //date
fmt.Format:='#.## €;-#.## €';
XF_C := Xls.AddFormat(fmt); //währung
fmt.Format:='#.##';
XF_F := Xls.AddFormat(fmt);

                      if Columns[j].Formatting.&Type=gdftFloat then
                      begin
                          swert:=cells[j,i].tostring;
                          swert:=Stringreplace(swert,'.','',[rfreplaceall]);
                          if trim(swert)<>'' then
                             fwert:=(StrToCurr(swert))
                          else fwert:=0;
                          //fwert:=floats[j,i];
                          Xls.SetCellValue(i+4, j, fwert);//CurrToStrF(fwert, ffCurrency, 2));
                          xls.SetCellFormat(i+4,j,XF_C);
                      end else
                      if Columns[j].Formatting.&Type=gdftdate then //datum
                      begin
                           if TryStrToDate(cells[(j),(i)].ToString, dwert) then
                              Xls.SetCellValue(i+4, j, dwert);
                           xls.SetCellFormat(i+4,j,XF_d);
                      end else
                      if Columns[j].Formatting.&Type=gdftNumber then
                      begin
                           if TryStrToInt(cells[(j),(i)].tostring,iwert)=true then
                           begin
                                Xls.SetCellValue(i+4, j,iwert);
                                xls.SetCellFormat(i+4,j,XF_i);
                           end else
                           begin
                                sWert:=cells[(j),(i)].ToString;
                                Xls.SetCellValue(i+4, j, swert);
                                xls.SetCellFormat(i+4,j,XF);
                           end;
                      end else
                      begin
                           sWert:=cells[(j),(i)].ToString;
                           Xls.SetCellValue(i+4, j, swert);
                           xls.SetCellFormat(i+4,j,XF);
                      end;
                  end;
                end;
                application.ProcessMessages;
          end;

     end;
     ApplyFormat := TFlxApplyFormat.Create;
     ApplyFormat.SetAllMembers(false);
     ApplyFormat.Borders.SetAllMembers(true);
     fmt := Xls.GetDefaultFormat;
     fmt.Borders.Left.Style := TFlxBorderStyle.Thin;
     fmt.Borders.Right.Style := TFlxBorderStyle.Thin;
     fmt.Borders.Top.Style := TFlxBorderStyle.Thin;
     fmt.Borders.Bottom.Style := TFlxBorderStyle.Thin;
     Xls.SetCellFormat(4, 1, 4, FNCGrid.ColumnCount-1, fmt, ApplyFormat, true);  //Set last parameter to true so it draws a box.
     xls.CellMarginFactor:=1.1;
     try
        for i:=1 to  FNCGrid.ColumnCount-1 do
             xls.AutofitCol(i,false,1.2);

     finally
            setze_Cursor(0);
     end;
     setze_Cursor(0);
end;
//Make the page print in landscape or portrait mode
Xls.PrintLandscape := true;

Hello,
has the problem been analyzed yet?
thank You :slight_smile:

Hi,
I've tried here but I couldn't reproduce it, it is probably related to the exact data that you have in the grid. You can get the test app I used (It is mostly your code) here:
https://download.tmssoftware.com/flexcel/samples/fnc_data_grid_export.zip

Do you see the behavior also in this app?
If you don't, can you think in anything that you might be doing different that could cause it?

And finally, to know if this is FlexCel related or FNCDataGridRelated, what happens in your project if you comment out the lines that call FlexCel but keep the rest of the code?

Hi, I found the problem. It seems to be related to the TaskDialog component.
with TMSFNCTaskDialog1 do
begin
Title:='Open file ...';
Content:='Do you want to open the file you just created? ';
Instruction:='Open file?';
if Execute=mryes then
ShellExecute(Handle, 'open', PChar(FileSaveDialog.FileName), nil, nil, SW_SHOWNORMAL);
end;

If I add this query, the previously selected row in the grid remains focused and an exception occurs. If I remove the TaskDialog component and add only the ShellExecute(Handle, 'open', PChar(FileSaveDialog.FileName), nil, nil, SW_SHOWNORMAL); query, everything works fine. I hope this helps a little with the search :-) Thanks
Project2.zip (97.9 KB)