Update godoc of package.

This commit is contained in:
Ri Xu 2016-10-19 20:39:44 +08:00
parent e28de172c6
commit 75abc628fe
10 changed files with 29 additions and 29 deletions

View File

@ -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

View File

@ -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">`

View File

@ -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 {

12
lib.go
View File

@ -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':

View File

@ -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)

View File

@ -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">

View File

@ -1,4 +1,4 @@
// Some code of this file reference tealeg/xlsx
// Some code of this file reference tealeg/xlsx.
package excelize

View File

@ -1,4 +1,4 @@
// Some code of this file reference tealeg/xlsx
// Some code of this file reference tealeg/xlsx.
package excelize

View File

@ -1,4 +1,4 @@
// 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"`
}

View File

@ -1,4 +1,4 @@
// 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"`
}