diff options
author | xuri <xuri.me@gmail.com> | 2022-09-07 00:18:16 +0800 |
---|---|---|
committer | xuri <xuri.me@gmail.com> | 2022-09-07 00:18:16 +0800 |
commit | 0c5cdfec1868f31f6e355cdcb0a91220bad80522 (patch) | |
tree | 58ad95b35e5ab305bf969a168f065acf894fc1eb /col.go | |
parent | 961a3e89330ab2cd5257e04384813a7e53ea3744 (diff) |
This closes #1293, add new function `GetColStyle`
- Fix generate workbook corruption after insert cols/rows in some case
- Update unit tests
- Update dependencies module
Diffstat (limited to 'col.go')
-rw-r--r-- | col.go | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -638,6 +638,30 @@ func (f *File) getColWidth(sheet string, col int) int { return int(defaultColWidthPixels) } +// GetColStyle provides a function to get column style ID by given worksheet +// name and column name. +func (f *File) GetColStyle(sheet, col string) (int, error) { + var styleID int + colNum, err := ColumnNameToNumber(col) + if err != nil { + return styleID, err + } + ws, err := f.workSheetReader(sheet) + if err != nil { + return styleID, err + } + ws.Lock() + defer ws.Unlock() + if ws.Cols != nil { + for _, v := range ws.Cols.Col { + if v.Min <= colNum && colNum <= v.Max { + styleID = v.Style + } + } + } + return styleID, err +} + // GetColWidth provides a function to get column width by given worksheet name // and column name. func (f *File) GetColWidth(sheet, col string) (float64, error) { @@ -649,6 +673,8 @@ func (f *File) GetColWidth(sheet, col string) (float64, error) { if err != nil { return defaultColWidth, err } + ws.Lock() + defer ws.Unlock() if ws.Cols != nil { var width float64 for _, v := range ws.Cols.Col { |