Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xuri
excelize
提交
7e12b560
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 搜索 >>
已验证
提交
7e12b560
编写于
3月 07, 2021
作者:
xurime
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#625, support setting formula for cell in streaming API
上级
71bd5e19
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
55 addition
and
26 deletion
+55
-26
chart.go
chart.go
+3
-3
stream.go
stream.go
+30
-1
stream_test.go
stream_test.go
+2
-2
xmlChartSheet.go
xmlChartSheet.go
+20
-20
未找到文件。
chart.go
浏览文件 @
7e12b560
// Copyright 2016 - 202
0
The excelize Authors. All rights reserved. Use of
// Copyright 2016 - 202
1
The excelize Authors. All rights reserved. Use of
// this source code is governed by a BSD-style license that can be found in
// the LICENSE file.
//
...
...
@@ -923,8 +923,8 @@ func (f *File) AddChartSheet(sheet, format string, combo ...string) error {
return
err
}
cs
:=
xlsxChartsheet
{
SheetViews
:
[]
*
xlsxChartsheetViews
{
{
SheetView
:
[]
*
xlsxChartsheetView
{{
ZoomScaleAttr
:
100
,
ZoomToFitAttr
:
true
}}
}
,
SheetViews
:
&
xlsxChartsheetViews
{
SheetView
:
[]
*
xlsxChartsheetView
{{
ZoomScaleAttr
:
100
,
ZoomToFitAttr
:
true
}},
},
}
f
.
SheetCount
++
...
...
stream.go
浏览文件 @
7e12b560
...
...
@@ -71,6 +71,13 @@ type StreamWriter struct {
// fmt.Println(err)
// }
//
// Set cell value and cell formula for a worksheet with stream writer:
//
// err := streamWriter.SetRow("A1", []interface{}{
// excelize.Cell{Value: 1},
// excelize.Cell{Value: 2},
// excelize.Cell{Formula: "SUM(A1,B1)"}});
//
func
(
f
*
File
)
NewStreamWriter
(
sheet
string
)
(
*
StreamWriter
,
error
)
{
sheetID
:=
f
.
getSheetID
(
sheet
)
if
sheetID
==
-
1
{
...
...
@@ -106,7 +113,14 @@ func (f *File) NewStreamWriter(sheet string) (*StreamWriter, error) {
//
// Create a table of F2:H6 with format set:
//
// err := sw.AddTable("F2", "H6", `{"table_name":"table","table_style":"TableStyleMedium2","show_first_column":true,"show_last_column":true,"show_row_stripes":false,"show_column_stripes":true}`)
// err := sw.AddTable("F2", "H6", `{
// "table_name": "table",
// "table_style": "TableStyleMedium2",
// "show_first_column": true,
// "show_last_column": true,
// "show_row_stripes": false,
// "show_column_stripes": true
// }`)
//
// Note that the table must be at least two lines including the header. The
// header cells must contain strings and must be unique.
...
...
@@ -266,6 +280,7 @@ func getRowElement(token xml.Token, hrow int) (startElement xml.StartElement, ok
// a value.
type
Cell
struct
{
StyleID
int
Formula
string
Value
interface
{}
}
...
...
@@ -291,9 +306,11 @@ func (sw *StreamWriter) SetRow(axis string, values []interface{}) error {
if
v
,
ok
:=
val
.
(
Cell
);
ok
{
c
.
S
=
v
.
StyleID
val
=
v
.
Value
setCellFormula
(
&
c
,
v
.
Formula
)
}
else
if
v
,
ok
:=
val
.
(
*
Cell
);
ok
&&
v
!=
nil
{
c
.
S
=
v
.
StyleID
val
=
v
.
Value
setCellFormula
(
&
c
,
v
.
Formula
)
}
if
err
=
setCellValFunc
(
&
c
,
val
);
err
!=
nil
{
_
,
_
=
sw
.
rawData
.
WriteString
(
`</row>`
)
...
...
@@ -305,6 +322,13 @@ func (sw *StreamWriter) SetRow(axis string, values []interface{}) error {
return
sw
.
rawData
.
Sync
()
}
// setCellFormula provides a function to set formula of a cell.
func
setCellFormula
(
c
*
xlsxC
,
formula
string
)
{
if
formula
!=
""
{
c
.
F
=
&
xlsxF
{
Content
:
formula
}
}
}
// setCellValFunc provides a function to set value of a cell.
func
setCellValFunc
(
c
*
xlsxC
,
val
interface
{})
(
err
error
)
{
switch
val
:=
val
.
(
type
)
{
...
...
@@ -373,6 +397,11 @@ func writeCell(buf *bufferedWriter, c xlsxC) {
fmt
.
Fprintf
(
buf
,
` t="%s"`
,
c
.
T
)
}
_
,
_
=
buf
.
WriteString
(
`>`
)
if
c
.
F
!=
nil
{
_
,
_
=
buf
.
WriteString
(
`<f>`
)
_
=
xml
.
EscapeText
(
buf
,
[]
byte
(
c
.
F
.
Content
))
_
,
_
=
buf
.
WriteString
(
`</f>`
)
}
if
c
.
V
!=
""
{
_
,
_
=
buf
.
WriteString
(
`<v>`
)
_
=
xml
.
EscapeText
(
buf
,
[]
byte
(
c
.
V
))
...
...
stream_test.go
浏览文件 @
7e12b560
...
...
@@ -55,8 +55,8 @@ func TestStreamWriter(t *testing.T) {
// Test set cell with style.
styleID
,
err
:=
file
.
NewStyle
(
`{"font":{"color":"#777777"}}`
)
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
streamWriter
.
SetRow
(
"A4"
,
[]
interface
{}{
Cell
{
StyleID
:
styleID
}}))
assert
.
NoError
(
t
,
streamWriter
.
SetRow
(
"A5"
,
[]
interface
{}{
&
Cell
{
StyleID
:
styleID
,
Value
:
"cell"
}}))
assert
.
NoError
(
t
,
streamWriter
.
SetRow
(
"A4"
,
[]
interface
{}{
Cell
{
StyleID
:
styleID
}
,
Cell
{
Formula
:
"SUM(A10,B10)"
}
}))
assert
.
NoError
(
t
,
streamWriter
.
SetRow
(
"A5"
,
[]
interface
{}{
&
Cell
{
StyleID
:
styleID
,
Value
:
"cell"
}
,
&
Cell
{
Formula
:
"SUM(A10,B10)"
}
}))
assert
.
EqualError
(
t
,
streamWriter
.
SetRow
(
"A6"
,
[]
interface
{}{
time
.
Now
()}),
"only UTC time expected"
)
for
rowID
:=
10
;
rowID
<=
51200
;
rowID
++
{
...
...
xmlChartSheet.go
浏览文件 @
7e12b560
// Copyright 2016 - 202
0
The excelize Authors. All rights reserved. Use of
// Copyright 2016 - 202
1
The excelize Authors. All rights reserved. Use of
// this source code is governed by a BSD-style license that can be found in
// the LICENSE file.
//
...
...
@@ -16,27 +16,27 @@ import "encoding/xml"
// xlsxChartsheet directly maps the chartsheet element of Chartsheet Parts in
// a SpreadsheetML document.
type
xlsxChartsheet
struct
{
XMLName
xml
.
Name
`xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main chartsheet"`
SheetPr
[]
*
xlsxChartsheetPr
`xml:"sheetPr"`
SheetViews
[]
*
xlsxChartsheetViews
`xml:"sheetViews"`
SheetProtection
[]
*
xlsxChartsheetProtection
`xml:"sheetProtection"`
CustomSheetViews
[]
*
xlsxCustomChartsheetViews
`xml:"customSheetViews"`
PageMargins
*
xlsxPageMargins
`xml:"pageMargins"`
PageSetup
[]
*
xlsxPageSetUp
`xml:"pageSetup"`
HeaderFooter
*
xlsxHeaderFooter
`xml:"headerFooter"`
Drawing
*
xlsxDrawing
`xml:"drawing"`
DrawingHF
[]
*
xlsxDrawingHF
`xml:"drawingHF"`
Picture
[]
*
xlsxPicture
`xml:"picture"`
WebPublishItems
[]
*
xlsxInnerXML
`xml:"webPublishItems"`
ExtLst
[]
*
xlsxExtLst
`xml:"extLst"`
XMLName
xml
.
Name
`xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main chartsheet"`
SheetPr
*
xlsxChartsheetPr
`xml:"sheetPr"`
SheetViews
*
xlsxChartsheetViews
`xml:"sheetViews"`
SheetProtection
*
xlsxChartsheetProtection
`xml:"sheetProtection"`
CustomSheetViews
*
xlsxCustomChartsheetViews
`xml:"customSheetViews"`
PageMargins
*
xlsxPageMargins
`xml:"pageMargins"`
PageSetup
*
xlsxPageSetUp
`xml:"pageSetup"`
HeaderFooter
*
xlsxHeaderFooter
`xml:"headerFooter"`
Drawing
*
xlsxDrawing
`xml:"drawing"`
DrawingHF
*
xlsxDrawingHF
`xml:"drawingHF"`
Picture
*
xlsxPicture
`xml:"picture"`
WebPublishItems
*
xlsxInnerXML
`xml:"webPublishItems"`
ExtLst
*
xlsxExtLst
`xml:"extLst"`
}
// xlsxChartsheetPr specifies chart sheet properties.
type
xlsxChartsheetPr
struct
{
XMLName
xml
.
Name
`xml:"sheetPr"`
PublishedAttr
bool
`xml:"published,attr,omitempty"`
CodeNameAttr
string
`xml:"codeName,attr,omitempty"`
TabColor
[]
*
xlsxTabColor
`xml:"tabColor"`
XMLName
xml
.
Name
`xml:"sheetPr"`
PublishedAttr
bool
`xml:"published,attr,omitempty"`
CodeNameAttr
string
`xml:"codeName,attr,omitempty"`
TabColor
*
xlsxTabColor
`xml:"tabColor"`
}
// xlsxChartsheetViews specifies chart sheet views.
...
...
@@ -71,13 +71,13 @@ type xlsxChartsheetProtection struct {
// xlsxCustomChartsheetViews collection of custom Chart Sheet View
// information.
type
xlsxCustomChartsheetViews
struct
{
XMLName
xml
.
Name
`xml:"custom
Charts
heetViews"`
XMLName
xml
.
Name
`xml:"custom
S
heetViews"`
CustomSheetView
[]
*
xlsxCustomChartsheetView
`xml:"customSheetView"`
}
// xlsxCustomChartsheetView defines custom view properties for chart sheets.
type
xlsxCustomChartsheetView
struct
{
XMLName
xml
.
Name
`xml:"custom
Charts
heetView"`
XMLName
xml
.
Name
`xml:"custom
S
heetView"`
GUIDAttr
string
`xml:"guid,attr"`
ScaleAttr
uint32
`xml:"scale,attr,omitempty"`
StateAttr
string
`xml:"state,attr,omitempty"`
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录