![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
![]() |

|
| Knowledge Base Most common error and how to trouble shoot them off |
![]() |
|
export as xls table
|
LinkBack | Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Fixed Error!
Posts: 141
Location: Chennai
Join Date: Feb 2007
Rep Power: 2
IM:
|
I want the tables to be generated in the browser window to be allso available as excell sheet, if requested through the webform (only the tables which are displayed in the browser, so maybe this can be done client-side ??). How can I do that? Preferably client side, since the server isn't that performant.. |
|
|
|
|
|
|
|
|
#2 (permalink) |
|
Fixed Error!
Posts: 141
Location: Chennai
Join Date: Feb 2007
Rep Power: 2
IM:
|
if ($mode=='csv') { header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="file.csv"'); echo csv($tab); exit; } /** * Emit a csv version of the tab. */ function csv($tab) { global $tabpath; $dq = '"'; $file = file_get_contents( "$tabpath/$tab" ); $file = normalize( $file ); list( $totalHours, $rate, $total, $litFile, $error ) = calculate( $file ); $lines = preg_split( '/\n/s', $file ); foreach( $lines as $line ) { $parts = preg_split('/ - /', $line); $o .= $dq.$parts[0].$dq.','; $o .= $dq.$parts[1].$dq.','; $o .= $dq.$parts[2].$dq.','; $o .= $dq.csvquote($parts[3]).$dq.','; $o .= $dq.preg_replace('/ minutes/','',$parts[4]).$dq.','; $o .= "\r\n"; } return $o; } function csvquote( $s ) { $s = preg_replace('/"/','""', $s); return $s; } I would modify the csv function like this. It takes a mysql result as an argument: /** * Emit a csv version of the result. */ function csv($result) { $dq = '"'; while( $row = mysql_fetch_row($result) ) { while( list($key,$value) = each($row) ) { $o .= $dq.csvquote($value).$dq; } $o .= "\r\n"; } return $o; } |
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|