Issue in decoding the characters #3010

Closed
opened 2023-10-12 06:42:26 +00:00 by Vish101 · 4 comments

cptable.utils.decode(65001, 'GÜNDÜZ TRAFO ELEKTRİK MAKİNALARI TURİZM', 'str')

getting the wrong decoding

'G܎Dܚ TRAFO ELEKTR렍AKARI TUR𚍀'

Please give me solution so I can decode these charcter and other language characters

cptable.utils.decode(65001, 'GÜNDÜZ TRAFO ELEKTRİK MAKİNALARI TURİZM', 'str') getting the wrong decoding 'G܎Dܚ TRAFO ELEKTR렍AKARI TUR𚍀' Please give me solution so I can decode these charcter and other language characters
Owner

Assuming the second argument is the correct JS string, you probably meant to encode:

> require("xlsx/dist/cpexcel").utils.encode(65001, 'GÜNDÜZ TRAFO ELEKTRİK MAKİNALARI TURİZM', 'buf')
<Buffer 47 c3 9c 4e 44 c3 9c 5a 20 54 52 41 46 4f 20 45 4c 45 4b 54 52 c4 b0 4b 20 4d 41 4b c4 b0 4e 41 4c 41 52 49 20 54 55 52 c4 b0 5a 4d>

> require("xlsx/dist/cpexcel").utils.encode(65001, 'GÜNDÜZ TRAFO ELEKTRİK MAKİNALARI TURİZM', 'str')
'GÃ\x9CNDÃ\x9CZ TRAFO ELEKTRÄ°K MAKÄ°NALARI TURÄ°ZM'

Encoding takes a JS string and encodes in the specified codepage, while decoding takes a string or array of bytes in the codepage and generates a JS-friendly string.

But in practice, you should be passing the option codepage to the read or write functions. For example, if you are trying to read Turkish files, it is most likely 1254 (Windows Turkish). To see the full list, check the table in https://git.sheetjs.com/sheetjs/js-codepage#generated-codepages

Assuming the second argument is the correct JS string, you probably meant to encode: ```js > require("xlsx/dist/cpexcel").utils.encode(65001, 'GÜNDÜZ TRAFO ELEKTRİK MAKİNALARI TURİZM', 'buf') <Buffer 47 c3 9c 4e 44 c3 9c 5a 20 54 52 41 46 4f 20 45 4c 45 4b 54 52 c4 b0 4b 20 4d 41 4b c4 b0 4e 41 4c 41 52 49 20 54 55 52 c4 b0 5a 4d> > require("xlsx/dist/cpexcel").utils.encode(65001, 'GÜNDÜZ TRAFO ELEKTRİK MAKİNALARI TURİZM', 'str') 'GÃ\x9CNDÃ\x9CZ TRAFO ELEKTRÄ°K MAKÄ°NALARI TURÄ°ZM' ``` Encoding takes a JS string and encodes in the specified codepage, while decoding takes a string or array of bytes in the codepage and generates a JS-friendly string. But in practice, you should be passing the option `codepage` to the read or write functions. For example, if you are trying to read Turkish files, it is most likely 1254 (Windows Turkish). To see the full list, check the table in https://git.sheetjs.com/sheetjs/js-codepage#generated-codepages
Author

cptable.utils.decode(65001, 'GÜNDÜZ TRAFO ELEKTRİK MAKİNALARI TURİZM', 'str')

As you can see Here I am using decode not encode but getting wrong data in output
wrong data is - 'G܎Dܚ TRAFO ELEKTR렍AKARI TUR𚍀'

While I want exact data which I am passing

cptable.utils.decode(65001, 'GÜNDÜZ TRAFO ELEKTRİK MAKİNALARI TURİZM', 'str') As you can see Here I am using decode not encode but getting wrong data in output wrong data is - 'G܎Dܚ TRAFO ELEKTR렍AKARI TUR𚍀' While I want exact data which I am passing
Owner

You are starting from a JS string (assuming 'GÜNDÜZ TRAFO ELEKTRİK MAKİNALARI TURİZM' is the correct string). That means you probably want to decode.

The encode operations take content in a specified encoding and generate JavaScript-friendly strings.

The decode operations take JavaScript-friendly strings and generate content using the specified encoding.

You are starting from a JS string (assuming `'GÜNDÜZ TRAFO ELEKTRİK MAKİNALARI TURİZM'` is the correct string). That means you probably want to **decode**. The **encode** operations take content in a specified encoding and generate JavaScript-friendly strings. The **decode** operations take JavaScript-friendly strings and generate content using the specified encoding.
Author

Ok got it, First I have to encode string to make it JavaScript-friendly string and then decode it

Ok got it, First I have to encode string to make it JavaScript-friendly string and then decode it
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#3010
No description provided.