Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix go lock #517

Merged
merged 2 commits into from
May 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"reflect"
"strconv"
"strings"
"sync"
"time"
)

Expand All @@ -30,6 +31,8 @@ const (
STCellFormulaTypeShared = "shared"
)

var rwMutex sync.RWMutex

// GetCellValue provides a function to get formatted value from cell by given
// worksheet name and axis in XLSX file. If it is possible to apply a format
// to the cell value, it will do so, if not then an error will be returned,
Expand Down Expand Up @@ -179,6 +182,8 @@ func setCellDuration(value time.Duration) (t string, v string) {
// SetCellInt provides a function to set int type value of a cell by given
// worksheet name, cell coordinates and cell value.
func (f *File) SetCellInt(sheet, axis string, value int) error {
rwMutex.Lock()
defer rwMutex.Unlock()
xlsx, err := f.workSheetReader(sheet)
if err != nil {
return err
Expand All @@ -200,6 +205,8 @@ func setCellInt(value int) (t string, v string) {
// SetCellBool provides a function to set bool type value of a cell by given
// worksheet name, cell name and cell value.
func (f *File) SetCellBool(sheet, axis string, value bool) error {
rwMutex.Lock()
defer rwMutex.Unlock()
xlsx, err := f.workSheetReader(sheet)
if err != nil {
return err
Expand Down Expand Up @@ -233,6 +240,8 @@ func setCellBool(value bool) (t string, v string) {
// f.SetCellFloat("Sheet1", "A1", float64(x), 2, 32)
//
func (f *File) SetCellFloat(sheet, axis string, value float64, prec, bitSize int) error {
rwMutex.Lock()
defer rwMutex.Unlock()
xlsx, err := f.workSheetReader(sheet)
if err != nil {
return err
Expand All @@ -254,6 +263,8 @@ func setCellFloat(value float64, prec, bitSize int) (t string, v string) {
// SetCellStr provides a function to set string type value of a cell. Total
// number of characters that a cell can contain 32767 characters.
func (f *File) SetCellStr(sheet, axis, value string) error {
rwMutex.Lock()
defer rwMutex.Unlock()
xlsx, err := f.workSheetReader(sheet)
if err != nil {
return err
Expand Down Expand Up @@ -327,6 +338,8 @@ type FormulaOpts struct {
// SetCellFormula provides a function to set cell formula by given string and
// worksheet name.
func (f *File) SetCellFormula(sheet, axis, formula string, opts ...FormulaOpts) error {
rwMutex.Lock()
defer rwMutex.Unlock()
xlsx, err := f.workSheetReader(sheet)
if err != nil {
return err
Expand Down