How to preserve leading zeros when generating a spreadsheet report?

I am generating a Report in LO Base 24.8.4.2 (Flatpak) and have codes with leading zeros that must be preserved. Is there a way to do that? Formatting is set to Text in the report Formatted field.

If you set the format to Text it will show the content of the field as it is saved in the database. In the database all numeric fields won’t save leading zeroes. You could only get this by formatting in a table, form or something else. Same will be in a report. So I would use a numeric formatting in report to get the zeroes.
Which database do you use? You could try to convert the numeric values to text content with leading zeroes by a query.

They are fixed-length CHAR values in the embedded HSQLDB 1.8 with leading zeros stored. They are only lost when the report is generated.

You set the report for executing in Calc? Then it might help to set ’ in front of the text content. You could get this by entering a formula in the report.
="'" & [MyNumber]
with a field called “MyNumber”.
Text content will be masked with ’ in Calc. So Calc doesn’t try to get a number.

Yes, Report Output Format is set to the second option, ODF Spreadsheet. Adding the single quote symbol does prevent Calc from removing the leading zeros but it doesn’t remove the symbol too. So it’s still a bit different from the desired format that I wanted to use to compare outputs via CSV diff. I’ll mark it as solution later if there is really no other way.

Have tried it now here with an example database. ’ indeed would set the ’ in front. Then changed in report to default format with leading zeroes. This will work.