summaryrefslogtreecommitdiff
path: root/excelize.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2020-08-14 16:09:50 +0000
committerxuri <xuri.me@gmail.com>2020-08-15 09:19:35 +0000
commitc3e92a51d744bc8420e0626b06ee3a0efd030341 (patch)
tree3ddf72f53711ae898baf584287d6b4b7ad4276b9 /excelize.go
parentcb6f8852bb764ffc1f9b637faaf594353476e17c (diff)
Compatible with Go 1.15, fix unit test failed on Windows and fixed #689 potential race condition
Diffstat (limited to 'excelize.go')
-rw-r--r--excelize.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/excelize.go b/excelize.go
index 5cc88e9..bfb3aba 100644
--- a/excelize.go
+++ b/excelize.go
@@ -24,12 +24,14 @@ import (
"path"
"strconv"
"strings"
+ "sync"
"golang.org/x/net/html/charset"
)
// File define a populated spreadsheet file struct.
type File struct {
+ sync.RWMutex
xmlAttr map[string][]xml.Attr
checked map[string]bool
sheetMap map[string]string
@@ -153,6 +155,8 @@ func (f *File) setDefaultTimeStyle(sheet, axis string, format int) error {
// workSheetReader provides a function to get the pointer to the structure
// after deserialization by given worksheet name.
func (f *File) workSheetReader(sheet string) (xlsx *xlsxWorksheet, err error) {
+ f.Lock()
+ defer f.Unlock()
var (
name string
ok bool
@@ -323,7 +327,7 @@ func (f *File) AddVBAProject(bin string) error {
var err error
// Check vbaProject.bin exists first.
if _, err = os.Stat(bin); os.IsNotExist(err) {
- return err
+ return fmt.Errorf("stat %s: no such file or directory", bin)
}
if path.Ext(bin) != ".bin" {
return errors.New("unsupported VBA project extension")