Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xuri
excelize
提交
75abc628
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 搜索 >>
提交
75abc628
编写于
10月 19, 2016
作者:
xurime
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update godoc of package.
上级
e28de172
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
29 addition
and
29 deletion
+29
-29
cell.go
cell.go
+1
-1
excelize.go
excelize.go
+6
-6
file.go
file.go
+1
-1
lib.go
lib.go
+6
-6
sheet.go
sheet.go
+8
-8
templates.go
templates.go
+1
-1
xmlContentTypes.go
xmlContentTypes.go
+1
-1
xmlSharedStrings.go
xmlSharedStrings.go
+1
-1
xmlWorkbook.go
xmlWorkbook.go
+2
-2
xmlWorksheet.go
xmlWorksheet.go
+2
-2
未找到文件。
cell.go
浏览文件 @
75abc628
...
...
@@ -6,7 +6,7 @@ import (
"strings"
)
// GetCellValue provide function get value from cell by given sheet index and axis in XLSX file
// GetCellValue provide function get value from cell by given sheet index and axis in XLSX file
.
func
(
f
*
File
)
GetCellValue
(
sheet
string
,
axis
string
)
string
{
axis
=
strings
.
ToUpper
(
axis
)
var
xlsx
xlsxWorksheet
...
...
excelize.go
浏览文件 @
75abc628
...
...
@@ -34,7 +34,7 @@ func OpenFile(filename string) (*File, error) {
},
nil
}
// SetCellValue provide function to set int or string type value of a cell
// SetCellValue provide function to set int or string type value of a cell
.
func
(
f
*
File
)
SetCellValue
(
sheet
string
,
axis
string
,
value
interface
{})
{
switch
t
:=
value
.
(
type
)
{
case
int
,
int8
,
int16
,
int32
,
int64
,
float32
,
float64
:
...
...
@@ -48,7 +48,7 @@ func (f *File) SetCellValue(sheet string, axis string, value interface{}) {
}
}
// SetCellInt provide function to set int type value of a cell
// SetCellInt provide function to set int type value of a cell
.
func
(
f
*
File
)
SetCellInt
(
sheet
string
,
axis
string
,
value
int
)
{
axis
=
strings
.
ToUpper
(
axis
)
var
xlsx
xlsxWorksheet
...
...
@@ -73,7 +73,7 @@ func (f *File) SetCellInt(sheet string, axis string, value int) {
f
.
saveFileList
(
name
,
replaceRelationshipsID
(
replaceWorkSheetsRelationshipsNameSpace
(
string
(
output
))))
}
// SetCellStr provide function to set string type value of a cell
// SetCellStr provide function to set string type value of a cell
.
func
(
f
*
File
)
SetCellStr
(
sheet
string
,
axis
string
,
value
string
)
{
axis
=
strings
.
ToUpper
(
axis
)
var
xlsx
xlsxWorksheet
...
...
@@ -98,7 +98,7 @@ func (f *File) SetCellStr(sheet string, axis string, value string) {
f
.
saveFileList
(
name
,
replaceRelationshipsID
(
replaceWorkSheetsRelationshipsNameSpace
(
string
(
output
))))
}
// Completion column element tags of XML in a sheet
// Completion column element tags of XML in a sheet
.
func
completeCol
(
xlsx
xlsxWorksheet
,
row
int
,
cell
int
)
xlsxWorksheet
{
if
len
(
xlsx
.
SheetData
.
Row
)
<
cell
{
for
i
:=
len
(
xlsx
.
SheetData
.
Row
);
i
<
cell
;
i
++
{
...
...
@@ -124,7 +124,7 @@ func completeCol(xlsx xlsxWorksheet, row int, cell int) xlsxWorksheet {
return
xlsx
}
// Completion row element tags of XML in a sheet
// Completion row element tags of XML in a sheet
.
func
completeRow
(
xlsx
xlsxWorksheet
,
row
int
,
cell
int
)
xlsxWorksheet
{
if
len
(
xlsx
.
SheetData
.
Row
)
<
row
{
for
i
:=
len
(
xlsx
.
SheetData
.
Row
);
i
<
row
;
i
++
{
...
...
@@ -150,7 +150,7 @@ func completeRow(xlsx xlsxWorksheet, row int, cell int) xlsxWorksheet {
return
xlsx
}
// Replace xl/worksheets/sheet%d.xml XML tags to self-closing for compatible Office Excel 2007
// Replace xl/worksheets/sheet%d.xml XML tags to self-closing for compatible Office Excel 2007
.
func
replaceWorkSheetsRelationshipsNameSpace
(
workbookMarshal
string
)
string
{
oldXmlns
:=
`<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">`
newXmlns
:=
`<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mx="http://schemas.microsoft.com/office/mac/excel/2008/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="urn:schemas-microsoft-com:mac:vml" xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac" xmlns:xm="http://schemas.microsoft.com/office/excel/2006/main">`
...
...
file.go
浏览文件 @
75abc628
...
...
@@ -6,7 +6,7 @@ import (
"os"
)
// CreateFile provide function to create new file by default template
// CreateFile provide function to create new file by default template
.
// For example:
// xlsx := CreateFile()
func
CreateFile
()
*
File
{
...
...
lib.go
浏览文件 @
75abc628
...
...
@@ -39,7 +39,7 @@ func ReadZipReader(r *zip.Reader) (map[string]string, int, error) {
return
fileList
,
worksheets
,
nil
}
// 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
{
if
content
,
ok
:=
f
.
XLSX
[
name
];
ok
{
return
strings
.
Replace
(
content
,
`<drawing r:id=`
,
`<drawing rid=`
,
-
1
)
...
...
@@ -47,12 +47,12 @@ func (f *File) readXML(name string) string {
return
``
}
// Update given file content in file list of XLSX
// Update given file content in file list of XLSX
.
func
(
f
*
File
)
saveFileList
(
name
string
,
content
string
)
{
f
.
XLSX
[
name
]
=
XMLHeader
+
content
}
// Read file content as string in a archive file
// Read file content as string in a archive file
.
func
readFile
(
file
*
zip
.
File
)
string
{
rc
,
err
:=
file
.
Open
()
if
err
!=
nil
{
...
...
@@ -64,7 +64,7 @@ func readFile(file *zip.File) string {
return
string
(
buff
.
Bytes
())
}
// Convert integer to Excel sheet column title
// Convert integer to Excel sheet column title
.
func
toAlphaString
(
value
int
)
string
{
if
value
<
0
{
return
``
...
...
@@ -78,7 +78,7 @@ func toAlphaString(value int) string {
return
ans
}
// Convert Excel sheet column title to int
// Convert Excel sheet column title to int
.
func
titleToNumber
(
s
string
)
int
{
weight
:=
0.0
sum
:=
0
...
...
@@ -90,7 +90,7 @@ func titleToNumber(s string) int {
}
// letterOnlyMapF is used in conjunction with strings.Map to return
// only the characters A-Z and a-z in a string
// only the characters A-Z and a-z in a string
.
func
letterOnlyMapF
(
rune
rune
)
rune
{
switch
{
case
'A'
<=
rune
&&
rune
<=
'Z'
:
...
...
sheet.go
浏览文件 @
75abc628
...
...
@@ -24,7 +24,7 @@ func (f *File) NewSheet(index int, name string) {
f
.
setWorkbook
(
index
,
name
)
}
// Read and update property of contents type of XLSX
// Read and update property of contents type of XLSX
.
func
(
f
*
File
)
setContentTypes
(
index
int
)
{
var
content
xlsxTypes
xml
.
Unmarshal
([]
byte
(
f
.
readXML
(
`[Content_Types].xml`
)),
&
content
)
...
...
@@ -39,7 +39,7 @@ func (f *File) setContentTypes(index int) {
f
.
saveFileList
(
`[Content_Types].xml`
,
string
(
output
))
}
// Update sheet property by given index
// Update sheet property by given index
.
func
(
f
*
File
)
setSheet
(
index
int
)
{
var
xlsx
xlsxWorksheet
xlsx
.
Dimension
.
Ref
=
"A1"
...
...
@@ -54,7 +54,7 @@ func (f *File) setSheet(index int) {
f
.
saveFileList
(
path
,
replaceRelationshipsID
(
replaceWorkSheetsRelationshipsNameSpace
(
string
(
output
))))
}
// Update workbook property of XLSX
// Update workbook property of XLSX
.
func
(
f
*
File
)
setWorkbook
(
index
int
,
name
string
)
{
var
content
xlsxWorkbook
xml
.
Unmarshal
([]
byte
(
f
.
readXML
(
`xl/workbook.xml`
)),
&
content
)
...
...
@@ -73,14 +73,14 @@ func (f *File) setWorkbook(index int, name string) {
f
.
saveFileList
(
`xl/workbook.xml`
,
replaceRelationshipsNameSpace
(
string
(
output
)))
}
// Read and unmarshal workbook relationships of XLSX
// Read and unmarshal workbook relationships of XLSX
.
func
(
f
*
File
)
readXlsxWorkbookRels
()
xlsxWorkbookRels
{
var
content
xlsxWorkbookRels
xml
.
Unmarshal
([]
byte
(
f
.
readXML
(
`xl/_rels/workbook.xml.rels`
)),
&
content
)
return
content
}
// Update workbook relationships property of XLSX
// Update workbook relationships property of XLSX
.
func
(
f
*
File
)
addXlsxWorkbookRels
(
sheet
int
)
{
content
:=
f
.
readXlsxWorkbookRels
()
rID
:=
len
(
content
.
Relationships
)
+
1
...
...
@@ -103,7 +103,7 @@ func (f *File) addXlsxWorkbookRels(sheet int) {
f
.
saveFileList
(
`xl/_rels/workbook.xml.rels`
,
string
(
output
))
}
// Update docProps/app.xml file of XML
// Update docProps/app.xml file of XML
.
func
(
f
*
File
)
setAppXML
()
{
f
.
saveFileList
(
`docProps/app.xml`
,
templateDocpropsApp
)
}
...
...
@@ -132,7 +132,7 @@ func replaceRelationshipsID(workbookMarshal string) string {
return
strings
.
Replace
(
rids
,
`<drawing rid="`
,
`<drawing r:id="`
,
-
1
)
}
// SetActiveSheet provide function to set default active sheet of XLSX by given index
// SetActiveSheet provide function to set default active sheet of XLSX by given index
.
func
(
f
*
File
)
SetActiveSheet
(
index
int
)
{
var
content
xlsxWorkbook
if
index
<
1
{
...
...
@@ -185,7 +185,7 @@ func (f *File) SetActiveSheet(index int) {
return
}
// Replace xl/workbook.xml XML tags to self-closing for compatible Office Excel 2007
// Replace xl/workbook.xml XML tags to self-closing for compatible Office Excel 2007
.
func
workBookCompatibility
(
workbookMarshal
string
)
string
{
workbookMarshal
=
strings
.
Replace
(
workbookMarshal
,
`xmlns:relationships="http://schemas.openxmlformats.org/officeDocument/2006/relationships" relationships:id="`
,
`r:id="`
,
-
1
)
workbookMarshal
=
strings
.
Replace
(
workbookMarshal
,
`></sheet>`
,
` />`
,
-
1
)
...
...
templates.go
浏览文件 @
75abc628
...
...
@@ -3,7 +3,7 @@
package
excelize
// XMLHeader define an XML declaration can also contain a standalone declaration
// XMLHeader define an XML declaration can also contain a standalone declaration
.
const
XMLHeader
=
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
standalone=
\"
yes
\"
?>
\n
"
const
templateDocpropsApp
=
`<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
...
...
xmlContentTypes.go
浏览文件 @
75abc628
// Some code of this file reference tealeg/xlsx
// Some code of this file reference tealeg/xlsx
.
package
excelize
...
...
xmlSharedStrings.go
浏览文件 @
75abc628
// Some code of this file reference tealeg/xlsx
// Some code of this file reference tealeg/xlsx
.
package
excelize
...
...
xmlWorkbook.go
浏览文件 @
75abc628
// Some code of this file reference tealeg/xlsx
// Some code of this file reference tealeg/xlsx
.
package
excelize
...
...
@@ -44,7 +44,7 @@ type xlsxWorkbook struct {
FileRecoveryPr
xlsxFileRecoveryPr
`xml:"fileRecoveryPr"`
}
// xlsxFileRecoveryPr maps sheet recovery information
// xlsxFileRecoveryPr maps sheet recovery information
.
type
xlsxFileRecoveryPr
struct
{
RepairLoad
int
`xml:"repairLoad,attr"`
}
...
...
xmlWorksheet.go
浏览文件 @
75abc628
// Some code of this file reference tealeg/xlsx
// Some code of this file reference tealeg/xlsx
.
package
excelize
...
...
@@ -26,7 +26,7 @@ type xlsxWorksheet struct {
Drawing
xlsxDrawing
`xml:"drawing"`
}
// xlsxDrawing change r:id to rid in the namespace
// xlsxDrawing change r:id to rid in the namespace
.
type
xlsxDrawing
struct
{
RID
string
`xml:"rid,attr"`
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录