Jump to content
php.lv forumi

Exports uz exceli utf8


Recommended Posts

Problēma exportējot datus uz excel failu. Palielam viss darbojas, vienīgā problēma, ka tiek izkropļotas garumzīmes un mīkstinājuma zīmes. Kā varētu pielabot šo kodu, lai problēmu novērstu un garumzīmes rādītos?


function cleanData(&$str) {
$str = preg_replace("/\t/", "\\t", $str);
$str = preg_replace("/\r?\n/", "\\n", $str);
if(mb_strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';

$filename = "poll_".$pollid."_" . date('Ymd') . ".xls";

header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel");

$flag = false;
foreach($excel as $row) {
if(!$flag) {
echo implode("\t", array_keys($row)) . "\r\n";
$flag = true;
array_walk($row, 'cleanData');
echo implode("\t", array_values($row)) . "\r\n";

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...