2015-05-29 83 views
2

我有一個包含非英文內容(俄語)的xlsx文件。我正在使用PHPExcel lib來讀取它。當我閱讀我的文件時,輸出是完全搞砸了?有沒有什麼辦法解決這一問題 ?我試圖轉換utf8,但沒有運氣。任何幫助將不勝感激。這是我的代碼。PHP使用PHPExcel讀取非英文內容的Excel文件lib

<?php 
include_once 'Classes/PHPExcel.php'; 
echo '<pre>'; 

$excelFile = "test.xlsx"; 

$objReader = PHPExcel_IOFactory::createReader('Excel2007'); 
$objPHPExcel = $objReader->load($excelFile); 

//Itrating through all the sheets in the excel workbook and storing the array data 
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) { 
    $arrayData[$worksheet->getTitle()] = $worksheet->toArray(); 
} 

/* function utf8_converter($arrayData) 
{ 
    array_walk_recursive($array, function(&$item, $key){ 
     if(!mb_detect_encoding($item, 'utf-8', true)){ 
      $item = utf8_encode($item); 
     } 
    }); 

     return $arrayData; 
} 
utf8_converter($arrayData); 
*/ 

print_r($arrayData); 

?> 

我的輸出,

[1] => Array 
       (
        [0] => 199 
        [1] => Clothing 
        [2] => ru 
        [3] => T shirt 
        [4] => БеÑплатный переводчик , перевод , БеÑплатный Ñловарь Интернет 
        [5] => БеÑплатный переводчик , перевод , БеÑплатный Ñловарь Интернет 
       ) 

      [2] => Array 
       (
        [0] => 203 
        [1] => Clothing 
        [2] => ru 
        [3] => pant 
        [4] => БеÑплатный переводчик , перевод , БеÑплатный Ñловарь Интернет 
        [5] => This test Short des 
       ) 

但是原來的值是什麼樣子,

Бесплатный переводчик , перевод , Бесплатный словарь Интернет 
+0

這哪裏是輸出到?一個控制檯?一個網頁? – Phylogenesis

+0

如果要輸出到網頁,請確保將其設置爲顯示UTF-8內容 –

+0

僅限於瀏覽器。 – Elavarasan

回答

-1

查找您的Excel庫代碼fputcsv(或類似的功能XLSX)調用。使所有必要的參數到它

INT fputcsv(資源$處理, 數組$字段[, 字符串$分界= 「」[, 字符串$外殼= '「'[,字符串$的escape_char = 」\「 ]]])

然後使用,

$text = "This is the Euro symbol '€'."; 

echo 'Original : ', $text, PHP_EOL; 
echo 'TRANSLIT : ', iconv("UTF-8", "ISO-8859-1//TRANSLIT", $text), PHP_EOL; 
echo 'IGNORE : ', iconv("UTF-8", "ISO-8859-1//IGNORE", $text), PHP_EOL; 
echo 'Plain : ', iconv("UTF-8", "ISO-8859-1", $text), PHP_EOL; 

這裏out_charset起着重要的作用。

如果追加字符串// TRANSLIT到out_charset音譯被激活。這種米意味着當字符不能在目標字符集中表示時,它可以通過一個或幾個相似的字符來近似。如果追加字符串// IGNORE,那麼無法在目標字符集中表示的字符會被丟棄。否則,會生成E_NOTICE並且函數將返回FALSE。

ISO 8859: 

ISO 8859-1 Western Europe 
ISO 8859-2 Western and Central Europe 
ISO 8859-3 Western Europe and South European (Turkish, Maltese plus Esperanto) 
ISO 8859-4 Western Europe and Baltic countries (Lithuania, Estonia, Latvia and Lapp) 
ISO 8859-5 Cyrillic alphabet 
ISO 8859-6 Arabic 
ISO 8859-7 Greek 
ISO 8859-8 Hebrew 
ISO 8859-9 Western Europe with amended Turkish character set 
ISO 8859-10 Western Europe with rationalised character set for Nordic languages, including complete Icelandic set 
ISO 8859-11 Thai 
ISO 8859-13 Baltic languages plus Polish 
ISO 8859-14 Celtic languages (Irish Gaelic, Scottish, Welsh) 
ISO 8859-15 Added the Euro sign and other rationalisations to ISO 8859-1 
ISO 8859-16 Central, Eastern and Southern European languages (Albanian, Bosnian, Croatian, Hungarian, Polish, Romanian, Serbian and Slovenian, but also French, German, Italian and Irish Gaelic) 

多字符集谷歌吧......

檢查的詳細信息,

[http://php.net/manual/en/function.iconv.php][1] 

[http://en.wikipedia.org/wiki/Character_encoding][2] 
+0

這不是簡單地讀取CSV文件....它正在讀取OfficeOpenXML格式的電子表格文件 –