From 18a6340e665e2384ed3c5448ae99fbc885808200 Mon Sep 17 00:00:00 2001 From: korv1982 Date: Mon, 23 Oct 2017 11:14:16 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20=D0=B8?= =?UTF-8?q?=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- workbook.go | 10 ++++++++-- xls.go | 5 ++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/workbook.go b/workbook.go index b0aa076..fd655e5 100644 --- a/workbook.go +++ b/workbook.go @@ -6,6 +6,7 @@ import ( "io" "os" "unicode/utf16" + "golang.org/x/text/encoding/charmap" ) //xls workbook type @@ -160,12 +161,17 @@ func (wb *WorkBook) parseBof(buf io.ReadSeeker, b *bof, pre *bof, offset_pre int } return } - +func decodeWindows1251(enc []byte) string { + dec := charmap.Windows1251.NewDecoder() + out, _ := dec.Bytes(enc) + return string(out) +} func (w *WorkBook) get_string(buf io.ReadSeeker, size uint16) (res string, err error) { if w.Is5ver { var bts = make([]byte, size) _, err = buf.Read(bts) - res = string(bts) + res = decodeWindows1251(bts) + //res = string(bts) } else { var richtext_num = uint16(0) var phonetic_size = uint32(0) diff --git a/xls.go b/xls.go index b425fc3..bc44581 100644 --- a/xls.go +++ b/xls.go @@ -27,7 +27,10 @@ func OpenReader(reader io.ReadSeeker, charset string) (wb *WorkBook, err error) for _, file := range dir { name := file.Name() if name == "Workbook" { - book = file + if book == nil { + book = file + } + //book = file // break } if name == "Book" {