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

Add useEncoding to SimpleExcelReader #167

Merged
merged 1 commit into from
Apr 3, 2024
Merged

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
10 checks passed
@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