From 90d200a10ba4d8c2ae2eff47ad8e1cca0ab28e76 Mon Sep 17 00:00:00 2001 From: xuri Date: Wed, 7 Jul 2021 00:57:43 +0800 Subject: Make the functions `SetSheetRow`, `New Style` and `SetCellStyle` concurrency safety --- styles.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'styles.go') diff --git a/styles.go b/styles.go index 235746c..5b9b200 100644 --- a/styles.go +++ b/styles.go @@ -1990,6 +1990,8 @@ func (f *File) NewStyle(style interface{}) (int, error) { fs.DecimalPlaces = 2 } s := f.stylesReader() + s.Lock() + defer s.Unlock() // check given style already exist. if cellXfsID = f.getStyleID(s, fs); cellXfsID != -1 { return cellXfsID, err @@ -2693,7 +2695,8 @@ func (f *File) SetCellStyle(sheet, hcell, vcell string, styleID int) error { } prepareSheetXML(ws, vcol, vrow) makeContiguousColumns(ws, hrow, vrow, vcol) - + ws.Lock() + defer ws.Unlock() for r := hrowIdx; r <= vrowIdx; r++ { for k := hcolIdx; k <= vcolIdx; k++ { ws.SheetData.Row[r].C[k].S = styleID -- cgit v1.2.1