Php Excel错误-空间字符显示为0
我在excel数据中遇到问题。我有一些PHP代码。此代码提取excel文件中的数据。在一列中,我得到了“0”值,这是错误的。实际数据为“@GTQ$/X0st” 我正在努力克服它。我不知道怎样才能解决这个问题 以下是我的功能:Php Excel错误-空间字符显示为0,php,excel,Php,Excel,我在excel数据中遇到问题。我有一些PHP代码。此代码提取excel文件中的数据。在一列中,我得到了“0”值,这是错误的。实际数据为“@GTQ$/X0st” 我正在努力克服它。我不知道怎样才能解决这个问题 以下是我的功能: function user_download_xls($userids, $fields, $includecompanyfield) { global $CFG, $SESSION, $DB; require_once("$CFG->libdir/
function user_download_xls($userids, $fields, $includecompanyfield) {
global $CFG, $SESSION, $DB;
require_once("$CFG->libdir/excellib.class.php");
require_once($CFG->dirroot.'/user/profile/lib.php');
$filename = clean_filename(get_string('users').'.xls');
$workbook = new MoodleExcelWorkbook('-');
$workbook->send($filename);
$worksheet = array();
$worksheet[0] = $workbook->add_worksheet('');
$col = 0;
foreach ($fields as $fieldname) {
if ($includecompanyfield || $fieldname != "profile_field_company") {
$worksheet[0]->write(0, $col, $fieldname);
$col++;
}
}
$worksheet[0]->write(0, $col, 'temppassword');
$row = 1;
foreach ($userids as $userid) {
// Stop the script from timing out on large numbers of users.
set_time_limit(30);
if (!$user = $DB->get_record('user', array('id' => $userid))) {
continue;
}
$col = 0;
profile_load_data($user);
foreach ($fields as $field => $unused) {
// Stop the script from timing out on large numbers of users.
set_time_limit(30);
if ($includecompanyfield || $field != "profile_field_company") {
$worksheet[0]->write($row, $col, $user->$field);
$col++;
}
}
$tempcode = company_user::get_temporary_password($user);
$worksheet[0]->write($row, $col, $tempcode);
$row++;
}
//exit;
$workbook->close();
die;
}
我的列正在从此步骤填充-$sheetwork[0]->write($row,$col,mb_convert_encoding($tempcode))
我尝试了谷歌的所有步骤,如下所示:
-utf8_解码
-htmlspecialchars
-mb_转换_编码
更新:调试后,我发现空间字符阻止显示正确的数据<代码>@位于将数据转换为0的第一个位置。我想我把数据转换成计算
提前感谢。utf8\u解码或utf8\u编码您使用哪一种?因为如果您的文本未在ISO-8859-1中编码,则不需要此函数。如果你的文本已经是UTF-8格式,你就不需要这个utf8_编码函数了。@Nawin,是的,你是对的。如果你有什么办法解决这个问题,请告诉我。谢谢