109221793
109221793

Reputation: 16867

Set encoding for Apache POI excel workbook

I'm using the Apache POI library to create, and fill an excel sheet in C# .NET.

The problem I'm faced with however, is that the data I populate my workbook with, contains some special characters (e.g. é, á, í, etc). I have been told that I need to create the worksheet with UTF-8 encoding in order for our partners to be able to auto ingest these excel files.

Does anyone who has experience using the POI library know how to set this value?

Upvotes: 0

Views: 2911

Answers (1)

Gagravarr
Gagravarr

Reputation: 48326

Apache POI is normally used from Java, so I don't know if the fact that you're using C# is affecting things or not...

If you were using POI in pure Java, then you simply create a Java String with your characters in it as normal. Next, pass that String to POI when setting the cell contents. POI will either store the text as ASCII or Unicode depending on the contents, and you don't need to do anything. (The encoding is all handled for you)

I'd suggest you ensure that you're creating the string properly with the international characters in it, then try passing that string to POI and see what happens. Hopefully C# will behave the same as Java and you'll be fine!

(If not, you might need to look into your C# / Java bridge, since as long as the right Unicode strings turn up in Java then POI should be correctly handling all the encoding stuff for you)

Upvotes: 1

Related Questions