Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export from PHP to Excel

Tags:

php

excel

I need to export data from php to Excel, and be able to format various items in the excel spreadsheet.

So far, the best library that I have found is PHPExcel. However, it seems very heavy, and somewhat slow. Granted, it is very powerful.

Is there anything a bit more lightweight and faster, that allows me to export to excel and be able to apply simple formatting (bold, alignment, borders)?

like image 601
JonoB Avatar asked Oct 23 '10 20:10

JonoB


People also ask

Can PHP write to an Excel file?

PHP provides a library to deal with Excel files. It is called PHP Excel library. It enables you to read and write spreadsheets in various formats including csv, xls, ods, and xlsx. You will need to ensure that you have PHP's upgraded version not older than PHP 5.2 .

How do I Export data from MySQL to Excel?

Within MySQL for Excel, Open a MySQL Connection, click the employee schema, Next, select the location table, click Edit MySQL Data, then choose Import to import the data into a new Microsoft Excel worksheet for editing.

How connect Excel to PHP?

Establish a ConnectionOpen the connection to Excel by calling the odbc_connect or odbc_pconnect methods. To close connections, use odbc_close or odbc_close_all. $conn = odbc_connect("CData ODBC Excel Source","user","password"); Connections opened with odbc_connect are closed when the script ends.


1 Answers

I just got done with this yesterday. Using PHPExcel, I had no problems reading in a "master" document with formatting, writing 20-100 rows of content, and saving off the file (I save it "to screen" for immediate download. While some people on the forums complained about speed and overhead, I'm pushing a lot of data its way and it doesn't have any problem at all doing what it advertises.

Note that somewhere I read to do styling in series as opposed to in loops when possible. For example, style a1:a50 as opposed to style->a1, style->a2 in a loop. Apparently, the two different scenarios have very different memory implications.

The only gotcha I found was a few quirks between outputting and reading Excel 2003 files. If you're working entirely in XLSX files, it should function exactly as documented.

like image 66
bpeterson76 Avatar answered Sep 21 '22 08:09

bpeterson76