Jump to content
php.lv forumi
Sign in to follow this  
shurix

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";
}

Share this post


Link to post
Share on other sites

Es nezinu kāds ir risinājums, bet visdrīzāk sāktu ar meklēšanu google - "php excel utf8"

Share this post


Link to post
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
Sign in to follow this  

×