0

I am trying to export to Excel some data using TMS's TFlexCelReport in Delphi 10.2 and getting an error which I cannot figure out how to fix. In an earlier version of Delphi (2007) and TMS it worked fine. The data is being retrieved from the database, some formatting is done and an XML file is created. Then, using this file and an xsl template file I'm trying to produce an Excel output but I'm getting an error saying that 'the named range MAIN on the Excel template refers to DataTable "MAIN" which is not defined. Verify that you added the dataset with FlexCelReport.AddTable method.' I tried adding it but it doesn't help. Not sure if I can attach the XML file and the template, in case any of them is relevant.

Tried adding the MAIN table but it doesn't help. It's on Windows 10.

procedure TdmExport.RunReport(const ExportFileName: String);
var
    Report: TFlexCelReport;
    TemplateStream: TResourceStream;
    OutputStream: TFileStream;
begin
    Report := TFlexCelReport.Create(true);
    try
        Report.GetInclude := GetIncludes;
        Report.AddTable('cdsExport', cdsExport);

        TemplateStream := TResourceStream.Create(hinstance, 'CATATemplatesOnTheExe', RT_RCDATA);
        try
            OutputStream := TFileStream.Create(ExportFileName, fmCreate);
            try
                Report.Run(TemplateStream, OutputStream);  // when executing this I get the error
            finally
                OutputStream.Free;
            end;
        finally
            TemplateStream.Free;
        end;
    finally
        Report.Free;
    end;
end;

Should get an Excel file formatted according to the template but I get the error I mentioned above.

procedure TdmExport.RunReport(const ExportFileName: String);
var
    Report: TFlexCelReport;
    TemplateStream: TResourceStream;
    OutputStream: TFileStream;
begin
    Report := TFlexCelReport.Create(true);
    try
        Report.GetInclude := GetIncludes;
        Report.AddTable('cdsExport', cdsExport);

        TemplateStream := TResourceStream.Create(hinstance, 'CATATemplatesOnTheExe', RT_RCDATA);
        try
            OutputStream := TFileStream.Create(ExportFileName, fmCreate);
            try
                Report.Run(TemplateStream, OutputStream);  // when executing this I get the error
            finally
                OutputStream.Free;
            end;
        finally
            TemplateStream.Free;
        end;
    finally
        Report.Free;
    end;
end;

The expected result is an Excel file built using the cdsExport.xml and the xsl template file. Instead I'm getting the error I mentioned above. Not sure if and how I could attach the xml and xsl files, if needed.

Ken White
  • 123,280
  • 14
  • 225
  • 444
  • 1
    Doesn't TMS offer support for their products? IIRC, they have support forums for users with licensed copies of their components. Have you asked there first? – Ken White Jun 28 '19 at 00:43
  • 2
    Are you adapt FlexCel ver 3 (D2007) template to new ver 6. Templates are not identical. ##cdsExport##field tags need to be changed to <#cdsExport.field>, the __MAIN__ range isn’t needed anymore, ... – Branko Jun 28 '19 at 06:35
  • Hi Ken, unfortunately I found out that the license we have doesn't include support unless there's a problem with their controls. – Mihai Valcu Jul 05 '19 at 15:04
  • Hi Branko, <#cdsExport.field> has the right format. I changed the name of the range from __MAIN__ to __cdsExport__ and now it runs without errors. However, it doesn't look like it should be. The template has the dange on the first row, an empty second row and the third row has "Time Records: " in the first column and the formula =COUNTIF(A3:A3,"<>") in the second column. – Mihai Valcu Jul 05 '19 at 15:12
  • What's expected as output is a number of rows with some values and the last row to have Total Records: and in the second column the number of rows the report produced. Instead, Total Records with a value of 0 and an empty row appears for all output rows, and a final Total Records with a value of 0. – Mihai Valcu Jul 05 '19 at 15:12
  • I am indeed using the new version 6 and before it was 3. With the range name change I don't get the error anymore but I cannot get the total number of records created by the report. What I need is a last row that has in the first column 'Total Records:' and in the second column the number of records the report produced. I kept on trying but nothing worked in this version 6. Thank you. – Mihai Valcu Jul 09 '19 at 15:30
  • I finally found a workaround and it's now working. There's only one small problem remaining: in the range on of the cells is set to center the content, however, when the report is output the cell content is left aligned. In v3 it was working fine. Any idea? Thank you. – Mihai Valcu Jul 11 '19 at 16:10

0 Answers0