Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xuri
excelize
提交
5dc22e87
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 搜索 >>
已验证
提交
5dc22e87
编写于
4月 02, 2024
作者:
xurime
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support get the cell images inserted by IMAGE formula function
上级
99992214
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
174 addition
and
67 deletion
+174
-67
excelize.go
excelize.go
+31
-6
picture.go
picture.go
+56
-31
picture_test.go
picture_test.go
+51
-13
templates.go
templates.go
+19
-17
xmlMetaData.go
xmlMetaData.go
+17
-0
未找到文件。
excelize.go
浏览文件 @
5dc22e87
...
...
@@ -605,7 +605,7 @@ func (f *File) metadataReader() (*xlsxMetadata, error) {
// deserialization of xl/richData/richvalue.xml.
func
(
f
*
File
)
richValueReader
()
(
*
xlsxRichValueData
,
error
)
{
var
richValue
xlsxRichValueData
if
err
:=
f
.
xmlNewDecoder
(
bytes
.
NewReader
(
namespaceStrictToTransitional
(
f
.
readXML
(
defaultXMLR
ichDataRichValue
))))
.
if
err
:=
f
.
xmlNewDecoder
(
bytes
.
NewReader
(
namespaceStrictToTransitional
(
f
.
readXML
(
defaultXMLR
dRichValuePart
))))
.
Decode
(
&
richValue
);
err
!=
nil
&&
err
!=
io
.
EOF
{
return
&
richValue
,
err
}
...
...
@@ -616,18 +616,43 @@ func (f *File) richValueReader() (*xlsxRichValueData, error) {
// after deserialization of xl/richData/richValueRel.xml.
func
(
f
*
File
)
richValueRelReader
()
(
*
xlsxRichValueRels
,
error
)
{
var
richValueRels
xlsxRichValueRels
if
err
:=
f
.
xmlNewDecoder
(
bytes
.
NewReader
(
namespaceStrictToTransitional
(
f
.
readXML
(
defaultXMLR
ichData
RichValueRel
))))
.
if
err
:=
f
.
xmlNewDecoder
(
bytes
.
NewReader
(
namespaceStrictToTransitional
(
f
.
readXML
(
defaultXMLR
d
RichValueRel
))))
.
Decode
(
&
richValueRels
);
err
!=
nil
&&
err
!=
io
.
EOF
{
return
&
richValueRels
,
err
}
return
&
richValueRels
,
nil
}
// getRichDataRichValueRelRelationships provides a function to get drawing
// relationships from xl/richData/_rels/richValueRel.xml.rels by given
// relationship ID.
// richValueWebImageReader provides a function to get the pointer to the
// structure after deserialization of xl/richData/rdRichValueWebImage.xml.
func
(
f
*
File
)
richValueWebImageReader
()
(
*
xlsxWebImagesSupportingRichData
,
error
)
{
var
richValueWebImages
xlsxWebImagesSupportingRichData
if
err
:=
f
.
xmlNewDecoder
(
bytes
.
NewReader
(
namespaceStrictToTransitional
(
f
.
readXML
(
defaultXMLRdRichValueWebImagePart
))))
.
Decode
(
&
richValueWebImages
);
err
!=
nil
&&
err
!=
io
.
EOF
{
return
&
richValueWebImages
,
err
}
return
&
richValueWebImages
,
nil
}
// getRichDataRichValueRelRelationships provides a function to get relationships
// from xl/richData/_rels/richValueRel.xml.rels by given relationship ID.
func
(
f
*
File
)
getRichDataRichValueRelRelationships
(
rID
string
)
*
xlsxRelationship
{
if
rels
,
_
:=
f
.
relsReader
(
defaultXMLRichDataRichValueRelRels
);
rels
!=
nil
{
if
rels
,
_
:=
f
.
relsReader
(
defaultXMLRdRichValueRelRels
);
rels
!=
nil
{
rels
.
mu
.
Lock
()
defer
rels
.
mu
.
Unlock
()
for
_
,
v
:=
range
rels
.
Relationships
{
if
v
.
ID
==
rID
{
return
&
v
}
}
}
return
nil
}
// getRichValueWebImageRelationships provides a function to get relationships
// from xl/richData/_rels/rdRichValueWebImage.xml.rels by given relationship ID.
func
(
f
*
File
)
getRichValueWebImageRelationships
(
rID
string
)
*
xlsxRelationship
{
if
rels
,
_
:=
f
.
relsReader
(
defaultXMLRdRichValueWebImagePartRels
);
rels
!=
nil
{
rels
.
mu
.
Lock
()
defer
rels
.
mu
.
Unlock
()
for
_
,
v
:=
range
rels
.
Relationships
{
...
...
picture.go
浏览文件 @
5dc22e87
...
...
@@ -31,6 +31,7 @@ type PictureInsertType int
const
(
PictureInsertTypePlaceOverCells
PictureInsertType
=
iota
PictureInsertTypePlaceInCell
PictureInsertTypeIMAGE
PictureInsertTypeDISPIMG
)
...
...
@@ -450,8 +451,7 @@ func (f *File) addMedia(file []byte, ext string) string {
// GetPictures provides a function to get picture meta info and raw content
// embed in spreadsheet by given worksheet and cell name. This function
// returns the image contents as []byte data types. This function is
// concurrency safe. Note that, this function doesn't support getting cell image
// inserted by IMAGE formula function currently. For example:
// concurrency safe. For example:
//
// f, err := excelize.OpenFile("Book1.xlsx")
// if err != nil {
...
...
@@ -507,8 +507,7 @@ func (f *File) GetPictures(sheet, cell string) ([]Picture, error) {
}
// GetPictureCells returns all picture cell references in a worksheet by a
// specific worksheet name. Note that, this function doesn't support getting
// cell image inserted by IMAGE formula function currently.
// specific worksheet name.
func
(
f
*
File
)
GetPictureCells
(
sheet
string
)
([]
string
,
error
)
{
f
.
mu
.
Lock
()
ws
,
err
:=
f
.
workSheetReader
(
sheet
)
...
...
@@ -812,7 +811,7 @@ func (f *File) getImageCells(sheet string) ([]string, error) {
}
cells
=
append
(
cells
,
c
.
R
)
}
r
,
err
:=
f
.
getImageCellRel
(
&
c
)
r
,
err
:=
f
.
getImageCellRel
(
&
c
,
&
Picture
{}
)
if
err
!=
nil
{
return
cells
,
err
}
...
...
@@ -825,30 +824,52 @@ func (f *File) getImageCells(sheet string) ([]string, error) {
return
cells
,
err
}
// get
ImageCellRichValueIdx returns index of the cell image rich value by given
//
cell value meta index and meta blocks
.
func
(
f
*
File
)
get
ImageCellRichValueIdx
(
vm
uint
,
blocks
*
xlsxMetadataBlocks
)
(
int
,
error
)
{
richValueIdx
:=
blocks
.
Bk
[
vm
-
1
]
.
Rc
[
0
]
.
V
richValue
,
err
:=
f
.
richValueReader
(
)
// get
RichDataRichValueRel returns relationship of the cell image by given meta
//
blocks value
.
func
(
f
*
File
)
get
RichDataRichValueRel
(
val
string
)
(
*
xlsxRelationship
,
error
)
{
var
r
*
xlsxRelationship
idx
,
err
:=
strconv
.
Atoi
(
val
)
if
err
!=
nil
{
return
-
1
,
err
return
r
,
err
}
if
richValueIdx
>=
len
(
richValue
.
Rv
)
{
return
-
1
,
err
richValueRel
,
err
:=
f
.
richValueRelReader
()
if
err
!=
nil
{
return
r
,
err
}
rv
:=
richValue
.
Rv
[
richValueIdx
]
.
V
if
len
(
rv
)
!=
2
||
rv
[
1
]
!=
"5"
{
return
-
1
,
err
if
idx
>=
len
(
richValueRel
.
Rels
)
{
return
r
,
err
}
rID
:=
richValueRel
.
Rels
[
idx
]
.
ID
if
r
=
f
.
getRichDataRichValueRelRelationships
(
rID
);
r
!=
nil
&&
r
.
Type
!=
SourceRelationshipImage
{
return
nil
,
err
}
return
r
,
err
}
// getRichDataWebImagesRel returns relationship of a web image by given meta
// blocks value.
func
(
f
*
File
)
getRichDataWebImagesRel
(
val
string
)
(
*
xlsxRelationship
,
error
)
{
var
r
*
xlsxRelationship
idx
,
err
:=
strconv
.
Atoi
(
val
)
if
err
!=
nil
{
return
r
,
err
}
richValue
RelIdx
,
err
:=
strconv
.
Atoi
(
rv
[
0
]
)
richValue
WebImages
,
err
:=
f
.
richValueWebImageReader
(
)
if
err
!=
nil
{
return
-
1
,
err
return
r
,
err
}
if
idx
>=
len
(
richValueWebImages
.
WebImageSrd
)
{
return
r
,
err
}
return
richValueRelIdx
,
err
rID
:=
richValueWebImages
.
WebImageSrd
[
idx
]
.
Blip
.
RID
if
r
=
f
.
getRichValueWebImageRelationships
(
rID
);
r
!=
nil
&&
r
.
Type
!=
SourceRelationshipImage
{
return
nil
,
err
}
return
r
,
err
}
// getImageCellRel returns the cell image relationship.
func
(
f
*
File
)
getImageCellRel
(
c
*
xlsxC
)
(
*
xlsxRelationship
,
error
)
{
func
(
f
*
File
)
getImageCellRel
(
c
*
xlsxC
,
pic
*
Picture
)
(
*
xlsxRelationship
,
error
)
{
var
r
*
xlsxRelationship
if
c
.
Vm
==
nil
||
c
.
V
!=
formulaErrorVALUE
{
return
r
,
nil
...
...
@@ -861,20 +882,23 @@ func (f *File) getImageCellRel(c *xlsxC) (*xlsxRelationship, error) {
if
vmd
==
nil
||
int
(
*
c
.
Vm
)
>
len
(
vmd
.
Bk
)
||
len
(
vmd
.
Bk
[
*
c
.
Vm
-
1
]
.
Rc
)
==
0
{
return
r
,
err
}
richValueRelIdx
,
err
:=
f
.
getImageCellRichValueIdx
(
*
c
.
Vm
,
vmd
)
if
err
!=
nil
||
richValueRelIdx
==
-
1
{
return
r
,
err
}
richValueRel
,
err
:=
f
.
richValueRelReader
()
richValueIdx
:=
vmd
.
Bk
[
*
c
.
Vm
-
1
]
.
Rc
[
0
]
.
V
richValue
,
err
:=
f
.
richValueReader
()
if
err
!=
nil
{
return
r
,
err
}
if
richValue
RelIdx
>=
len
(
richValueRel
.
Rels
)
{
if
richValue
Idx
>=
len
(
richValue
.
Rv
)
{
return
r
,
err
}
rID
:=
richValueRel
.
Rels
[
richValueRelIdx
]
.
ID
if
r
=
f
.
getRichDataRichValueRelRelationships
(
rID
);
r
!=
nil
&&
r
.
Type
!=
SourceRelationshipImage
{
return
nil
,
err
rv
:=
richValue
.
Rv
[
richValueIdx
]
.
V
if
len
(
rv
)
==
2
&&
rv
[
1
]
==
"5"
{
pic
.
InsertType
=
PictureInsertTypePlaceInCell
return
f
.
getRichDataRichValueRel
(
rv
[
0
])
}
// cell image inserted by IMAGE formula function
if
len
(
rv
)
>
3
&&
rv
[
1
]
+
rv
[
2
]
==
"10"
{
pic
.
InsertType
=
PictureInsertTypeIMAGE
return
f
.
getRichDataWebImagesRel
(
rv
[
0
])
}
return
r
,
err
}
...
...
@@ -888,11 +912,12 @@ func (f *File) getCellImages(sheet, cell string) ([]Picture, error) {
return
pics
,
err
}
_
,
err
=
f
.
getCellStringFunc
(
sheet
,
cell
,
func
(
x
*
xlsxWorksheet
,
c
*
xlsxC
)
(
string
,
bool
,
error
)
{
r
,
err
:=
f
.
getImageCellRel
(
c
)
pic
:=
Picture
{
Format
:
&
GraphicOptions
{},
InsertType
:
PictureInsertTypePlaceInCell
}
r
,
err
:=
f
.
getImageCellRel
(
c
,
&
pic
)
if
err
!=
nil
||
r
==
nil
{
return
""
,
true
,
err
}
pic
:=
Picture
{
Extension
:
filepath
.
Ext
(
r
.
Target
),
Format
:
&
GraphicOptions
{},
InsertType
:
PictureInsertTypePlaceInCell
}
pic
.
Extension
=
filepath
.
Ext
(
r
.
Target
)
if
buffer
,
_
:=
f
.
Pkg
.
Load
(
strings
.
TrimPrefix
(
strings
.
ReplaceAll
(
r
.
Target
,
".."
,
"xl"
),
"/"
));
buffer
!=
nil
{
pic
.
File
=
buffer
.
([]
byte
)
pics
=
append
(
pics
,
pic
)
...
...
picture_test.go
浏览文件 @
5dc22e87
...
...
@@ -246,7 +246,7 @@ func TestGetPicture(t *testing.T) {
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
f
.
SetCellFormula
(
"Sheet1"
,
"F21"
,
"=_xlfn.DISPIMG(
\"
ID_********************************
\"
,1)"
))
f
.
Pkg
.
Store
(
defaultXMLPathCellImages
,
[]
byte
(
`<etc:cellImages xmlns:etc="http://www.wps.cn/officeDocument/2017/etCustomData"><etc:cellImage><xdr:pic><xdr:nvPicPr><xdr:cNvPr id="1" name="ID_********************************" descr="CellImage1"/></xdr:nvPicPr><xdr:blipFill><a:blip r:embed="rId1"/></xdr:blipFill></xdr:pic></etc:cellImage></etc:cellImages>`
))
f
.
Pkg
.
Store
(
defaultXMLPathCellImagesRels
,
[]
byte
(
`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="media/image1.jpeg"/></Relationships>`
))
f
.
Pkg
.
Store
(
defaultXMLPathCellImagesRels
,
[]
byte
(
fmt
.
Sprintf
(
`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="%s" Target="media/image1.jpeg"/></Relationships>`
,
SourceRelationshipImage
)
))
pics
,
err
=
f
.
GetPictures
(
"Sheet1"
,
"F21"
)
assert
.
NoError
(
t
,
err
)
assert
.
Len
(
t
,
pics
,
2
)
...
...
@@ -457,9 +457,9 @@ func TestGetCellImages(t *testing.T) {
f
:=
NewFile
()
assert
.
NoError
(
t
,
f
.
AddPicture
(
"Sheet1"
,
"A1"
,
filepath
.
Join
(
"test"
,
"images"
,
"excel.png"
),
nil
))
f
.
Pkg
.
Store
(
defaultXMLMetadata
,
[]
byte
(
`<metadata><valueMetadata count="1"><bk><rc t="1" v="0"/></bk></valueMetadata></metadata>`
))
f
.
Pkg
.
Store
(
defaultXMLR
ichDataRichValue
,
[]
byte
(
`<rvData count="1"><rv s="0"><v>0</v><v>5</v></rv></rvData>`
))
f
.
Pkg
.
Store
(
defaultXMLR
ichData
RichValueRel
,
[]
byte
(
`<richValueRels><rel r:id="rId1"/></richValueRels>`
))
f
.
Pkg
.
Store
(
defaultXMLR
ichData
RichValueRelRels
,
[]
byte
(
fmt
.
Sprintf
(
`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="%s" Target="../media/image1.png"/></Relationships>`
,
SourceRelationshipImage
)))
f
.
Pkg
.
Store
(
defaultXMLR
dRichValuePart
,
[]
byte
(
`<rvData count="1"><rv s="0"><v>0</v><v>5</v></rv></rvData>`
))
f
.
Pkg
.
Store
(
defaultXMLR
d
RichValueRel
,
[]
byte
(
`<richValueRels><rel r:id="rId1"/></richValueRels>`
))
f
.
Pkg
.
Store
(
defaultXMLR
d
RichValueRelRels
,
[]
byte
(
fmt
.
Sprintf
(
`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="%s" Target="../media/image1.png"/></Relationships>`
,
SourceRelationshipImage
)))
f
.
Sheet
.
Store
(
"xl/worksheets/sheet1.xml"
,
&
xlsxWorksheet
{
SheetData
:
xlsxSheetData
{
Row
:
[]
xlsxRow
{
{
R
:
1
,
C
:
[]
xlsxC
{{
R
:
"A1"
,
T
:
"e"
,
V
:
formulaErrorVALUE
,
Vm
:
uintPtr
(
1
)}}},
...
...
@@ -477,19 +477,19 @@ func TestGetCellImages(t *testing.T) {
assert
.
Equal
(
t
,
[]
string
{
"A1"
},
cells
)
// Test get the cell images without image relationships parts
f
.
Relationships
.
Delete
(
defaultXMLR
ichData
RichValueRelRels
)
f
.
Pkg
.
Store
(
defaultXMLR
ichData
RichValueRelRels
,
[]
byte
(
fmt
.
Sprintf
(
`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="%s" Target="../media/image1.png"/></Relationships>`
,
SourceRelationshipHyperLink
)))
f
.
Relationships
.
Delete
(
defaultXMLR
d
RichValueRelRels
)
f
.
Pkg
.
Store
(
defaultXMLR
d
RichValueRelRels
,
[]
byte
(
fmt
.
Sprintf
(
`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="%s" Target="../media/image1.png"/></Relationships>`
,
SourceRelationshipHyperLink
)))
pics
,
err
=
f
.
GetPictures
(
"Sheet1"
,
"A1"
)
assert
.
NoError
(
t
,
err
)
assert
.
Empty
(
t
,
pics
)
// Test get the cell images with unsupported charset rich data rich value relationships
f
.
Relationships
.
Delete
(
defaultXMLR
ichData
RichValueRelRels
)
f
.
Pkg
.
Store
(
defaultXMLR
ichData
RichValueRelRels
,
MacintoshCyrillicCharset
)
f
.
Relationships
.
Delete
(
defaultXMLR
d
RichValueRelRels
)
f
.
Pkg
.
Store
(
defaultXMLR
d
RichValueRelRels
,
MacintoshCyrillicCharset
)
pics
,
err
=
f
.
GetPictures
(
"Sheet1"
,
"A1"
)
assert
.
NoError
(
t
,
err
)
assert
.
Empty
(
t
,
pics
)
// Test get the cell images with unsupported charset rich data rich value
f
.
Pkg
.
Store
(
defaultXMLR
ichData
RichValueRel
,
MacintoshCyrillicCharset
)
f
.
Pkg
.
Store
(
defaultXMLR
d
RichValueRel
,
MacintoshCyrillicCharset
)
_
,
err
=
f
.
GetPictures
(
"Sheet1"
,
"A1"
)
assert
.
EqualError
(
t
,
err
,
"XML syntax error on line 1: invalid UTF-8"
)
// Test get the image cells without block of metadata records
...
...
@@ -498,7 +498,7 @@ func TestGetCellImages(t *testing.T) {
assert
.
Empty
(
t
,
cells
)
// Test get the cell images with rich data rich value relationships
f
.
Pkg
.
Store
(
defaultXMLMetadata
,
[]
byte
(
`<metadata><valueMetadata count="1"><bk><rc t="1" v="0"/></bk></valueMetadata></metadata>`
))
f
.
Pkg
.
Store
(
defaultXMLR
ichData
RichValueRel
,
[]
byte
(
`<richValueRels/>`
))
f
.
Pkg
.
Store
(
defaultXMLR
d
RichValueRel
,
[]
byte
(
`<richValueRels/>`
))
pics
,
err
=
f
.
GetPictures
(
"Sheet1"
,
"A1"
)
assert
.
NoError
(
t
,
err
)
assert
.
Empty
(
t
,
pics
)
...
...
@@ -514,17 +514,17 @@ func TestGetCellImages(t *testing.T) {
f
=
prepareWorkbook
()
// Test get the cell images with empty image cell rich value
f
.
Pkg
.
Store
(
defaultXMLR
ichDataRichValue
,
[]
byte
(
`<rvData count="1"><rv s="0"><v></v><v>5</v></rv></rvData>`
))
f
.
Pkg
.
Store
(
defaultXMLR
dRichValuePart
,
[]
byte
(
`<rvData count="1"><rv s="0"><v></v><v>5</v></rv></rvData>`
))
pics
,
err
=
f
.
GetPictures
(
"Sheet1"
,
"A1"
)
assert
.
EqualError
(
t
,
err
,
"strconv.Atoi: parsing
\"\"
: invalid syntax"
)
assert
.
Empty
(
t
,
pics
)
// Test get the cell images without image cell rich value
f
.
Pkg
.
Store
(
defaultXMLR
ichDataRichValue
,
[]
byte
(
`<rvData count="1"><rv s="0"><v>0</v><v>1</v></rv></rvData>`
))
f
.
Pkg
.
Store
(
defaultXMLR
dRichValuePart
,
[]
byte
(
`<rvData count="1"><rv s="0"><v>0</v><v>1</v></rv></rvData>`
))
pics
,
err
=
f
.
GetPictures
(
"Sheet1"
,
"A1"
)
assert
.
NoError
(
t
,
err
)
assert
.
Empty
(
t
,
pics
)
// Test get the cell images with unsupported charset rich value
f
.
Pkg
.
Store
(
defaultXMLR
ichDataRichValue
,
MacintoshCyrillicCharset
)
f
.
Pkg
.
Store
(
defaultXMLR
dRichValuePart
,
MacintoshCyrillicCharset
)
_
,
err
=
f
.
GetPictures
(
"Sheet1"
,
"A1"
)
assert
.
EqualError
(
t
,
err
,
"XML syntax error on line 1: invalid UTF-8"
)
...
...
@@ -534,6 +534,44 @@ func TestGetCellImages(t *testing.T) {
pics
,
err
=
f
.
GetPictures
(
"Sheet1"
,
"A1"
)
assert
.
NoError
(
t
,
err
)
assert
.
Empty
(
t
,
pics
)
f
=
prepareWorkbook
()
// Test get the cell images inserted by IMAGE formula function
f
.
Pkg
.
Store
(
defaultXMLRdRichValuePart
,
[]
byte
(
`<rvData count="1"><rv s="1"><v>0</v><v>1</v><v>0</v><v>0</v></rv></rvData>`
))
f
.
Pkg
.
Store
(
defaultXMLRdRichValueWebImagePart
,
[]
byte
(
`<webImagesSrd xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><webImageSrd><address r:id="rId1"/><blip r:id="rId2"/></webImageSrd>
</webImagesSrd>`
))
f
.
Pkg
.
Store
(
defaultXMLRdRichValueWebImagePartRels
,
[]
byte
(
fmt
.
Sprintf
(
`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="%s" Target="https://github.com/xuri/excelize" TargetMode="External"/><Relationship Id="rId2" Type="%s" Target="../media/image1.png"/></Relationships>`
,
SourceRelationshipHyperLink
,
SourceRelationshipImage
)))
pics
,
err
=
f
.
GetPictures
(
"Sheet1"
,
"A1"
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
1
,
len
(
pics
))
assert
.
Equal
(
t
,
PictureInsertTypeIMAGE
,
pics
[
0
]
.
InsertType
)
// Test get the cell images inserted by IMAGE formula function with unsupported charset web images relationships
f
.
Relationships
.
Delete
(
defaultXMLRdRichValueWebImagePartRels
)
f
.
Pkg
.
Store
(
defaultXMLRdRichValueWebImagePartRels
,
MacintoshCyrillicCharset
)
pics
,
err
=
f
.
GetPictures
(
"Sheet1"
,
"A1"
)
assert
.
NoError
(
t
,
err
)
assert
.
Empty
(
t
,
pics
)
// Test get the cell images inserted by IMAGE formula function without image part
f
.
Relationships
.
Delete
(
defaultXMLRdRichValueWebImagePartRels
)
f
.
Pkg
.
Store
(
defaultXMLRdRichValueWebImagePartRels
,
[]
byte
(
fmt
.
Sprintf
(
`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="%s" Target="https://github.com/xuri/excelize" TargetMode="External"/><Relationship Id="rId2" Type="%s" Target="../media/image1.png"/></Relationships>`
,
SourceRelationshipHyperLink
,
SourceRelationshipHyperLink
)))
pics
,
err
=
f
.
GetPictures
(
"Sheet1"
,
"A1"
)
assert
.
NoError
(
t
,
err
)
assert
.
Empty
(
t
,
pics
)
// Test get the cell images inserted by IMAGE formula function with unsupported charset web images part
f
.
Pkg
.
Store
(
defaultXMLRdRichValueWebImagePart
,
MacintoshCyrillicCharset
)
_
,
err
=
f
.
GetPictures
(
"Sheet1"
,
"A1"
)
assert
.
EqualError
(
t
,
err
,
"XML syntax error on line 1: invalid UTF-8"
)
// Test get the cell images inserted by IMAGE formula function with empty charset web images part
f
.
Pkg
.
Store
(
defaultXMLRdRichValueWebImagePart
,
[]
byte
(
`<webImagesSrd xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" />`
))
pics
,
err
=
f
.
GetPictures
(
"Sheet1"
,
"A1"
)
assert
.
NoError
(
t
,
err
)
assert
.
Empty
(
t
,
pics
)
// Test get the cell images inserted by IMAGE formula function with invalid rich value index
f
.
Pkg
.
Store
(
defaultXMLRdRichValuePart
,
[]
byte
(
`<rvData count="1"><rv s="1"><v></v><v>1</v><v>0</v><v>0</v></rv></rvData>`
))
_
,
err
=
f
.
GetPictures
(
"Sheet1"
,
"A1"
)
assert
.
EqualError
(
t
,
err
,
"strconv.Atoi: parsing
\"\"
: invalid syntax"
)
}
func
TestGetImageCells
(
t
*
testing
.
T
)
{
...
...
templates.go
浏览文件 @
5dc22e87
...
...
@@ -266,23 +266,25 @@ var supportedChartDataLabelsPosition = map[ChartType][]ChartDataLabelPositionTyp
}
const
(
defaultTempFileSST
=
"sharedStrings"
defaultXMLMetadata
=
"xl/metadata.xml"
defaultXMLPathCalcChain
=
"xl/calcChain.xml"
defaultXMLPathCellImages
=
"xl/cellimages.xml"
defaultXMLPathCellImagesRels
=
"xl/_rels/cellimages.xml.rels"
defaultXMLPathContentTypes
=
"[Content_Types].xml"
defaultXMLPathDocPropsApp
=
"docProps/app.xml"
defaultXMLPathDocPropsCore
=
"docProps/core.xml"
defaultXMLPathSharedStrings
=
"xl/sharedStrings.xml"
defaultXMLPathStyles
=
"xl/styles.xml"
defaultXMLPathTheme
=
"xl/theme/theme1.xml"
defaultXMLPathVolatileDeps
=
"xl/volatileDependencies.xml"
defaultXMLPathWorkbook
=
"xl/workbook.xml"
defaultXMLPathWorkbookRels
=
"xl/_rels/workbook.xml.rels"
defaultXMLRichDataRichValue
=
"xl/richData/rdrichvalue.xml"
defaultXMLRichDataRichValueRel
=
"xl/richData/richValueRel.xml"
defaultXMLRichDataRichValueRelRels
=
"xl/richData/_rels/richValueRel.xml.rels"
defaultTempFileSST
=
"sharedStrings"
defaultXMLMetadata
=
"xl/metadata.xml"
defaultXMLPathCalcChain
=
"xl/calcChain.xml"
defaultXMLPathCellImages
=
"xl/cellimages.xml"
defaultXMLPathCellImagesRels
=
"xl/_rels/cellimages.xml.rels"
defaultXMLPathContentTypes
=
"[Content_Types].xml"
defaultXMLPathDocPropsApp
=
"docProps/app.xml"
defaultXMLPathDocPropsCore
=
"docProps/core.xml"
defaultXMLPathSharedStrings
=
"xl/sharedStrings.xml"
defaultXMLPathStyles
=
"xl/styles.xml"
defaultXMLPathTheme
=
"xl/theme/theme1.xml"
defaultXMLPathVolatileDeps
=
"xl/volatileDependencies.xml"
defaultXMLPathWorkbook
=
"xl/workbook.xml"
defaultXMLPathWorkbookRels
=
"xl/_rels/workbook.xml.rels"
defaultXMLRdRichValuePart
=
"xl/richData/rdrichvalue.xml"
defaultXMLRdRichValueRel
=
"xl/richData/richValueRel.xml"
defaultXMLRdRichValueRelRels
=
"xl/richData/_rels/richValueRel.xml.rels"
defaultXMLRdRichValueWebImagePart
=
"xl/richData/rdRichValueWebImage.xml"
defaultXMLRdRichValueWebImagePartRels
=
"xl/richData/_rels/rdRichValueWebImage.xml.rels"
)
// IndexedColorMapping is the table of default mappings from indexed color value
...
...
xmlMetaData.go
浏览文件 @
5dc22e87
...
...
@@ -98,3 +98,20 @@ type xlsxRichValueRels struct {
type
xlsxRichValueRelRelationship
struct
{
ID
string
`xml:"id,attr"`
}
// xlsxWebImagesSupportingRichData directly maps the webImagesSrd element. This
// element specifies a list of sets of properties associated with web image rich
// values.
type
xlsxWebImagesSupportingRichData
struct
{
XMLName
xml
.
Name
`xml:"webImagesSrd"`
WebImageSrd
[]
xlsxWebImageSupportingRichData
`xml:"webImageSrd"`
ExtLst
*
xlsxInnerXML
`xml:"extLst"`
}
// xlsxWebImageSupportingRichData directly maps the webImageSrd element. This
// element specifies a set of properties for a web image rich value.
type
xlsxWebImageSupportingRichData
struct
{
Address
xlsxExternalReference
`xml:"address"`
MoreImagesAddress
xlsxExternalReference
`xml:"moreImagesAddress"`
Blip
xlsxExternalReference
`xml:"blip"`
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录