Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xuri
excelize
提交
1c45425f
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 搜索 >>
已验证
提交
1c45425f
编写于
10月 17, 2018
作者:
xurime
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
resolve #276, add OfficeOpenXML-XMLSchema-Strict mode support
上级
d8a34af3
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
53 addition
and
32 deletion
+53
-32
chart.go
chart.go
+1
-1
excelize.go
excelize.go
+1
-1
lib.go
lib.go
+16
-0
picture.go
picture.go
+6
-6
sheet.go
sheet.go
+4
-4
styles.go
styles.go
+2
-2
test/Book1.xlsx
test/Book1.xlsx
+0
-0
xmlDrawing.go
xmlDrawing.go
+23
-18
未找到文件。
chart.go
浏览文件 @
1c45425f
...
...
@@ -1097,7 +1097,7 @@ func (f *File) drawingParser(drawingXML string, content *xlsxWsDr) int {
_
,
ok
:=
f
.
XLSX
[
drawingXML
]
if
ok
{
// Append Model
decodeWsDr
:=
decodeWsDr
{}
_
=
xml
.
Unmarshal
(
[]
byte
(
f
.
readXML
(
drawingXML
)),
&
decodeWsDr
)
_
=
xml
.
Unmarshal
(
namespaceStrictToTransitional
(
f
.
readXML
(
drawingXML
)),
&
decodeWsDr
)
content
.
R
=
decodeWsDr
.
R
cNvPrID
=
len
(
decodeWsDr
.
OneCellAnchor
)
+
len
(
decodeWsDr
.
TwoCellAnchor
)
+
1
for
_
,
v
:=
range
decodeWsDr
.
OneCellAnchor
{
...
...
excelize.go
浏览文件 @
1c45425f
...
...
@@ -100,7 +100,7 @@ func (f *File) workSheetReader(sheet string) *xlsxWorksheet {
}
if
f
.
Sheet
[
name
]
==
nil
{
var
xlsx
xlsxWorksheet
_
=
xml
.
Unmarshal
(
f
.
readXML
(
name
),
&
xlsx
)
_
=
xml
.
Unmarshal
(
namespaceStrictToTransitional
(
f
.
readXML
(
name
)
),
&
xlsx
)
if
f
.
checked
==
nil
{
f
.
checked
=
make
(
map
[
string
]
bool
)
}
...
...
lib.go
浏览文件 @
1c45425f
...
...
@@ -183,3 +183,19 @@ func parseFormatSet(formatSet string) []byte {
}
return
[]
byte
(
"{}"
)
}
// namespaceStrictToTransitional provides a method to convert Strict and
// Transitional namespaces.
func
namespaceStrictToTransitional
(
content
[]
byte
)
[]
byte
{
var
namespaceTranslationDic
=
map
[
string
]
string
{
StrictSourceRelationship
:
SourceRelationship
,
StrictSourceRelationshipChart
:
SourceRelationshipChart
,
StrictSourceRelationshipComments
:
SourceRelationshipComments
,
StrictSourceRelationshipImage
:
SourceRelationshipImage
,
StrictNameSpaceSpreadSheet
:
NameSpaceSpreadSheet
,
}
for
s
,
n
:=
range
namespaceTranslationDic
{
content
=
bytes
.
Replace
(
content
,
[]
byte
(
s
),
[]
byte
(
n
),
-
1
)
}
return
content
}
picture.go
浏览文件 @
1c45425f
...
...
@@ -185,7 +185,7 @@ func (f *File) addSheetRelationships(sheet, relType, target, targetMode string)
_
,
ok
=
f
.
XLSX
[
rels
]
if
ok
{
ID
.
Reset
()
_
=
xml
.
Unmarshal
(
[]
byte
(
f
.
readXML
(
rels
)),
&
sheetRels
)
_
=
xml
.
Unmarshal
(
namespaceStrictToTransitional
(
f
.
readXML
(
rels
)),
&
sheetRels
)
rID
=
len
(
sheetRels
.
Relationships
)
+
1
ID
.
WriteString
(
"rId"
)
ID
.
WriteString
(
strconv
.
Itoa
(
rID
))
...
...
@@ -211,7 +211,7 @@ func (f *File) deleteSheetRelationships(sheet, rID string) {
}
var
rels
=
"xl/worksheets/_rels/"
+
strings
.
TrimPrefix
(
name
,
"xl/worksheets/"
)
+
".rels"
var
sheetRels
xlsxWorkbookRels
_
=
xml
.
Unmarshal
(
[]
byte
(
f
.
readXML
(
rels
)),
&
sheetRels
)
_
=
xml
.
Unmarshal
(
namespaceStrictToTransitional
(
f
.
readXML
(
rels
)),
&
sheetRels
)
for
k
,
v
:=
range
sheetRels
.
Relationships
{
if
v
.
ID
==
rID
{
sheetRels
.
Relationships
=
append
(
sheetRels
.
Relationships
[
:
k
],
sheetRels
.
Relationships
[
k
+
1
:
]
...
)
...
...
@@ -328,7 +328,7 @@ func (f *File) addDrawingRelationships(index int, relType, target, targetMode st
_
,
ok
:=
f
.
XLSX
[
rels
]
if
ok
{
ID
.
Reset
()
_
=
xml
.
Unmarshal
(
[]
byte
(
f
.
readXML
(
rels
)),
&
drawingRels
)
_
=
xml
.
Unmarshal
(
namespaceStrictToTransitional
(
f
.
readXML
(
rels
)),
&
drawingRels
)
rID
=
len
(
drawingRels
.
Relationships
)
+
1
ID
.
WriteString
(
"rId"
)
ID
.
WriteString
(
strconv
.
Itoa
(
rID
))
...
...
@@ -448,7 +448,7 @@ func (f *File) getSheetRelationshipsTargetByID(sheet, rID string) string {
}
var
rels
=
"xl/worksheets/_rels/"
+
strings
.
TrimPrefix
(
name
,
"xl/worksheets/"
)
+
".rels"
var
sheetRels
xlsxWorkbookRels
_
=
xml
.
Unmarshal
(
[]
byte
(
f
.
readXML
(
rels
)),
&
sheetRels
)
_
=
xml
.
Unmarshal
(
namespaceStrictToTransitional
(
f
.
readXML
(
rels
)),
&
sheetRels
)
for
_
,
v
:=
range
sheetRels
.
Relationships
{
if
v
.
ID
==
rID
{
return
v
.
Target
...
...
@@ -488,7 +488,7 @@ func (f *File) GetPicture(sheet, cell string) (string, []byte) {
return
""
,
nil
}
decodeWsDr
:=
decodeWsDr
{}
_
=
xml
.
Unmarshal
(
[]
byte
(
f
.
readXML
(
drawingXML
)),
&
decodeWsDr
)
_
=
xml
.
Unmarshal
(
namespaceStrictToTransitional
(
f
.
readXML
(
drawingXML
)),
&
decodeWsDr
)
cell
=
strings
.
ToUpper
(
cell
)
fromCol
:=
string
(
strings
.
Map
(
letterOnlyMapF
,
cell
))
...
...
@@ -523,7 +523,7 @@ func (f *File) getDrawingRelationships(rels, rID string) *xlsxWorkbookRelation {
return
nil
}
var
drawingRels
xlsxWorkbookRels
_
=
xml
.
Unmarshal
(
[]
byte
(
f
.
readXML
(
rels
)),
&
drawingRels
)
_
=
xml
.
Unmarshal
(
namespaceStrictToTransitional
(
f
.
readXML
(
rels
)),
&
drawingRels
)
for
_
,
v
:=
range
drawingRels
.
Relationships
{
if
v
.
ID
==
rID
{
return
&
v
...
...
sheet.go
浏览文件 @
1c45425f
...
...
@@ -51,7 +51,7 @@ func (f *File) NewSheet(name string) int {
func
(
f
*
File
)
contentTypesReader
()
*
xlsxTypes
{
if
f
.
ContentTypes
==
nil
{
var
content
xlsxTypes
_
=
xml
.
Unmarshal
(
[]
byte
(
f
.
readXML
(
"[Content_Types].xml"
)),
&
content
)
_
=
xml
.
Unmarshal
(
namespaceStrictToTransitional
(
f
.
readXML
(
"[Content_Types].xml"
)),
&
content
)
f
.
ContentTypes
=
&
content
}
return
f
.
ContentTypes
...
...
@@ -71,7 +71,7 @@ func (f *File) contentTypesWriter() {
func
(
f
*
File
)
workbookReader
()
*
xlsxWorkbook
{
if
f
.
WorkBook
==
nil
{
var
content
xlsxWorkbook
_
=
xml
.
Unmarshal
(
[]
byte
(
f
.
readXML
(
"xl/workbook.xml"
)),
&
content
)
_
=
xml
.
Unmarshal
(
namespaceStrictToTransitional
(
f
.
readXML
(
"xl/workbook.xml"
)),
&
content
)
f
.
WorkBook
=
&
content
}
return
f
.
WorkBook
...
...
@@ -162,7 +162,7 @@ func (f *File) setWorkbook(name string, rid int) {
func
(
f
*
File
)
workbookRelsReader
()
*
xlsxWorkbookRels
{
if
f
.
WorkBookRels
==
nil
{
var
content
xlsxWorkbookRels
_
=
xml
.
Unmarshal
(
[]
byte
(
f
.
readXML
(
"xl/_rels/workbook.xml.rels"
)),
&
content
)
_
=
xml
.
Unmarshal
(
namespaceStrictToTransitional
(
f
.
readXML
(
"xl/_rels/workbook.xml.rels"
)),
&
content
)
f
.
WorkBookRels
=
&
content
}
return
f
.
WorkBookRels
...
...
@@ -267,7 +267,7 @@ func (f *File) GetActiveSheetIndex() int {
buffer
.
WriteString
(
"xl/worksheets/sheet"
)
buffer
.
WriteString
(
strings
.
TrimPrefix
(
v
.
ID
,
"rId"
))
buffer
.
WriteString
(
".xml"
)
_
=
xml
.
Unmarshal
(
[]
byte
(
f
.
readXML
(
buffer
.
String
())),
&
xlsx
)
_
=
xml
.
Unmarshal
(
namespaceStrictToTransitional
(
f
.
readXML
(
buffer
.
String
())),
&
xlsx
)
for
_
,
sheetView
:=
range
xlsx
.
SheetViews
.
SheetView
{
if
sheetView
.
TabSelected
{
ID
,
_
:=
strconv
.
Atoi
(
strings
.
TrimPrefix
(
v
.
ID
,
"rId"
))
...
...
styles.go
浏览文件 @
1c45425f
...
...
@@ -999,7 +999,7 @@ func is12HourTime(format string) bool {
func
(
f
*
File
)
stylesReader
()
*
xlsxStyleSheet
{
if
f
.
Styles
==
nil
{
var
styleSheet
xlsxStyleSheet
_
=
xml
.
Unmarshal
(
[]
byte
(
f
.
readXML
(
"xl/styles.xml"
)),
&
styleSheet
)
_
=
xml
.
Unmarshal
(
namespaceStrictToTransitional
(
f
.
readXML
(
"xl/styles.xml"
)),
&
styleSheet
)
f
.
Styles
=
&
styleSheet
}
return
f
.
Styles
...
...
@@ -2757,7 +2757,7 @@ func getPaletteColor(color string) string {
// structure after deserialization.
func
(
f
*
File
)
themeReader
()
*
xlsxTheme
{
var
theme
xlsxTheme
_
=
xml
.
Unmarshal
(
[]
byte
(
f
.
readXML
(
"xl/theme/theme1.xml"
)),
&
theme
)
_
=
xml
.
Unmarshal
(
namespaceStrictToTransitional
(
f
.
readXML
(
"xl/theme/theme1.xml"
)),
&
theme
)
return
&
theme
}
...
...
test/Book1.xlsx
浏览文件 @
1c45425f
无法预览此类型文件
xmlDrawing.go
浏览文件 @
1c45425f
...
...
@@ -13,24 +13,29 @@ import "encoding/xml"
// Source relationship and namespace.
const
(
SourceRelationship
=
"http://schemas.openxmlformats.org/officeDocument/2006/relationships"
SourceRelationshipChart
=
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart"
SourceRelationshipComments
=
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"
SourceRelationshipImage
=
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
SourceRelationshipTable
=
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/table"
SourceRelationshipDrawingML
=
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing"
SourceRelationshipDrawingVML
=
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing"
SourceRelationshipHyperLink
=
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
SourceRelationshipWorkSheet
=
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"
SourceRelationshipChart201506
=
"http://schemas.microsoft.com/office/drawing/2015/06/chart"
SourceRelationshipChart20070802
=
"http://schemas.microsoft.com/office/drawing/2007/8/2/chart"
SourceRelationshipChart2014
=
"http://schemas.microsoft.com/office/drawing/2014/chart"
SourceRelationshipCompatibility
=
"http://schemas.openxmlformats.org/markup-compatibility/2006"
NameSpaceDrawingML
=
"http://schemas.openxmlformats.org/drawingml/2006/main"
NameSpaceDrawingMLChart
=
"http://schemas.openxmlformats.org/drawingml/2006/chart"
NameSpaceDrawingMLSpreadSheet
=
"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"
NameSpaceSpreadSheet
=
"http://schemas.openxmlformats.org/spreadsheetml/2006/main"
NameSpaceXML
=
"http://www.w3.org/XML/1998/namespace"
SourceRelationship
=
"http://schemas.openxmlformats.org/officeDocument/2006/relationships"
SourceRelationshipChart
=
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart"
SourceRelationshipComments
=
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"
SourceRelationshipImage
=
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
SourceRelationshipTable
=
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/table"
SourceRelationshipDrawingML
=
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing"
SourceRelationshipDrawingVML
=
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing"
SourceRelationshipHyperLink
=
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
SourceRelationshipWorkSheet
=
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"
SourceRelationshipChart201506
=
"http://schemas.microsoft.com/office/drawing/2015/06/chart"
SourceRelationshipChart20070802
=
"http://schemas.microsoft.com/office/drawing/2007/8/2/chart"
SourceRelationshipChart2014
=
"http://schemas.microsoft.com/office/drawing/2014/chart"
SourceRelationshipCompatibility
=
"http://schemas.openxmlformats.org/markup-compatibility/2006"
NameSpaceDrawingML
=
"http://schemas.openxmlformats.org/drawingml/2006/main"
NameSpaceDrawingMLChart
=
"http://schemas.openxmlformats.org/drawingml/2006/chart"
NameSpaceDrawingMLSpreadSheet
=
"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"
NameSpaceSpreadSheet
=
"http://schemas.openxmlformats.org/spreadsheetml/2006/main"
NameSpaceXML
=
"http://www.w3.org/XML/1998/namespace"
StrictSourceRelationship
=
"http://purl.oclc.org/ooxml/officeDocument/relationships"
StrictSourceRelationshipChart
=
"http://purl.oclc.org/ooxml/officeDocument/relationships/chart"
StrictSourceRelationshipComments
=
"http://purl.oclc.org/ooxml/officeDocument/relationships/comments"
StrictSourceRelationshipImage
=
"http://purl.oclc.org/ooxml/officeDocument/relationships/image"
StrictNameSpaceSpreadSheet
=
"http://purl.oclc.org/ooxml/spreadsheetml/main"
)
var
supportImageTypes
=
map
[
string
]
string
{
".gif"
:
".gif"
,
".jpg"
:
".jpeg"
,
".jpeg"
:
".jpeg"
,
".png"
:
".png"
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录