Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
此号慢热型
excelize
提交
70f63281
excelize
项目概览
此号慢热型
/
excelize
与 Fork 源项目一致
Fork自
xuri / excelize
通知
2
Star
0
Fork
0
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
70f63281
编写于
5月 16, 2017
作者:
xurime
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support set font style of shape text. Relate issue #38.
上级
cf97118b
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
96 addition
and
61 deletion
+96
-61
chart.go
chart.go
+3
-3
comment.go
comment.go
+3
-3
excelize_test.go
excelize_test.go
+1
-1
shape.go
shape.go
+47
-3
xmlChart.go
xmlChart.go
+30
-43
xmlDrawing.go
xmlDrawing.go
+1
-0
xmlStyles.go
xmlStyles.go
+11
-8
未找到文件。
chart.go
浏览文件 @
70f63281
...
...
@@ -252,7 +252,7 @@ func (f *File) addChart(formatSet *formatChart) {
Rich
:
&
cRich
{
P
:
aP
{
PPr
:
&
aPPr
{
DefRPr
:
a
Def
RPr
{
DefRPr
:
aRPr
{
Kern
:
1200
,
Strike
:
"noStrike"
,
U
:
"none"
,
...
...
@@ -292,7 +292,7 @@ func (f *File) addChart(formatSet *formatChart) {
TxPr
:
cTxPr
{
P
:
aP
{
PPr
:
&
aPPr
{
DefRPr
:
a
Def
RPr
{
DefRPr
:
aRPr
{
Kern
:
1200
,
U
:
"none"
,
Sz
:
14000
,
...
...
@@ -812,7 +812,7 @@ func (f *File) drawPlotAreaTxPr() *cTxPr {
},
P
:
aP
{
PPr
:
&
aPPr
{
DefRPr
:
a
Def
RPr
{
DefRPr
:
aRPr
{
Sz
:
900
,
B
:
false
,
I
:
false
,
...
...
comment.go
浏览文件 @
70f63281
...
...
@@ -158,7 +158,7 @@ func (f *File) addComment(commentsXML, cell string, formatSet *formatComment) {
}
comments
:=
xlsxComments
{
Authors
:
[]
xlsxAuthor
{
xlsxAuthor
{
{
Author
:
formatSet
.
Author
,
},
},
...
...
@@ -168,7 +168,7 @@ func (f *File) addComment(commentsXML, cell string, formatSet *formatComment) {
AuthorID
:
0
,
Text
:
xlsxText
{
R
:
[]
xlsxR
{
xlsxR
{
{
RPr
:
&
xlsxRPr
{
B
:
" "
,
Sz
:
&
attrValInt
{
Val
:
9
},
...
...
@@ -180,7 +180,7 @@ func (f *File) addComment(commentsXML, cell string, formatSet *formatComment) {
},
T
:
a
,
},
xlsxR
{
{
RPr
:
&
xlsxRPr
{
Sz
:
&
attrValInt
{
Val
:
9
},
Color
:
&
xlsxColor
{
...
...
excelize_test.go
浏览文件 @
70f63281
...
...
@@ -517,7 +517,7 @@ func TestAddShape(t *testing.T) {
t
.
Log
(
err
)
}
xlsx
.
AddShape
(
"Sheet1"
,
"A30"
,
`{"type":"rect","text":"Rectangle Shape"}`
)
xlsx
.
AddShape
(
"Sheet3"
,
"H1"
,
`{"type":"ellipseRibbon", "color":{"line":"#4286f4","fill":"#8eb9ff"}, "height": 90}`
)
xlsx
.
AddShape
(
"Sheet3"
,
"H1"
,
`{"type":"ellipseRibbon", "color":{"line":"#4286f4","fill":"#8eb9ff"}, "
font":{"bold":true,"italic":true,"family":"Berlin Sans FB Demi","size":36,"color":"#777777","underline":"single"}, "
height": 90}`
)
err
=
xlsx
.
Save
()
if
err
!=
nil
{
t
.
Log
(
err
)
...
...
shape.go
浏览文件 @
70f63281
...
...
@@ -22,6 +22,14 @@ func parseFormatShapeSet(formatSet string) *formatShape {
XScale
:
1.0
,
YScale
:
1.0
,
},
Font
:
formatFont
{
Bold
:
false
,
Italic
:
false
,
Underline
:
"none"
,
Family
:
"Calibri"
,
Size
:
11
,
Color
:
"#000000"
,
},
Text
:
" "
,
}
json
.
Unmarshal
([]
byte
(
formatSet
),
&
format
)
...
...
@@ -33,7 +41,7 @@ func parseFormatShapeSet(formatSet string) *formatShape {
// print settings) and properties set. For example, add text box (rect shape) in
// Sheet1:
//
// xlsx.AddShape("Sheet1", "G6", `{"type":"rect", "text":"Rectangle Shape", "color":{"line":"#4286F4","fill":"#8eb9ff"}, "width": 180, "height": 90}`)
// xlsx.AddShape("Sheet1", "G6", `{"type":"rect", "text":"Rectangle Shape", "color":{"line":"#4286F4","fill":"#8eb9ff"}, "
font":{"bold":true,"italic":true,"family":"Berlin Sans FB Demi","size":36,"color":"#777777","underline":"sng"}, "
width": 180, "height": 90}`)
//
// The following shows the type of chart supported by excelize:
//
...
...
@@ -225,6 +233,27 @@ func parseFormatShapeSet(formatSet string) *formatShape {
// wedgeRectCallout (Callout Wedge Rectangle Shape)
// wedgeRoundRectCallout (Callout Wedge Round Rectangle Shape)
//
// The following shows the type of text underline supported by excelize:
//
// none
// words
// sng
// dbl
// heavy
// dotted
// dottedHeavy
// dash
// dashHeavy
// dashLong
// dashLongHeavy
// dotDash
// dotDashHeavy
// dotDotDash
// dotDotDashHeavy
// wavy
// wavyHeavy
// wavyDbl
//
func
(
f
*
File
)
AddShape
(
sheet
,
cell
,
format
string
)
{
formatSet
:=
parseFormatShapeSet
(
format
)
// Read sheet data.
...
...
@@ -250,6 +279,12 @@ func (f *File) AddShape(sheet, cell, format string) {
// addDrawingShape
func
(
f
*
File
)
addDrawingShape
(
sheet
,
drawingXML
,
cell
string
,
formatSet
*
formatShape
)
{
textUnderlineType
:=
map
[
string
]
bool
{
"none"
:
true
,
"words"
:
true
,
"sng"
:
true
,
"dbl"
:
true
,
"heavy"
:
true
,
"dotted"
:
true
,
"dottedHeavy"
:
true
,
"dash"
:
true
,
"dashHeavy"
:
true
,
"dashLong"
:
true
,
"dashLongHeavy"
:
true
,
"dotDash"
:
true
,
"dotDashHeavy"
:
true
,
"dotDotDash"
:
true
,
"dotDotDashHeavy"
:
true
,
"wavy"
:
true
,
"wavyHeavy"
:
true
,
"wavyDbl"
:
true
}
u
:=
formatSet
.
Font
.
Underline
_
,
ok
:=
textUnderlineType
[
u
]
if
!
ok
{
u
=
"none"
}
cell
=
strings
.
ToUpper
(
cell
)
fromCol
:=
string
(
strings
.
Map
(
letterOnlyMapF
,
cell
))
fromRow
,
_
:=
strconv
.
Atoi
(
strings
.
Map
(
intOnlyMapF
,
cell
))
...
...
@@ -262,7 +297,7 @@ func (f *File) addDrawingShape(sheet, drawingXML, cell string, formatSet *format
content
.
A
=
NameSpaceDrawingML
content
.
Xdr
=
NameSpaceDrawingMLSpreadSheet
cNvPrID
:=
1
_
,
ok
:
=
f
.
XLSX
[
drawingXML
]
_
,
ok
=
f
.
XLSX
[
drawingXML
]
if
ok
{
// Append Model
decodeWsDr
:=
decodeWsDr
{}
xml
.
Unmarshal
([]
byte
(
f
.
readXML
(
drawingXML
)),
&
decodeWsDr
)
...
...
@@ -331,9 +366,18 @@ func (f *File) addDrawingShape(sheet, drawingXML, cell string, formatSet *format
P
:
&
aP
{
R
:
&
aR
{
RPr
:
aRPr
{
I
:
formatSet
.
Font
.
Italic
,
B
:
formatSet
.
Font
.
Bold
,
Lang
:
"en-US"
,
AltLang
:
"en-US"
,
Sz
:
1100
,
U
:
u
,
Sz
:
formatSet
.
Font
.
Size
*
100
,
Latin
:
&
aLatin
{
Typeface
:
formatSet
.
Font
.
Family
},
SolidFill
:
&
aSolidFill
{
SrgbClr
:
&
attrValString
{
Val
:
strings
.
Replace
(
strings
.
ToUpper
(
formatSet
.
Font
.
Color
),
"#"
,
""
,
-
1
),
},
},
},
T
:
formatSet
.
Text
,
},
...
...
xmlChart.go
浏览文件 @
70f63281
...
...
@@ -108,44 +108,15 @@ type aP struct {
// formatting, since they are directly applied to the paragraph and supersede
// any formatting from styles.
type
aPPr
struct
{
DefRPr
aDefRPr
`xml:"a:defRPr"`
}
// aDefRPr directly maps the a:defRPr element. This element contains all
// default run level text properties for the text runs within a containing
// paragraph. These properties are to be used when overriding properties have
// not been defined within the rPr element.
type
aDefRPr
struct
{
AltLang
string
`xml:"altLang,attr,omitempty"`
B
bool
`xml:"b,attr"`
Baseline
int
`xml:"baseline,attr"`
Bmk
string
`xml:"bmk,attr,omitempty"`
Cap
string
`xml:"cap,attr,omitempty"`
Dirty
bool
`xml:"dirty,attr,omitempty"`
Err
bool
`xml:"err,attr,omitempty"`
I
bool
`xml:"i,attr"`
Kern
int
`xml:"kern,attr"`
Kumimoji
bool
`xml:"kumimoji,attr,omitempty"`
Lang
string
`xml:"lang,attr,omitempty"`
NoProof
bool
`xml:"noProof,attr,omitempty"`
NormalizeH
bool
`xml:"normalizeH,attr,omitempty"`
SmtClean
bool
`xml:"smtClean,attr,omitempty"`
SmtID
uint64
`xml:"smtId,attr,omitempty"`
Spc
int
`xml:"spc,attr"`
Strike
string
`xml:"strike,attr,omitempty"`
Sz
int
`xml:"sz,attr"`
U
string
`xml:"u,attr,omitempty"`
SolidFill
*
aSolidFill
`xml:"a:solidFill"`
Latin
*
aLatin
`xml:"a:latin"`
Ea
*
aEa
`xml:"a:ea"`
Cs
*
aCs
`xml:"a:cs"`
DefRPr
aRPr
`xml:"a:defRPr"`
}
// aSolidFill (Solid Fill) directly maps the solidFill element. This element
// specifies a solid color fill. The shape is filled entirely with the specified
// color.
type
aSolidFill
struct
{
SchemeClr
*
aSchemeClr
`xml:"a:schemeClr,omitempty"`
SchemeClr
*
aSchemeClr
`xml:"a:schemeClr"`
SrgbClr
*
attrValString
`xml:"a:srgbClr"`
}
// aSchemeClr (Scheme Color) directly maps the a:schemeClr element. This
...
...
@@ -206,9 +177,29 @@ type aR struct {
// properties are defined as direct formatting, since they are directly applied
// to the run and supersede any formatting from styles.
type
aRPr
struct
{
Lang
string
`xml:"lang,attr,omitempty"`
AltLang
string
`xml:"altLang,attr,omitempty"`
Sz
int
`xml:"sz,attr,omitempty"`
AltLang
string
`xml:"altLang,attr,omitempty"`
B
bool
`xml:"b,attr"`
Baseline
int
`xml:"baseline,attr"`
Bmk
string
`xml:"bmk,attr,omitempty"`
Cap
string
`xml:"cap,attr,omitempty"`
Dirty
bool
`xml:"dirty,attr,omitempty"`
Err
bool
`xml:"err,attr,omitempty"`
I
bool
`xml:"i,attr"`
Kern
int
`xml:"kern,attr"`
Kumimoji
bool
`xml:"kumimoji,attr,omitempty"`
Lang
string
`xml:"lang,attr,omitempty"`
NoProof
bool
`xml:"noProof,attr,omitempty"`
NormalizeH
bool
`xml:"normalizeH,attr,omitempty"`
SmtClean
bool
`xml:"smtClean,attr,omitempty"`
SmtID
uint64
`xml:"smtId,attr,omitempty"`
Spc
int
`xml:"spc,attr"`
Strike
string
`xml:"strike,attr,omitempty"`
Sz
int
`xml:"sz,attr,omitempty"`
U
string
`xml:"u,attr,omitempty"`
SolidFill
*
aSolidFill
`xml:"a:solidFill"`
Latin
*
aLatin
`xml:"a:latin"`
Ea
*
aEa
`xml:"a:ea"`
Cs
*
aCs
`xml:"a:cs"`
}
// cSpPr (Shape Properties) directly maps the c:spPr element. This element
...
...
@@ -579,14 +570,10 @@ type formatChart struct {
// formatChartLegend directly maps the format settings of the chart legend.
type
formatChartLegend
struct
{
None
bool
`json:"none"`
DeleteSeries
[]
int
`json:"delete_series"`
Font
struct
{
Size
int
`json:"size"`
Blod
bool
`json:"blod"`
Italic
bool
`json:"italic"`
}
`json:"font"`
Layout
struct
{
None
bool
`json:"none"`
DeleteSeries
[]
int
`json:"delete_series"`
Font
formatFont
`json:"font"`
Layout
struct
{
X
float64
`json:"x"`
Y
float64
`json:"y"`
Width
float64
`json:"width"`
...
...
xmlDrawing.go
浏览文件 @
70f63281
...
...
@@ -349,6 +349,7 @@ type formatShape struct {
Width
int
`json:"width"`
Height
int
`json:"height"`
Format
formatPicture
`json:"format"`
Font
formatFont
`json:"font"`
Text
string
`json:"text"`
Color
formatShapeColor
`json:"color"`
}
...
...
xmlStyles.go
浏览文件 @
70f63281
...
...
@@ -282,6 +282,16 @@ type xlsxStyleColors struct {
Color
string
`xml:",innerxml"`
}
// formatFont directly maps the styles settings of the fonts.
type
formatFont
struct
{
Bold
bool
`json:"bold"`
Italic
bool
`json:"italic"`
Underline
string
`json:"underline"`
Family
string
`json:"family"`
Size
int
`json:"size"`
Color
string
`json:"color"`
}
// formatCellStyle directly maps the styles settings of the borders.
type
formatCellStyle
struct
{
Border
[]
struct
{
...
...
@@ -295,14 +305,7 @@ type formatCellStyle struct {
Color
[]
string
`json:"color"`
Shading
int
`json:"shading"`
}
`json:"fill"`
Font
*
struct
{
Bold
bool
`json:"bold"`
Italic
bool
`json:"italic"`
Underline
string
`json:"underline"`
Family
string
`json:"family"`
Size
int
`json:"size"`
Color
string
`json:"color"`
}
`json:"font"`
Font
*
formatFont
`json:"font"`
Alignment
*
struct
{
Horizontal
string
`json:"horizontal"`
Indent
int
`json:"indent"`
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录