xlsReader icon indicating copy to clipboard operation
xlsReader copied to clipboard

Incorrect decoding of compressed characters

Open eidrisov opened this issue 2 years ago • 0 comments

Decoding of compressed characters is not handled correclty:

func (r *LabelBIFF8) GetString() string {
	if int(r.grbit[0]) == 1 {
		name := helpers.BytesToUints16(r.rgb[:])
		runes := utf16.Decode(name)
		return string(runes)
	} else {
		return string(decodeWindows1251(r.rgb[:]))
	}
}

The code outputs incorrect result: Hinterfьllmaterial Ш 6 mm Expected output Hinterfüllmaterial Ø 6 mm

Each compressed character(byte) has to be converted into unit16 and then decoded. The line return string(decodeWindows1251(r.rgb[:])) should be replaced with:

name := []uint16{}
for _, b := range r.rgb[:] {
   name = append(name, uint16(b))
}
runes := utf16.Decode(name)
return string(runes)

eidrisov avatar Nov 17 '23 09:11 eidrisov