Skip to content

Conversation

aminevg
Copy link
Contributor

@aminevg aminevg commented Apr 3, 2024

This PR adds a useEncoding method to SimpleExcelReader to allow use of custom encodings (SHIFT_JIS, EUC_JP, etc).

Currently, opening files in encodings other than UTF-8 can lead to garbled output. This allows us to set the exact encoding we want the data to be in.

This also enables us to check what encoding our data is in. An example:

function check_csv_encoding(string $path, string $encoding): bool
{
    try {
        SimpleExcelReader::create($path)->useEncoding($encoding)->getHeaders();

        return true;
    } catch (\OpenSpout\Common\Exception\EncodingConversionException $e) {
        return false;
    }
}

I am not sure if this should be something this library should handle, but if needed, I can make a PR for that as well.

@freekmurze freekmurze merged commit 256d710 into spatie:main Apr 3, 2024
@freekmurze
Copy link
Member

Thanks!

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

Successfully merging this pull request may close these issues.

2 participants