Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
此号慢热型
excelize
提交
2e8fa2d3
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,发现更多精彩内容 >>
提交
2e8fa2d3
编写于
9月 12, 2016
作者:
xurime
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use conjunction with strings.Map to split Axis and update godoc.
上级
cbfd6577
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
34 addition
and
37 deletion
+34
-37
cell.go
cell.go
+1
-1
excelize.go
excelize.go
+8
-8
lib.go
lib.go
+18
-21
sheet.go
sheet.go
+4
-4
xmlWorkbook.go
xmlWorkbook.go
+3
-3
未找到文件。
cell.go
浏览文件 @
2e8fa2d3
...
@@ -10,7 +10,7 @@ import (
...
@@ -10,7 +10,7 @@ import (
func
(
f
*
File
)
GetCellValue
(
sheet
string
,
axis
string
)
string
{
func
(
f
*
File
)
GetCellValue
(
sheet
string
,
axis
string
)
string
{
axis
=
strings
.
ToUpper
(
axis
)
axis
=
strings
.
ToUpper
(
axis
)
var
xlsx
xlsxWorksheet
var
xlsx
xlsxWorksheet
row
:=
getRowIndex
(
axis
)
row
,
_
:=
strconv
.
Atoi
(
strings
.
Map
(
intOnlyMapF
,
axis
)
)
xAxis
:=
row
-
1
xAxis
:=
row
-
1
name
:=
`xl/worksheets/`
+
strings
.
ToLower
(
sheet
)
+
`.xml`
name
:=
`xl/worksheets/`
+
strings
.
ToLower
(
sheet
)
+
`.xml`
xml
.
Unmarshal
([]
byte
(
f
.
readXML
(
name
)),
&
xlsx
)
xml
.
Unmarshal
([]
byte
(
f
.
readXML
(
name
)),
&
xlsx
)
...
...
excelize.go
浏览文件 @
2e8fa2d3
...
@@ -52,8 +52,8 @@ func (f *File) SetCellValue(sheet string, axis string, value interface{}) {
...
@@ -52,8 +52,8 @@ func (f *File) SetCellValue(sheet string, axis string, value interface{}) {
func
(
f
*
File
)
SetCellInt
(
sheet
string
,
axis
string
,
value
int
)
{
func
(
f
*
File
)
SetCellInt
(
sheet
string
,
axis
string
,
value
int
)
{
axis
=
strings
.
ToUpper
(
axis
)
axis
=
strings
.
ToUpper
(
axis
)
var
xlsx
xlsxWorksheet
var
xlsx
xlsxWorksheet
col
:=
getColIndex
(
axis
)
col
:=
string
(
strings
.
Map
(
letterOnlyMapF
,
axis
)
)
row
:=
getRowIndex
(
axis
)
row
,
_
:=
strconv
.
Atoi
(
strings
.
Map
(
intOnlyMapF
,
axis
)
)
xAxis
:=
row
-
1
xAxis
:=
row
-
1
yAxis
:=
titleToNumber
(
col
)
yAxis
:=
titleToNumber
(
col
)
...
@@ -77,8 +77,8 @@ func (f *File) SetCellInt(sheet string, axis string, value int) {
...
@@ -77,8 +77,8 @@ func (f *File) SetCellInt(sheet string, axis string, value int) {
func
(
f
*
File
)
SetCellStr
(
sheet
string
,
axis
string
,
value
string
)
{
func
(
f
*
File
)
SetCellStr
(
sheet
string
,
axis
string
,
value
string
)
{
axis
=
strings
.
ToUpper
(
axis
)
axis
=
strings
.
ToUpper
(
axis
)
var
xlsx
xlsxWorksheet
var
xlsx
xlsxWorksheet
col
:=
getColIndex
(
axis
)
col
:=
string
(
strings
.
Map
(
letterOnlyMapF
,
axis
)
)
row
:=
getRowIndex
(
axis
)
row
,
_
:=
strconv
.
Atoi
(
strings
.
Map
(
intOnlyMapF
,
axis
)
)
xAxis
:=
row
-
1
xAxis
:=
row
-
1
yAxis
:=
titleToNumber
(
col
)
yAxis
:=
titleToNumber
(
col
)
...
@@ -196,8 +196,8 @@ func checkRow(xlsx xlsxWorksheet) xlsxWorksheet {
...
@@ -196,8 +196,8 @@ func checkRow(xlsx xlsxWorksheet) xlsxWorksheet {
if
lenCol
<
1
{
if
lenCol
<
1
{
continue
continue
}
}
endR
:=
getColIndex
(
v
.
C
[
lenCol
-
1
]
.
R
)
endR
:=
string
(
strings
.
Map
(
letterOnlyMapF
,
v
.
C
[
lenCol
-
1
]
.
R
)
)
endRow
:=
getRowIndex
(
v
.
C
[
lenCol
-
1
]
.
R
)
endRow
,
_
:=
strconv
.
Atoi
(
strings
.
Map
(
intOnlyMapF
,
v
.
C
[
lenCol
-
1
]
.
R
)
)
endCol
:=
titleToNumber
(
endR
)
+
1
endCol
:=
titleToNumber
(
endR
)
+
1
if
lenCol
<
endCol
{
if
lenCol
<
endCol
{
oldRow
:=
xlsx
.
SheetData
.
Row
[
k
]
.
C
oldRow
:=
xlsx
.
SheetData
.
Row
[
k
]
.
C
...
@@ -213,7 +213,7 @@ func checkRow(xlsx xlsxWorksheet) xlsxWorksheet {
...
@@ -213,7 +213,7 @@ func checkRow(xlsx xlsxWorksheet) xlsxWorksheet {
}
}
xlsx
.
SheetData
.
Row
[
k
]
.
C
=
tmp
xlsx
.
SheetData
.
Row
[
k
]
.
C
=
tmp
for
_
,
y
:=
range
oldRow
{
for
_
,
y
:=
range
oldRow
{
colAxis
:=
titleToNumber
(
getColIndex
(
y
.
R
))
colAxis
:=
titleToNumber
(
string
(
strings
.
Map
(
letterOnlyMapF
,
y
.
R
)
))
xlsx
.
SheetData
.
Row
[
k
]
.
C
[
colAxis
]
=
y
xlsx
.
SheetData
.
Row
[
k
]
.
C
[
colAxis
]
=
y
}
}
}
}
...
...
lib.go
浏览文件 @
2e8fa2d3
...
@@ -7,8 +7,6 @@ import (
...
@@ -7,8 +7,6 @@ import (
"io"
"io"
"log"
"log"
"math"
"math"
"regexp"
"strconv"
"strings"
"strings"
)
)
...
@@ -28,9 +26,9 @@ func ReadZipReader(r *zip.Reader) (map[string]string, int, error) {
...
@@ -28,9 +26,9 @@ func ReadZipReader(r *zip.Reader) (map[string]string, int, error) {
for
_
,
v
:=
range
r
.
File
{
for
_
,
v
:=
range
r
.
File
{
fileList
[
v
.
Name
]
=
readFile
(
v
)
fileList
[
v
.
Name
]
=
readFile
(
v
)
if
len
(
v
.
Name
)
>
18
{
if
len
(
v
.
Name
)
>
18
{
if
v
.
Name
[
0
:
19
]
==
"xl/worksheets/sheet"
{
if
v
.
Name
[
0
:
19
]
==
`xl/worksheets/sheet`
{
var
xlsx
xlsxWorksheet
var
xlsx
xlsxWorksheet
xml
.
Unmarshal
([]
byte
(
strings
.
Replace
(
fileList
[
v
.
Name
],
"<drawing r:id="
,
"<drawing rid="
,
-
1
)),
&
xlsx
)
xml
.
Unmarshal
([]
byte
(
strings
.
Replace
(
fileList
[
v
.
Name
],
`<drawing r:id=`
,
`<drawing rid=`
,
-
1
)),
&
xlsx
)
xlsx
=
checkRow
(
xlsx
)
xlsx
=
checkRow
(
xlsx
)
output
,
_
:=
xml
.
Marshal
(
xlsx
)
output
,
_
:=
xml
.
Marshal
(
xlsx
)
fileList
[
v
.
Name
]
=
replaceRelationshipsID
(
replaceWorkSheetsRelationshipsNameSpace
(
string
(
output
)))
fileList
[
v
.
Name
]
=
replaceRelationshipsID
(
replaceWorkSheetsRelationshipsNameSpace
(
string
(
output
)))
...
@@ -44,7 +42,7 @@ func ReadZipReader(r *zip.Reader) (map[string]string, int, error) {
...
@@ -44,7 +42,7 @@ func ReadZipReader(r *zip.Reader) (map[string]string, int, error) {
// Read XML content as string and replace drawing property in XML namespace of sheet
// Read XML content as string and replace drawing property in XML namespace of sheet
func
(
f
*
File
)
readXML
(
name
string
)
string
{
func
(
f
*
File
)
readXML
(
name
string
)
string
{
if
content
,
ok
:=
f
.
XLSX
[
name
];
ok
{
if
content
,
ok
:=
f
.
XLSX
[
name
];
ok
{
return
strings
.
Replace
(
content
,
"<drawing r:id="
,
"<drawing rid="
,
-
1
)
return
strings
.
Replace
(
content
,
`<drawing r:id=`
,
`<drawing rid=`
,
-
1
)
}
}
return
``
return
``
}
}
...
@@ -91,24 +89,23 @@ func titleToNumber(s string) int {
...
@@ -91,24 +89,23 @@ func titleToNumber(s string) int {
return
sum
-
1
return
sum
-
1
}
}
// Split Excel sheet column title to string and integer, return XAxis
// letterOnlyMapF is used in conjunction with strings.Map to return
func
getColIndex
(
axis
string
)
string
{
// only the characters A-Z and a-z in a string
r
,
err
:=
regexp
.
Compile
(
`[^\D]`
)
func
letterOnlyMapF
(
rune
rune
)
rune
{
if
err
!=
nil
{
switch
{
log
.
Fatal
(
err
)
case
'A'
<=
rune
&&
rune
<=
'Z'
:
return
rune
case
'a'
<=
rune
&&
rune
<=
'z'
:
return
rune
-
32
}
}
return
string
(
r
.
ReplaceAll
([]
byte
(
axis
),
[]
byte
(
""
)))
return
-
1
}
}
// Split Excel sheet column title to string and integer, return YAxis
// intOnlyMapF is used in conjunction with strings.Map to return only
func
getRowIndex
(
axis
string
)
int
{
// the numeric portions of a string.
r
,
err
:=
regexp
.
Compile
(
`[\D]`
)
func
intOnlyMapF
(
rune
rune
)
rune
{
if
err
!=
nil
{
if
rune
>=
48
&&
rune
<
58
{
log
.
Fatal
(
err
)
return
rune
}
row
,
err
:=
strconv
.
Atoi
(
string
(
r
.
ReplaceAll
([]
byte
(
axis
),
[]
byte
(
""
))))
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
}
return
row
return
-
1
}
}
sheet.go
浏览文件 @
2e8fa2d3
...
@@ -30,7 +30,7 @@ func (f *File) setContentTypes(index int) {
...
@@ -30,7 +30,7 @@ func (f *File) setContentTypes(index int) {
xml
.
Unmarshal
([]
byte
(
f
.
readXML
(
`[Content_Types].xml`
)),
&
content
)
xml
.
Unmarshal
([]
byte
(
f
.
readXML
(
`[Content_Types].xml`
)),
&
content
)
content
.
Overrides
=
append
(
content
.
Overrides
,
xlsxOverride
{
content
.
Overrides
=
append
(
content
.
Overrides
,
xlsxOverride
{
PartName
:
`/xl/worksheets/sheet`
+
strconv
.
Itoa
(
index
)
+
`.xml`
,
PartName
:
`/xl/worksheets/sheet`
+
strconv
.
Itoa
(
index
)
+
`.xml`
,
ContentType
:
"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"
,
ContentType
:
`application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml`
,
})
})
output
,
err
:=
xml
.
Marshal
(
content
)
output
,
err
:=
xml
.
Marshal
(
content
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -94,7 +94,7 @@ func (f *File) addXlsxWorkbookRels(sheet int) {
...
@@ -94,7 +94,7 @@ func (f *File) addXlsxWorkbookRels(sheet int) {
content
.
Relationships
=
append
(
content
.
Relationships
,
xlsxWorkbookRelation
{
content
.
Relationships
=
append
(
content
.
Relationships
,
xlsxWorkbookRelation
{
ID
:
ID
.
String
(),
ID
:
ID
.
String
(),
Target
:
target
.
String
(),
Target
:
target
.
String
(),
Type
:
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"
,
Type
:
`http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet`
,
})
})
output
,
err
:=
xml
.
Marshal
(
content
)
output
,
err
:=
xml
.
Marshal
(
content
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
xmlWorkbook.go
浏览文件 @
2e8fa2d3
...
@@ -9,9 +9,9 @@ import (
...
@@ -9,9 +9,9 @@ import (
const
(
const
(
// sheet state values as defined by
// sheet state values as defined by
// http://msdn.microsoft.com/en-us/library/office/documentformat.openxml.spreadsheet.sheetstatevalues.aspx
// http://msdn.microsoft.com/en-us/library/office/documentformat.openxml.spreadsheet.sheetstatevalues.aspx
sheetStateVisible
=
"visible"
sheetStateVisible
=
`visible`
sheetStateHidden
=
"hidden"
sheetStateHidden
=
`hidden`
sheetStateVeryHidden
=
"veryHidden"
sheetStateVeryHidden
=
`veryHidden`
)
)
// xmlxWorkbookRels contains xmlxWorkbookRelations
// xmlxWorkbookRels contains xmlxWorkbookRelations
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录