Link to home
Start Free TrialLog in
Avatar of n00b0101
n00b0101

asked on

PEAR - Spreadsheet Excel Writer - File error

I query the database and retrieve the following array:

Array
(
      [0] => Array
      (
            [id] => 5689
            [item] => YUIOPD
            [size] => 8
            [cost] => $99.99
      )

      [1] => Array
      (
            [id] => 7664
            [item] => TYJKIP
            [size] => 12
            [cost] => $199.99
      )

      [2] => Array
      (
            [id] => 2113
            [item] => HYTIUP
            [size] => 4
            [cost] => $79.99
      )
)

I'm trying to enter that data into an excel spreadsheet using the Spreadsheet Excel Writer PEAR pkg. But, I keep getting: File error: data may be lost, and only the ids are in the spreadsheet, each on its own row.  I'm trying to figure out how to put each element into its own row for each one.

Right now, the code looks like this:
$excel = new Spreadsheet_Excel_Writer('textexcel.xls');
$sheet =& $excel->addWorksheet('worksheet 1');
$i = 0;
  foreach($res as $data) {
		foreach($data as $k => $v) {
				$sheet->write($i, $k, $v);
		}
		$i++;
  }
$excel->close();

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of MacAnthony
MacAnthony
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of n00b0101
n00b0101

ASKER

Thanks so much!