We have several capabilities in our backend project that enable file export to xlsx. We tested everything out locally, and everything is functioning well. However, I installed the app on an Azure App Service, and some (not all) of the exports aren't functioning properly.
I set up the database (MySQL), frontend (React), and backend (PHP) in Azure. Because we don't want to waste time with the data, I moved the data from the local database to the database that was deployed in Azure.
For the export-related functionalities in the backend project, we use Laravel with Maatwebsite. I developed a class with construct, query, and headings functions as well as implementations of FromQuery, WithHeading, and ShouldAutoSize.
Next, in a Controller, I use this structure to get the file:
public function functionName(Request $request){ $fileName= 'name'.time().'.xlsx'; return (new ClassThatHasTheLogicOfExporting($request->all()))->download($fileName); }
All of my exports function as intended, however, occasionally I receive the message "Excel cannot open the file because the file format or file extension is not correct." I attempt to open the file.
I've been reading about the problem, and some people suggest that I use ob start() (at the start of the class) and ob end clean() (right before exporting the file), however when I do this, the web app returns a 404 error.
It's odd because the file opens without any issues when I add a filter to the data for exporting (for example, downloading only the data of persons in a specified city) (I can do it in the frontend app). I was able to download all the data in different batches using this approach, therefore I don't believe that the problem is due to unusual characters in the data.
Does anybody have any suggestions?