CSV, characters problem with write


i am reading some data from REST and then I am writing them to CSV file.
Data has special characters which are seend in csv file correctly but when CSV file is opened, the characters are not presented correctly.

Characters like “č,ć,š,ž”
My code:
writer := csv.NewWriter(file)
defer writer.Flush()
writer.UseCRLF = true
err := writer.Write(value)

thank you!

I’m not sure about this but it sounds like a UTF-8 encoding problem on your end. Might help you figure out where to look.


The problem is Excel. It defaults to open csv files with wrong encoding. There is 3 solutions

  1. Import from inside Excel https://support.office.com/en-us/article/text-import-wizard-c5b02af6-fda1-4440-899f-f78bafe41857?ui=en-US&rs=en-US&ad=US
  2. Change extension to .txt and right click it and select open with Excel and then will Excel show the same import guide
  3. Convert the file to the format Excel will import automatically. It is a UTF16LE file with the first line is a 16-bit word 0XFFFE followed by “sep=\t\n” and then the rest of the file as UTF16LE (little endian). Maybe you could switch the two first bytes and use UTF16BE (big endian)

The program that is reading this CSV file is on windows server.
OS where golang runs is linux (docker -> golang 1.8)

And which program is it?

Does it require a certain encoding or can you change the encoding to match with what go emits?

You should probably update. 1.11 is current and 1.8 is probably not supported by many libraries anymore, usually only current and last minors are supported by the libraries, that means: 1.11 and 1.10.

1 Like

hello @NobbZ for sure it require certain ecoding, UTF8. But from documentation part of library, it should be UTF8. I tried to find how to change encoding but with no luck…

I will try to upgrade golang

Well, we do not know where your data comes from, maybe it’s already in the wrong format? Depending on how you read and write the data might get converted but does not necessarily…

So you need to show more code perhaps even a simplified input.


i am using librarie: https://github.com/Genert/pipedrive-api/

result, _, err := client.Persons.List(context.Background()) and then save with above code

func CsvGen(data [][]string) {

file, err := os.Create("result.csv")
checkError("Cannot create file", err)
defer file.Close()

writer := csv.NewWriter(file)
defer writer.Flush()
writer.UseCRLF = true

for _, value := range data {
	//	fmt.Println("before for:", len(value))
	for {
		if len(value) >= 5 {
		} else {
			value = append(value, "")
		//fmt.Println("izven loopa:", len(value))


	err := writer.Write(value)
	checkError("Cannot write to file", err)



Sorry, I do not know that API or library.

Please show the the fmt.Printf("%#v", []byte(item)) representation of an broken example, how you’d expect to see it and what you see instead.

I’m still the opinion that the encoding in your datasource is not UTF-8.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.