summaryrefslogtreecommitdiff
path: root/cell.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2020-05-22 17:01:45 +0800
committerGitHub <noreply@github.com>2020-05-22 17:01:45 +0800
commit0dd616b18fef393ea5b632ba25ca365575f5f61b (patch)
treec6ebd61a7d9a7da5b993ffb82e4fb6c036e75d6a /cell.go
parent2efc7107ff30dc7f1e1a798082616ee488f99489 (diff)
parentec14de32f0c06f7a26b6b79578f666c0cc50b72c (diff)
Merge pull request #517 from hengmyj/fix/cell_lock
make set cell value is concurrency safe
Diffstat (limited to 'cell.go')
-rw-r--r--cell.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/cell.go b/cell.go
index 63db194..97feb0a 100644
--- a/cell.go
+++ b/cell.go
@@ -16,6 +16,7 @@ import (
"reflect"
"strconv"
"strings"
+ "sync"
"time"
)
@@ -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,
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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