This closes #1903, made GetCellStyle function concurrency safe
- Update comment of the function and unit test
This commit is contained in:
parent
42ad4d6959
commit
0c3dfb1605
|
@ -42,6 +42,9 @@ func TestConcurrency(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
// Concurrency set cell style
|
||||
assert.NoError(t, f.SetCellStyle("Sheet1", "A3", "A3", style))
|
||||
// Concurrency get cell style
|
||||
_, err = f.GetCellStyle("Sheet1", "A3")
|
||||
assert.NoError(t, err)
|
||||
// Concurrency add picture
|
||||
assert.NoError(t, f.AddPicture("Sheet1", "F21", filepath.Join("test", "images", "excel.jpg"),
|
||||
&GraphicOptions{
|
||||
|
|
|
@ -2186,19 +2186,22 @@ func setCellXfs(style *xlsxStyleSheet, fontID, numFmtID, fillID, borderID int, a
|
|||
}
|
||||
|
||||
// GetCellStyle provides a function to get cell style index by given worksheet
|
||||
// name and cell reference.
|
||||
// name and cell reference. This function is concurrency safe.
|
||||
func (f *File) GetCellStyle(sheet, cell string) (int, error) {
|
||||
f.mu.Lock()
|
||||
ws, err := f.workSheetReader(sheet)
|
||||
if err != nil {
|
||||
f.mu.Unlock()
|
||||
return 0, err
|
||||
}
|
||||
f.mu.Unlock()
|
||||
ws.mu.Lock()
|
||||
defer ws.mu.Unlock()
|
||||
col, row, err := CellNameToCoordinates(cell)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
ws.prepareSheetXML(col, row)
|
||||
ws.mu.Lock()
|
||||
defer ws.mu.Unlock()
|
||||
return ws.prepareCellStyle(col, row, ws.SheetData.Row[row-1].C[col-1].S), err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue