Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP Pear Excel Spreadsheet Writer

Empfohlene Antworten

Veröffentlicht

Hallo zusammen,

ich erstelle mit folgender Funktion ein Excel Spreadsheet:


/**
* Exportiert eine MySQL Tabelle ins Excel format und sendet die Datei zum Browser
* @param string $location Speicherort auf dem Server
* @param string $filename Dateiname mit dem die Datei zum Download angeboten wird
* @param mysql_result $mysql_result Resultobject von mysql_query
*/
function rs2xls( $location, $filename, $mysql_result)
{
$filename = str_replace( ' ', '_', $filename);
$filename = str_replace( 'ä', 'ae', $filename);
$filename = str_replace( 'ö', 'oe', $filename);
$filename = str_replace( 'ü', 'ue', $filename);
$filename = str_replace( 'Ä', 'Ae', $filename);
$filename = str_replace( 'Ö', 'Oe', $filename);
$filename = str_replace( 'Ü', 'Ue', $filename);

$xls =& new Spreadsheet_Excel_Writer( $location);

// Send HTTP headers to tell the browser what's coming
handleError( $xls->send( $filename));

// Arbeitsblatt hinzufügen
handleError( $sheet =& $xls->addWorksheet( 'Tabelle1'));

$printHeaders = true;
$line = 0;
while(( $row = mysql_fetch_row( $mysql_result) )!== false) {
if ( $printHeaders) {
for ( $i = 0; $i < count( $row); $i++) {
$column = ucwords( mysql_field_name( $mysql_result, $i));
handleError( $sheet->write( $line, $i, $column));
}
$line++;
$printHeaders = false;
}

for ( $i = 0; $i < count( $row); $i++) {
handleError( $sheet->write( $line, $i, $row[ $i]));
}
$line++;
}

handleError( $xls->close());

return $filename;
}

function handleError( $obj) {
if (PEAR::isError($obj)) {
exit($obj->getMessage());
}
}
[/PHP]

Ich generiere damit eine Excel Datei auf dem Server und sende diese an den Client.

Die generierte Datei auf dem Server sieht genauso aus wie ich das haben will, aber leider bekommt der Client diese nicht "richtig" zum Download. Heisst also der Client bekommt eine andere Datei angeboten, als die die generiert wird...

Fehler gibt der Spreadsheet Writer keine aus, da diese ja ausgegeben in den Files stehen müsste, die auf dem Server generiert wurden...

Ich rufe die funktion so auf:

[PHP]
$result = mysql_query('SELECT * FROM tabelle');

rx2xls( "../files/rex_formbkk_kontakt/20050705_1725.xls",
"20050705_1725.xls",
$result);

Ich weiss langsam net mehr wo ich kucken soll :-(

Bin dankbar für jeden Tipp!

Gruß,

Markus

Hi,

Wo und wie wird die Datei denn geschickt?


handleError( $xls->send( $filename)); // senden der header
//snip
handleError( $xls->close()); // senden der Datei
[/PHP]

Danke für die Mühe,

Gruß,

Markus

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.