从数据库到csv的导出数据需要很少的帮助。 不幸的是,我的国家有特殊字符čćšžđ。 导出工作正常,如果在Notepad ++中打开.csv,它会给我正确的单词形式。但是当它在Excel中打开时,特殊字符就像象形文字一样。 数据库中的示例我有: 出口前的阵列中的IZLETIŠTESTOJČIĆ:IZLETIŠTESTOJČIĆ,在Notepad ++中:IZLETIŠTESTOJČIĆ,但在Excel中我得到了IZLETIĹTESTOJÄŚIĆ
为什么不工作? 这是代码,我是否需要添加内容或者我需要在Excel中更改内容
function convertToCSV($data, $options) {
$exportName = implode($options['exportName']);
// setting the csv header
if (is_array($options) && isset($options['headers']) && is_array($options['headers'])) {
$headers = $options['headers'];
} else {
$headers = array(
'Content-Type' => 'text/csv,charset=UTF-8',
'Content-Disposition' => 'attachment; filename="'.$exportName.'.xls"'
);
}
$output = '';
// setting the first row of the csv if provided in options array
if (isset($options['firstRow']) && is_array($options['firstRow'])) {
$output .= implode(' ', $options['firstRow']);
$output .= "\n"; // new line after the first line
}
// setting the columns for the csv. if columns provided, then fetching the or else object keys
if (isset($options['columns']) && is_array($options['columns'])) {
$columns = $options['columns'];
} else {
$objectKeys = get_object_vars($data[0]);
$columns = array_keys($objectKeys);
}
// populating the main output string
foreach ($data as $row) {
foreach ($columns as $column) {
$output .= str_replace(' ', ';', $row->$column);
$output .= ' ';
}
$output .= "\n";
}
// calling the Response class make function inside my class to send the response.
// if our class is not a controller, this is required.
return Response::make($output, 200, $headers);
}
答案 0 :(得分:1)
试
protected function convertChar($text)
{
return @iconv('UTF-8','ISO-8859-2//TRANSLIT',$text);
}
的iconv( 'UTF-8', '的 your_code 强> // TRANSLIT',$文本);
答案 1 :(得分:0)
您可以尝试在返回之前在$search = array('%C4%8D','%C4%87','%C5%A1','%C5%BE','%C4%91');
$replace = array('č','ć','š','ž','đ');
$output = str_replace($search, $replace, $output);
上进行搜索和替换。这些字符可能是百分比编码的,所以你可以试试这个:
[
{ "mid" => 123, "updated" => "2015-05-05 05:05:05"}
{ "mid" => 456, "updated" => "2015-05-05 05:06:05"}
{ "mid" => 789, "updated" => "2015-05-05 05:05:05"}
{ "mid" => 123, "updated" => "2015-05-05 05:05:07"}
{ "mid" => 456, "updated" => "2015-05-05 05:05:05"}
]
如果有效,请告诉我。