PHPExcel - 将奇怪的字符保存到数据库

PHPExcel - Saving weird Characters to Database

我正在使用 PHPExcel 版本 1.8.0,2014-03-02。

在 Excel 我有这种细胞: Ahumada nº 301 / Huérfanos

但是在数据库中显示: Ahumada nº 301 / Huérfanos

有人知道如何解决这个问题吗?

这是我的代码:

include 'PHPExcel/IOFactory.php';
$inputFileName = 'data.xlsx'; 

try {
    $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
} 
catch(Exception $e) {
die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}

$allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
$arrayCount = count($allDataInSheet);

for($i=2;$i<=$arrayCount;$i++){
    $local      =   trim($allDataInSheet[$i]['A']);
    $descripcion=   trim($allDataInSheet[$i]['B']);
    $comuna     =   trim($allDataInSheet[$i]['C']);
    $region     =   trim($allDataInSheet[$i]['D']);
    $insertTable= "INSERT INTO sucursales (Numero, Direccion, Comuna, Region, ID_Cliente) VALUES('".$local."', '".$descripcion."','".$comuna."', '".$region."', '".$_POST['select_cliente2']."');";
    mysqli_query($con,$insertTable);
}

谢谢!

找到方法了!我只是在 php 中添加了这一行,一切正常!

header('Content-Type: text/html; charset=utf-8');

我加了

mysqli_set_charset($con, "utf8")

连接到 mysql,现在正常工作!

谢谢。