LoginSignup
0
1

More than 3 years have passed since last update.

Goodby CSVライブラリのパース時のエラー

Posted at

はじめに

LaravelでCSVインポートし、DB登録する処理を実装するために、Goodby CSVライブラリを
インストールし、いざ実装したところ、以下のようなエラーが出てしまった。

Column size should be 7, but 6 columns given

エラー解決方法

CSVファイルの中身を確認したところ、列数が通常だと7列あるべきところ、6列となっている
ところがあったため、エラーが返ってきたようだ。
githubにもしっかり書かれていました。英語読めるようになりたい、、、

解決方法①

unstrict()を追加すると厳密な列数のチェックが行われないようになる。

$interpreter = new Interpreter();
$interpreter->unstrict();    //追加

解決方法②

例外を投げる。こちらの方法のほうがより現実的?

use Goodby\CSV\Import\Standard\Exception\StrictViolationException

~省略~

try {
    $lexer->parse($tmpPath, $interpreter);
} catch (StrictViolationException $e) {
    // 例外処理を書く
}

参考

https://github.com/goodby/csv

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1