Jump to content

Export to Excel


jacmaes
 Share

Recommended Posts

A group of architects doing field and statistical research on city neighborhoods came to me to create an online database that they could edit from anywhere. PW seemed like the perfect choice since it's very easy to customize the admin to fit their needs, and they are indeed quite happy.

Now, however, they'd like to have an Excel file of all the neighborhoods, one on each row, so that they can work with the data offline and produce printed documents of their research.

The PW tree is organized geographically: region > city > neighborhood. In other words, each neighborhood is a page with about 40 fields (and growing). How would you guys go about it? 

Link to comment
Share on other sites

I have recently used this code to create CSV, works great.

// array, with for each row an array
$array = array(
    array('val 1 - row 1', 'val 2 - row 1', 'val 3 - row 1'),
    array('val 1 - row 2', 'val 2 - row 2', 'val 3 - row 2'),
    array('val 1 - row 3', 'val 2 - row 3', 'val 3 - row 3'),
    etc...
    );

	
$out = '';
$handle = fopen('php://temp', 'r+'); // temp read/write file-like wrapper
foreach ($array as $line) fputcsv($handle, $line, ',', '"');
rewind($handle);
while (!feof($handle)) $out .= fread($handle, 8192);
fclose($handle);
echo trim($out);
  • Like 4
Link to comment
Share on other sites

There are other libraries, but this one is pretty powerful:

phpexcel.codeplex.com

Moved to here https://github.com/PHPOffice/PHPExcel

I have used it to generate excel files from PW. Cool thing is that it also allows you to automatically generate charts from the data.

Edited by Pete
Project has moved to Github
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...