Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conv(): Wrong charset, conversion from MACCENTRALEUROPE' to UTF-8' is not allowed #989

Closed
DarkCobalt opened this issue Nov 16, 2016 · 4 comments

Comments

@DarkCobalt
Copy link

Hi I have problem when try use function \Excel::load then i have error iconv

Code

$filePath = 'storage/uploads/valued/'.$this->filename;
\Excel::load($filePath, function($excel){});

Package version, Laravel version

"laravel/framework": "5.1.*",
"maatwebsite/excel": "~2.0.0"

Expected behaviour

ErrorException in String.php line 496:
iconv(): Wrong charset, conversion from MACCENTRALEUROPE' to UTF-8' is not allowed

in String.php line 496
at HandleExceptions->handleError('8', 'iconv(): Wrong charset, conversion from MACCENTRALEUROPE' to UTF-8' is not allowed', '/home/forge/default/vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/String.php', '496', array('value' => 'U�ytkownik Microsoft Office', 'to' => 'UTF-8', 'from' => 'MACCENTRALEUROPE'))
at iconv('MACCENTRALEUROPE', 'UTF-8', 'U�ytkownik Microsoft Office') in String.php line 496
at PHPExcel_Shared_String::ConvertEncoding('U�ytkownik Microsoft Office', 'UTF-8', 'MACCENTRALEUROPE') in Excel5.php line 1244
at PHPExcel_Reader_Excel5->_readSummaryInformation() in Excel5.php line 623
at PHPExcel_Reader_Excel5->load('/home/forge/default/storage/uploads/valued/1479295210d287327d434a952d12b857fee0111cee.xls') in LaravelExcelReader.php line 227
at LaravelExcelReader->load('storage/uploads/valued/1479295210d287327d434a952d12b857fee0111cee.xls', null, false) in Excel.php line 118
at Excel->load('storage/uploads/valued/1479295210d287327d434a952d12b857fee0111cee.xls', object(Closure)) in Facade.php line 219
at Facade::__callStatic('load', array('storage/uploads/valued/1479295210d287327d434a952d12b857fee0111cee.xls', object(Closure))) in ImportValuedSheet.php line 57
at Excel::load('storage/uploads/valued/1479295210d287327d434a952d12b857fee0111cee.xls', object(Closure)) in ImportValuedSheet.php line 57
at ImportValuedSheet->handle() in ResumeManageController.php line 63
at ResumeManageController->postLoadFileValued(object(Request))
at call_user_func_array(array(object(ResumeManageController), 'postLoadFileValued'), array(object(Request))) in Controller.php line 256
at Controller->callAction('postLoadFileValued', array(object(Request))) in ControllerDispatcher.php line 164
at ControllerDispatcher->call(object(ResumeManageController), object(Route), 'postLoadFileValued') in ControllerDispatcher.php line 112
at ControllerDispatcher->Illuminate\Routing{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 114
at ControllerDispatcher->callWithinStack(object(ResumeManageController), object(Route), object(Request), 'postLoadFileValued') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\Resumes\ResumeManageController', 'postLoadFileValued') in Route.php line 203
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 708
at Router->Illuminate\Routing{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in Authenticate.php line 45
at Authenticate->handle(object(Request), object(Closure))
at call_user_func_array(array(object(Authenticate), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 710
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 675
at Router->dispatchToRoute(object(Request)) in Router.php line 635
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in Debugbar.php line 49
at Debugbar->handle(object(Request), object(Closure))
at call_user_func_array(array(object(Debugbar), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in VerifyCsrfToken.php line 50
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 53

@DarkCobalt
Copy link
Author

This is file when i got error
wycena_polis_2016-11-16 11-27.xls.zip

@lhcGinv
Copy link

lhcGinv commented Nov 25, 2016

this is my promble too:
iconv(): Detected an illegal character in input string
ConvertEncoding('商品分类demo', 'UTF-8', 'CP1252')

@lhcGinv
Copy link

lhcGinv commented Nov 25, 2016

To avoid this error,the first row must use utf-8 code in my excel file

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Jul 7, 2021
Fixes issue PHPOffice#549 and SpartnerNL/Laravel-Excel#989 (which is the source of the new test file). Some systems accept MACCENTRALEUROPE as the name for the appropriate encoding, and some accept MAC-CENTRALEUROPE. I fortunately have access to at least one of each type, and have run the tests on each.

CodePage.php has an array of translations from codepage number to string. I now allow the value to itself be an array; if so, the code will test each in turn to see if it can be used in iconv. I did not go fishing for other similar problems. If such show up, they can be dealt with in the same manner as this one. I don't really expect others, since this is a problem not merely for Xls, but, even then, it applies only to BIFF5 and earlier.

I also moved XlsTest from Reader to Reader/Xls.
MarkBaker pushed a commit to PHPOffice/PhpSpreadsheet that referenced this issue Jul 12, 2021
* Xls Reader Handle MACCENTRALEUROPE With or Without Hyphen

Fixes issue #549 and SpartnerNL/Laravel-Excel#989 (which is the source of the new test file). Some systems accept MACCENTRALEUROPE as the name for the appropriate encoding, and some accept MAC-CENTRALEUROPE. I fortunately have access to at least one of each type, and have run the tests on each.

CodePage.php has an array of translations from codepage number to string. I now allow the value to itself be an array; if so, the code will test each in turn to see if it can be used in iconv. I did not go fishing for other similar problems. If such show up, they can be dealt with in the same manner as this one. I don't really expect others, since this is a problem not merely for Xls, but, even then, it applies only to BIFF5 and earlier.

I also moved XlsTest from Reader to Reader/Xls.

* Cache Successful Result For Future Use

Per suggestion from @MarkBaker
@lintaba
Copy link

lintaba commented Oct 21, 2021

seems like autodetect is not the same name as its in iconv. (MACCENTRALEUROPE vs MAC-CENTRALEUROPE)

what helped me is this:

// composer.json
    "autoload": {
...
        "files": ["override/StringHelper.php"]
    },

copy builtin StringHelper to your override/StringHelper.php location, and add the following "hack":

public static function convertEncoding($value, $to, $from)
    {
        if($from === "MACCENTRALEUROPE"){$from = "MAC-CENTRALEUROPE";} //patched
        if($from === "MACCYRILLIC"){$from = "MAC-CYRILLIC";} //patched
        if (self::getIsIconvEnabled()) {
            $result = iconv($from, $to . self::$iconvOptions, $value);
            if (false !== $result) {
                return $result;
            }
        }

        return mb_convert_encoding($value, $to, $from);
    }

(edit: i can see that there were a fix for this, so if you can, use that :) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants