Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xuri
excelize
提交
79958aa7
excelize
项目概览
xuri
/
excelize
通知
13
Star
2
Fork
4
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
excelize
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
已验证
提交
79958aa7
编写于
5月 25, 2024
作者:
xurime
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
This closes #1903, made GetCellStyle, SetRowVisible and GetRowVisible functions concurrency safe
- Update comments of the functions and unit tests
上级
42ad4d69
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
33 addition
and
9 deletion
+33
-9
cell_test.go
cell_test.go
+10
-1
col.go
col.go
+3
-0
rows.go
rows.go
+14
-5
styles.go
styles.go
+6
-3
未找到文件。
cell_test.go
浏览文件 @
79958aa7
...
...
@@ -4,6 +4,7 @@ import (
"fmt"
_
"image/jpeg"
"math"
"math/rand"
"os"
"path/filepath"
"reflect"
...
...
@@ -42,6 +43,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
{
...
...
@@ -87,7 +91,12 @@ func TestConcurrency(t *testing.T) {
// Concurrency get columns visible
visible
,
err
:=
f
.
GetColVisible
(
"Sheet1"
,
"A"
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
true
,
visible
)
assert
.
True
(
t
,
visible
)
// Concurrency set row visible
assert
.
NoError
(
t
,
f
.
SetRowVisible
(
"Sheet1"
,
1
+
rand
.
Intn
(
1000
),
false
))
// Concurrency get row visible
_
,
err
=
f
.
GetRowVisible
(
"Sheet1"
,
1
+
rand
.
Intn
(
1000
))
assert
.
NoError
(
t
,
err
)
// Concurrency add data validation
dv
:=
NewDataValidation
(
true
)
dv
.
Sqref
=
fmt
.
Sprintf
(
"A%d:B%d"
,
val
,
val
)
...
...
col.go
浏览文件 @
79958aa7
...
...
@@ -294,10 +294,13 @@ func (f *File) SetColVisible(sheet, columns string, visible bool) error {
if
err
!=
nil
{
return
err
}
f
.
mu
.
Lock
()
ws
,
err
:=
f
.
workSheetReader
(
sheet
)
if
err
!=
nil
{
f
.
mu
.
Unlock
()
return
err
}
f
.
mu
.
Unlock
()
ws
.
mu
.
Lock
()
defer
ws
.
mu
.
Unlock
()
colData
:=
xlsxCol
{
...
...
rows.go
浏览文件 @
79958aa7
...
...
@@ -480,37 +480,46 @@ func (f *File) sharedStringsReader() (*xlsxSST, error) {
}
// SetRowVisible provides a function to set visible of a single row by given
// worksheet name and Excel row number. For example, hide row 2 in Sheet1:
// worksheet name and row number. This function is concurrency safe. For
// example, hide row 2 in Sheet1:
//
// err := f.SetRowVisible("Sheet1", 2, false)
func
(
f
*
File
)
SetRowVisible
(
sheet
string
,
row
int
,
visible
bool
)
error
{
if
row
<
1
{
return
newInvalidRowNumberError
(
row
)
}
f
.
mu
.
Lock
()
ws
,
err
:=
f
.
workSheetReader
(
sheet
)
if
err
!=
nil
{
f
.
mu
.
Unlock
()
return
err
}
f
.
mu
.
Unlock
()
ws
.
mu
.
Lock
()
defer
ws
.
mu
.
Unlock
()
ws
.
prepareSheetXML
(
0
,
row
)
ws
.
SheetData
.
Row
[
row
-
1
]
.
Hidden
=
!
visible
return
nil
}
// GetRowVisible provides a function to get visible of a single row by given
// worksheet name and
Excel row number. For example, get visible state of row
// 2 in Sheet1:
// worksheet name and
row number. This function is concurrency safe. For
//
example, get visible state of row
2 in Sheet1:
//
// visible, err := f.GetRowVisible("Sheet1", 2)
func
(
f
*
File
)
GetRowVisible
(
sheet
string
,
row
int
)
(
bool
,
error
)
{
if
row
<
1
{
return
false
,
newInvalidRowNumberError
(
row
)
}
f
.
mu
.
Lock
()
ws
,
err
:=
f
.
workSheetReader
(
sheet
)
if
err
!=
nil
{
f
.
mu
.
Unlock
()
return
false
,
err
}
f
.
mu
.
Unlock
()
ws
.
mu
.
Lock
()
defer
ws
.
mu
.
Unlock
()
if
row
>
len
(
ws
.
SheetData
.
Row
)
{
return
false
,
nil
}
...
...
styles.go
浏览文件 @
79958aa7
...
...
@@ -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
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录