2016-12-05 3 views
0

Microsoft Office ExcelでサポートされているCSVファイルを生成するにはどうすればよいですか?Laravel Microsoft Office ExcelをサポートするCSVを作成する

Laravel/Excel(http://www.maatwebsite.nl/laravel-excel/)を使用してCSVを作成しましたが、内容は日本語の文字です。

Microsoft Office Excelを使用してCSVを開くと、Microsoft Office Excelで読み込みできない日本のチャレーターが表示されます(既にloadView()関数を使用してCSVを作成しているため)

メモ帳でCSVを開き、変更を保存せずにMicrosoft Office Excelと日本語の文字を使用して再度開きます。

何が起こったのですか?メモ帳でファイル(既定のものとメモ帳から保存されたcsv)の両方を開いて、別のものを確認してください。コンテンツファイルには違いはありません。

マイビュー:

<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/plain; charset=UTF-8" /> 
    </head> 
    <body> 
     <table> 
      <thead> 
       <tr> 
        @foreach($keys as $key) 
         <th>{!! $key !!}</th> 
        @endforeach 
       </tr> 
      </thead> 
      <tbody> 
       @foreach($contents as $content) 
        <tr> 
         @foreach($keys as $key) 
          <td>{!! $content[ $key ] !!}</td> 
         @endforeach 
        </tr> 
       @endforeach 
      </tbody> 
     </table> 
    </body> 
</html> 

マイコントローラー:

Excel::create('locations-' . date('Y-m-d'), function ($export_file) { 
    $export_file->sheet('Locations', function($sheet) { 
     $sheet->loadView('admin.layout.export', Location::getExportData()); 
    }); 
})->download($type); 

場所:: getExportData():

public static function getExportData() { 
    $data[ 'contents' ] = []; 
    $data[ 'keys' ] = [ 
     'control', 
     'name', 
     'type', 
     'address', 
     'longitude', 
     'latitude', 
     'description' 
    ]; 

    $count = Location::count(); 
    if($count > 0) { 
     $off_ex = 1000; 
     for($i = 0; $i < ($count/$off_ex); $i++) { 
      $locations = Location::skip($i * $off_ex)->take($off_ex)->get(); 
      foreach ($locations as $key => $location) { 
       $data[ 'contents' ][] = [ 
        'control' => '', 
        'name' => mb_convert_encoding($location->name, "UTF-8"), 
        'type' => $location->type, 
        'address' => $location->address, 
        'longitude' => $location->longitude, 
        'latitude' => $location->latitude, 
        'description' => $location->description 
       ]; 
      } 
     } 
    } 

    return $data; 
} 

画像:

enter image description here

+0

であなたは、このcsvファイルとcsvファイル自体を生成するために使用されるコードを投稿してください。 – Jerodev

+0

@Jerodevは私の質問を更新 –

答えて

0

この問題を解決するには、ビューファイルの先頭に<meta charset="UTF-8">を含めるようにしてください。

detailed reference

+0

それはインポートする設定ですか?私は輸出する必要があります –

+0

@ YudiYohanesSeptianGotama申し訳ありません!私の間違い。私の更新された答えを見てください。 –

+0

はい私はそれにメタを含む、私は自分のコードで私の質問を更新 –

関連する問題