Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xuri
excelize
提交
956a4627
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 搜索 >>
提交
956a4627
编写于
9月 05, 2016
作者:
xurime
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix issue #4 use builtin `map` instead of home-built.
上级
9c3a24d5
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
27 addition
and
46 deletion
+27
-46
cell.go
cell.go
+1
-1
excelize.go
excelize.go
+3
-3
file.go
file.go
+6
-6
lib.go
lib.go
+9
-28
sheet.go
sheet.go
+8
-8
未找到文件。
cell.go
浏览文件 @
956a4627
...
...
@@ -7,7 +7,7 @@ import (
)
// GetCellValue provide function get value from cell by given sheet index and axis in XLSX file
func
GetCellValue
(
file
[]
FileList
,
sheet
string
,
axis
string
)
string
{
func
GetCellValue
(
file
map
[
string
]
string
,
sheet
string
,
axis
string
)
string
{
axis
=
strings
.
ToUpper
(
axis
)
var
xlsx
xlsxWorksheet
row
:=
getRowIndex
(
axis
)
...
...
excelize.go
浏览文件 @
956a4627
...
...
@@ -17,7 +17,7 @@ type FileList struct {
// OpenFile take the name of an XLSX file and returns a populated
// xlsx.File struct for it.
func
OpenFile
(
filename
string
)
(
file
[]
FileList
,
err
error
)
{
func
OpenFile
(
filename
string
)
(
file
map
[
string
]
string
,
err
error
)
{
var
f
*
zip
.
ReadCloser
f
,
err
=
zip
.
OpenReader
(
filename
)
if
err
!=
nil
{
...
...
@@ -28,7 +28,7 @@ func OpenFile(filename string) (file []FileList, err error) {
}
// SetCellInt provide function to set int type value of a cell
func
SetCellInt
(
file
[]
FileList
,
sheet
string
,
axis
string
,
value
int
)
[]
FileList
{
func
SetCellInt
(
file
map
[
string
]
string
,
sheet
string
,
axis
string
,
value
int
)
map
[
string
]
string
{
axis
=
strings
.
ToUpper
(
axis
)
var
xlsx
xlsxWorksheet
col
:=
getColIndex
(
axis
)
...
...
@@ -58,7 +58,7 @@ func SetCellInt(file []FileList, sheet string, axis string, value int) []FileLis
}
// SetCellStr provide function to set string type value of a cell
func
SetCellStr
(
file
[]
FileList
,
sheet
string
,
axis
string
,
value
string
)
[]
FileList
{
func
SetCellStr
(
file
map
[
string
]
string
,
sheet
string
,
axis
string
,
value
string
)
map
[
string
]
string
{
axis
=
strings
.
ToUpper
(
axis
)
var
xlsx
xlsxWorksheet
col
:=
getColIndex
(
axis
)
...
...
file.go
浏览文件 @
956a4627
...
...
@@ -9,8 +9,8 @@ import (
// CreateFile provide function to create new file by default template
// For example:
// xlsx := CreateFile()
func
CreateFile
()
[]
FileList
{
var
file
[]
FileList
func
CreateFile
()
map
[
string
]
string
{
file
:=
make
(
map
[
string
]
string
)
file
=
saveFileList
(
file
,
`_rels/.rels`
,
templateRels
)
file
=
saveFileList
(
file
,
`docProps/app.xml`
,
templateDocpropsApp
)
file
=
saveFileList
(
file
,
`docProps/core.xml`
,
templateDocpropsCore
)
...
...
@@ -24,15 +24,15 @@ func CreateFile() []FileList {
}
// Save after create or update to an xlsx file at the provided path.
func
Save
(
files
[]
FileList
,
name
string
)
error
{
func
Save
(
files
map
[
string
]
string
,
name
string
)
error
{
buf
:=
new
(
bytes
.
Buffer
)
w
:=
zip
.
NewWriter
(
buf
)
for
_
,
file
:=
range
files
{
f
,
err
:=
w
.
Create
(
file
.
Key
)
for
path
,
content
:=
range
files
{
f
,
err
:=
w
.
Create
(
path
)
if
err
!=
nil
{
return
err
}
_
,
err
=
f
.
Write
([]
byte
(
file
.
Value
))
_
,
err
=
f
.
Write
([]
byte
(
content
))
if
err
!=
nil
{
return
err
}
...
...
lib.go
浏览文件 @
956a4627
...
...
@@ -14,51 +14,32 @@ import (
// ReadZip takes a pointer to a zip.ReadCloser and returns a
// xlsx.File struct populated with its contents. In most cases
// ReadZip is not used directly, but is called internally by OpenFile.
func
ReadZip
(
f
*
zip
.
ReadCloser
)
(
[]
FileList
,
error
)
{
func
ReadZip
(
f
*
zip
.
ReadCloser
)
(
map
[
string
]
string
,
error
)
{
defer
f
.
Close
()
return
ReadZipReader
(
&
f
.
Reader
)
}
// ReadZipReader can be used to read an XLSX in memory without
// touching the filesystem.
func
ReadZipReader
(
r
*
zip
.
Reader
)
(
[]
FileList
,
error
)
{
var
fileList
[]
FileList
func
ReadZipReader
(
r
*
zip
.
Reader
)
(
map
[
string
]
string
,
error
)
{
fileList
:=
make
(
map
[
string
]
string
)
for
_
,
v
:=
range
r
.
File
{
singleFile
:=
FileList
{
Key
:
v
.
Name
,
Value
:
readFile
(
v
),
}
fileList
=
append
(
fileList
,
singleFile
)
fileList
[
v
.
Name
]
=
readFile
(
v
)
}
return
fileList
,
nil
}
// Read XML content as string and replace drawing property in XML namespace of sheet
func
readXML
(
files
[]
FileList
,
name
string
)
string
{
for
_
,
file
:=
range
files
{
if
file
.
Key
==
name
{
return
strings
.
Replace
(
file
.
Value
,
"<drawing r:id="
,
"<drawing rid="
,
-
1
)
}
func
readXML
(
files
map
[
string
]
string
,
name
string
)
string
{
if
content
,
ok
:=
files
[
name
];
ok
{
return
strings
.
Replace
(
content
,
"<drawing r:id="
,
"<drawing rid="
,
-
1
)
}
return
``
}
// Update given file content in file list of XLSX
func
saveFileList
(
files
[]
FileList
,
name
string
,
content
string
)
[]
FileList
{
for
k
,
v
:=
range
files
{
if
v
.
Key
==
name
{
files
=
files
[
:
k
+
copy
(
files
[
k
:
],
files
[
k
+
1
:
])]
files
=
append
(
files
,
FileList
{
Key
:
name
,
Value
:
XMLHeader
+
content
,
})
return
files
}
}
files
=
append
(
files
,
FileList
{
Key
:
name
,
Value
:
XMLHeader
+
content
,
})
func
saveFileList
(
files
map
[
string
]
string
,
name
string
,
content
string
)
map
[
string
]
string
{
files
[
name
]
=
XMLHeader
+
content
return
files
}
...
...
sheet.go
浏览文件 @
956a4627
...
...
@@ -11,7 +11,7 @@ import (
// NewSheet provice function to greate a new sheet by given index, when
// creating a new XLSX file, the default sheet will be create, when you
// create a new file, you need to ensure that the index is continuous.
func
NewSheet
(
file
[]
FileList
,
index
int
,
name
string
)
[]
FileList
{
func
NewSheet
(
file
map
[
string
]
string
,
index
int
,
name
string
)
map
[
string
]
string
{
// Update docProps/app.xml
file
=
setAppXML
(
file
)
// Update [Content_Types].xml
...
...
@@ -26,7 +26,7 @@ func NewSheet(file []FileList, index int, name string) []FileList {
}
// Read and update property of contents type of XLSX
func
setContentTypes
(
file
[]
FileList
,
index
int
)
[]
FileList
{
func
setContentTypes
(
file
map
[
string
]
string
,
index
int
)
map
[
string
]
string
{
var
content
xlsxTypes
xml
.
Unmarshal
([]
byte
(
readXML
(
file
,
`[Content_Types].xml`
)),
&
content
)
content
.
Overrides
=
append
(
content
.
Overrides
,
xlsxOverride
{
...
...
@@ -41,7 +41,7 @@ func setContentTypes(file []FileList, index int) []FileList {
}
// Update sheet property by given index
func
setSheet
(
file
[]
FileList
,
index
int
)
[]
FileList
{
func
setSheet
(
file
map
[
string
]
string
,
index
int
)
map
[
string
]
string
{
var
xlsx
xlsxWorksheet
xlsx
.
Dimension
.
Ref
=
"A1"
xlsx
.
SheetViews
.
SheetView
=
append
(
xlsx
.
SheetViews
.
SheetView
,
xlsxSheetView
{
...
...
@@ -56,7 +56,7 @@ func setSheet(file []FileList, index int) []FileList {
}
// Update workbook property of XLSX
func
setWorkbook
(
file
[]
FileList
,
index
int
,
name
string
)
[]
FileList
{
func
setWorkbook
(
file
map
[
string
]
string
,
index
int
,
name
string
)
map
[
string
]
string
{
var
content
xlsxWorkbook
xml
.
Unmarshal
([]
byte
(
readXML
(
file
,
`xl/workbook.xml`
)),
&
content
)
...
...
@@ -75,14 +75,14 @@ func setWorkbook(file []FileList, index int, name string) []FileList {
}
// Read and unmarshal workbook relationships of XLSX
func
readXlsxWorkbookRels
(
file
[]
FileList
)
xlsxWorkbookRels
{
func
readXlsxWorkbookRels
(
file
map
[
string
]
string
)
xlsxWorkbookRels
{
var
content
xlsxWorkbookRels
xml
.
Unmarshal
([]
byte
(
readXML
(
file
,
`xl/_rels/workbook.xml.rels`
)),
&
content
)
return
content
}
// Update workbook relationships property of XLSX
func
addXlsxWorkbookRels
(
file
[]
FileList
,
sheet
int
)
[]
FileList
{
func
addXlsxWorkbookRels
(
file
map
[
string
]
string
,
sheet
int
)
map
[
string
]
string
{
content
:=
readXlsxWorkbookRels
(
file
)
rID
:=
len
(
content
.
Relationships
)
+
1
ID
:=
bytes
.
Buffer
{}
...
...
@@ -105,7 +105,7 @@ func addXlsxWorkbookRels(file []FileList, sheet int) []FileList {
}
// Update docProps/app.xml file of XML
func
setAppXML
(
file
[]
FileList
)
[]
FileList
{
func
setAppXML
(
file
map
[
string
]
string
)
map
[
string
]
string
{
return
saveFileList
(
file
,
`docProps/app.xml`
,
templateDocpropsApp
)
}
...
...
@@ -134,7 +134,7 @@ func replaceRelationshipsID(workbookMarshal string) string {
}
// SetActiveSheet provide function to set default active sheet of XLSX by given index
func
SetActiveSheet
(
file
[]
FileList
,
index
int
)
[]
FileList
{
func
SetActiveSheet
(
file
map
[
string
]
string
,
index
int
)
map
[
string
]
string
{
var
content
xlsxWorkbook
if
index
<
1
{
index
=
1
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录