MySQL to Excel generation using PHP

后端 未结 7 1060
遇见更好的自我
遇见更好的自我 2021-01-06 22:00


        
相关标签:
7条回答
  • 2021-01-06 22:17

    You're not really generating an Excel file. You're generating what amounts to a .csv file using tabs as the seperator.

    To generate a 'real' Excel file, use PHPExcel.

    0 讨论(0)
  • 2021-01-06 22:17

    The problem is that when Excel sees a file ending in .xls, it expects the file to conform to its BIFF standard. Your code does not produce a BIFF-compliant file. If you want, I can provide you with PHP functions that produce BIFF-compliant files, but it's too long to post here.

    0 讨论(0)
  • 2021-01-06 22:21

    You seem to be generating a file with tab-separated fields, and are claiming in your headers that this is the same format as a binary Excel spreadsheet uses. It isn't the format Excel uses. And the program loading the spreadsheet is letting you know that you are misleading people - possibly just yourself.

    You should probably look into using an export format such as a CSV file; converting from tab-delimited to comma-separated is not going to be hard.

    0 讨论(0)
  • 2021-01-06 22:29

    If you're just going to create a tab delimited file, why not skip PHP and let MySQL do it for you with SELECT INTO OUTFILE?

    PHP can handle the download part. Set the Content-type header to text/plain. Excel knows how to open that.

    0 讨论(0)
  • 2021-01-06 22:29

    Your program is looking for a standard .xls document, which is entirely different than what you are outputting. Your program outputs a tab delimited sheet, which is a .txt file. Try switching your program from tabs to commas as delimiters and saving as a .csv (comma separated value).

    0 讨论(0)
  • 2021-01-06 22:30

    Try PEAR's (PHP Extension and Application Repository) Spreadsheet_Excel_Writer. I use that to generate Excel files in the BIFF format.

    0 讨论(0)
提交回复
热议问题