I have researched a lot to convert an xml file to 2d array in a same way excel does trying to make same algorithm as excel does when you open an xml file in excel.
<
The PHP library PHPExcel solves your issue:
https://phpexcel.codeplex.com/
You can find some samples here too:
https://phpexcel.codeplex.com/wikipage?title=Examples&referringTitle=Home
https://github.com/PHPOffice/PHPExcel/wiki/User%20Documentation
It's the most reliable Excel library for PHP and it's constantly maintained and upgraded.
Keep in mind that you can read (from an Excel file etc.) and write (to an Excel file, PDF etc.).