My Blog
Excel to csv as utf8 encode directly by Nicolas
- September 16, 2017
- -
- General
- -
- nicolas
Hi, I am Nicolas, you know me and I know you, we are humans with problems 😉
Unfortunately this year, I do not have much time to upload articles and videos because of my job as a web developer.
Many pieces of my work in the company I'm working on are automated on websites.
So wanting and not, I discover new things where I have decided from now on to share them with the world.
Because I will need a lot of time to upload all the articles, I will start with the last problem I faced.
A few days ago I encountered a problem.
I uploaded a csv file to e-shop bagdome.gr.
I use the file with the "wp all import" plugin on wordpress to import products.
The problem is that the file contained Greek characters and I had to open it with the notepad every time, and save it as utf8 encode.
The problem is that in the last few days I started to add the Bulgarian language in due to a new e-shop, which had to pull its data through bagdome.gr with xml.
I found out that by doing the export from excel to csv file, the Bulgarian characters were like this: ????????????
So I had to find a way to do the excel itself exporting csv to utf8.
As the old man say's, you must ask to find your way so, I searched on google and found nothing except some information from a source that led me to solve the problem by using an .exe, a vba code and a .bat file.
See the solution below:
- Create a folder in your C: Drive and name it CSV
- Open that folder and create a new file by right click and choose "new text file" and name it as "convert.bat" be carefull, the extension of the file must be .bat , not .txt
- Right click on the new file you just create and choose edit, and add the following code inside and save it: "%~dp0xls2csv.exe" "%~dp0temp.xls"
- Ok now download the following tool and extract it inside the folder: https://drive.google.com/open?id=0B0-xSvKcaUZhOHhldWdHd0F2Mkk
- Ok now its time to move the excel file you working on to C:CSV
- Open your excel file and search for the Developer tab, if you can't see it up there, go to File>Options>Customize Ribbon and check the Developer Tab and click OK.
- As soon as you are on developer tab, click on Visual Basic button.
- As soon as the visual basic window opens, right click on your left sidebar and choose Insert>Module
- As you can see the window of the new module opens so you can write your vba code inside
- Copy & Paste the following code: https://pastebin.com/v6sQudTC
- Read the comments with the green color and edit the code according to your needs.
- As soon as you finish with the code, close the visual basic window and save your excel file.
- Final go on Developer Tab, click the Macro button, choose your Macro and click Run
If everything is Ok an explorer window will open with your newly created csv file inside encoded as utf8.
This article is not finished 100%, I will record a video for this and also I will create a setup app with a demo excel inside so you can use it without the need of doing all this steps.
Best Regards, Nicolas Lagios
This post is also available in: Ελληνικά