Преглед изворни кода

Format code with golint rules

Ri Xu пре 9 година
родитељ
комит
192af02a40
8 измењених фајлова са 59 додато и 60 уклоњено
  1. 3 3
      cell.go
  2. 6 5
      excelize.go
  3. 10 13
      file.go
  4. 4 4
      lib.go
  5. 20 20
      sheet.go
  6. 9 8
      templates.go
  7. 4 4
      xmlWorkbook.go
  8. 3 3
      xmlWorksheet.go

+ 3 - 3
cell.go

@@ -6,14 +6,14 @@ import (
 	"strings"
 )
 
-// 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 GetCellValue(file []FileList, sheet string, axis string) string {
 	axis = strings.ToUpper(axis)
 	var xlsx xlsxWorksheet
 	row := getRowIndex(axis)
 	xAxis := row - 1
 	name := `xl/worksheets/` + strings.ToLower(sheet) + `.xml`
-	xml.Unmarshal([]byte(readXml(file, name)), &xlsx)
+	xml.Unmarshal([]byte(readXML(file, name)), &xlsx)
 	rows := len(xlsx.SheetData.Row)
 	if rows <= xAxis {
 		return ``
@@ -26,7 +26,7 @@ func GetCellValue(file []FileList, sheet string, axis string) string {
 					shardStrings := xlsxSST{}
 					xlsxSI := 0
 					xlsxSI, _ = strconv.Atoi(v.V)
-					xml.Unmarshal([]byte(readXml(file, `xl/sharedStrings.xml`)), &shardStrings)
+					xml.Unmarshal([]byte(readXML(file, `xl/sharedStrings.xml`)), &shardStrings)
 					return shardStrings.SI[xlsxSI].T
 				case "str":
 					return v.V

+ 6 - 5
excelize.go

@@ -8,12 +8,13 @@ import (
 	"strings"
 )
 
+// FileList define a populated xlsx.File struct.
 type FileList struct {
 	Key   string
 	Value string
 }
 
-// OpenFile() take the name of an XLSX file and returns a populated
+// 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) {
 	var f *zip.ReadCloser
@@ -25,7 +26,7 @@ func OpenFile(filename string) (file []FileList, err error) {
 	return
 }
 
-// Set int type value of a cell
+// SetCellInt provide function to set int type value of a cell
 func SetCellInt(file []FileList, sheet string, axis string, value int) []FileList {
 	axis = strings.ToUpper(axis)
 	var xlsx xlsxWorksheet
@@ -35,7 +36,7 @@ func SetCellInt(file []FileList, sheet string, axis string, value int) []FileLis
 	yAxis := titleToNumber(col)
 
 	name := `xl/worksheets/` + strings.ToLower(sheet) + `.xml`
-	xml.Unmarshal([]byte(readXml(file, name)), &xlsx)
+	xml.Unmarshal([]byte(readXML(file, name)), &xlsx)
 
 	rows := xAxis + 1
 	cell := yAxis + 1
@@ -56,7 +57,7 @@ func SetCellInt(file []FileList, sheet string, axis string, value int) []FileLis
 	return file
 }
 
-// Set string type value of a cell
+// SetCellStr provide function to set string type value of a cell
 func SetCellStr(file []FileList, sheet string, axis string, value string) []FileList {
 	axis = strings.ToUpper(axis)
 	var xlsx xlsxWorksheet
@@ -66,7 +67,7 @@ func SetCellStr(file []FileList, sheet string, axis string, value string) []File
 	yAxis := titleToNumber(col)
 
 	name := `xl/worksheets/` + strings.ToLower(sheet) + `.xml`
-	xml.Unmarshal([]byte(readXml(file, name)), &xlsx)
+	xml.Unmarshal([]byte(readXML(file, name)), &xlsx)
 
 	rows := xAxis + 1
 	cell := yAxis + 1

+ 10 - 13
file.go

@@ -6,23 +6,20 @@ import (
 	"os"
 )
 
-// Create a new xlsx file
-//
+// CreateFile provide function to create new file by default template
 // For example:
-//
 // xlsx := CreateFile()
-//
 func CreateFile() []FileList {
 	var file []FileList
-	file = saveFileList(file, `_rels/.rels`, TEMPLATE_RELS)
-	file = saveFileList(file, `docProps/app.xml`, TEMPLATE_DOCPROPS_APP)
-	file = saveFileList(file, `docProps/core.xml`, TEMPLATE_DOCPROPS_CORE)
-	file = saveFileList(file, `xl/_rels/workbook.xml.rels`, TEMPLATE_WORKBOOK_RELS)
-	file = saveFileList(file, `xl/theme/theme1.xml`, TEMPLATE_THEME)
-	file = saveFileList(file, `xl/worksheets/sheet1.xml`, TEMPLATE_SHEET)
-	file = saveFileList(file, `xl/styles.xml`, TEMPLATE_STYLES)
-	file = saveFileList(file, `xl/workbook.xml`, TEMPLATE_WORKBOOK)
-	file = saveFileList(file, `[Content_Types].xml`, TEMPLATE_CONTENT_TYPES)
+	file = saveFileList(file, `_rels/.rels`, templateRels)
+	file = saveFileList(file, `docProps/app.xml`, templateDocpropsApp)
+	file = saveFileList(file, `docProps/core.xml`, templateDocpropsCore)
+	file = saveFileList(file, `xl/_rels/workbook.xml.rels`, templateWorkbookRels)
+	file = saveFileList(file, `xl/theme/theme1.xml`, templateTheme)
+	file = saveFileList(file, `xl/worksheets/sheet1.xml`, templateSheet)
+	file = saveFileList(file, `xl/styles.xml`, templateStyles)
+	file = saveFileList(file, `xl/workbook.xml`, templateWorkbook)
+	file = saveFileList(file, `[Content_Types].xml`, templateContentTypes)
 	return file
 }
 

+ 4 - 4
lib.go

@@ -11,15 +11,15 @@ import (
 	"strings"
 )
 
-// ReadZip() takes a pointer to a zip.ReadCloser and returns a
-// xlsx.File struct populated with its contents.  In most cases
+// 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) {
 	defer f.Close()
 	return ReadZipReader(&f.Reader)
 }
 
-// ReadZipReader() can be used to read an XLSX in memory without
+// ReadZipReader can be used to read an XLSX in memory without
 // touching the filesystem.
 func ReadZipReader(r *zip.Reader) ([]FileList, error) {
 	var fileList []FileList
@@ -34,7 +34,7 @@ func ReadZipReader(r *zip.Reader) ([]FileList, error) {
 }
 
 // Read XML content as string and replace drawing property in XML namespace of sheet
-func readXml(files []FileList, name string) string {
+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)

+ 20 - 20
sheet.go

@@ -7,12 +7,12 @@ import (
 	"strings"
 )
 
-// Create 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.
+// 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 {
 	// Update docProps/app.xml
-	file = setAppXml(file)
+	file = setAppXML(file)
 	// Update [Content_Types].xml
 	file = setContentTypes(file, index)
 	// Create new sheet /xl/worksheets/sheet%d.xml
@@ -27,7 +27,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 {
 	var content xlsxTypes
-	xml.Unmarshal([]byte(readXml(file, `[Content_Types].xml`)), &content)
+	xml.Unmarshal([]byte(readXML(file, `[Content_Types].xml`)), &content)
 	content.Overrides = append(content.Overrides, xlsxOverride{
 		PartName:    `/xl/worksheets/sheet` + strconv.Itoa(index) + `.xml`,
 		ContentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",
@@ -44,7 +44,7 @@ func setSheet(file []FileList, index int) []FileList {
 	var xlsx xlsxWorksheet
 	xlsx.Dimension.Ref = "A1"
 	xlsx.SheetViews.SheetView = append(xlsx.SheetViews.SheetView, xlsxSheetView{
-		WorkbookViewId: 0,
+		WorkbookViewID: 0,
 	})
 	output, err := xml.MarshalIndent(xlsx, "", "")
 	if err != nil {
@@ -57,14 +57,14 @@ func setSheet(file []FileList, index int) []FileList {
 // Update workbook property of XLSX
 func setWorkbook(file []FileList, index int, name string) []FileList {
 	var content xlsxWorkbook
-	xml.Unmarshal([]byte(readXml(file, `xl/workbook.xml`)), &content)
+	xml.Unmarshal([]byte(readXML(file, `xl/workbook.xml`)), &content)
 
 	rels := readXlsxWorkbookRels(file)
-	rId := len(rels.Relationships)
+	rID := len(rels.Relationships)
 	content.Sheets.Sheet = append(content.Sheets.Sheet, xlsxSheet{
 		Name:    name,
-		SheetId: strconv.Itoa(index),
-		Id:      "rId" + strconv.Itoa(rId),
+		SheetID: strconv.Itoa(index),
+		ID:      "rId" + strconv.Itoa(rID),
 	})
 	output, err := xml.MarshalIndent(content, "", "")
 	if err != nil {
@@ -76,16 +76,16 @@ func setWorkbook(file []FileList, index int, name string) []FileList {
 // Read and unmarshal workbook relationships of XLSX
 func readXlsxWorkbookRels(file []FileList) xlsxWorkbookRels {
 	var content xlsxWorkbookRels
-	xml.Unmarshal([]byte(readXml(file, `xl/_rels/workbook.xml.rels`)), &content)
+	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 {
 	content := readXlsxWorkbookRels(file)
-	rId := len(content.Relationships) + 1
+	rID := len(content.Relationships) + 1
 	content.Relationships = append(content.Relationships, xlsxWorkbookRelation{
-		Id:     "rId" + strconv.Itoa(rId),
+		ID:     "rId" + strconv.Itoa(rID),
 		Target: `worksheets/sheet` + strconv.Itoa(sheet) + `.xml`,
 		Type:   "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet",
 	})
@@ -97,8 +97,8 @@ func addXlsxWorkbookRels(file []FileList, sheet int) []FileList {
 }
 
 // Update docProps/app.xml file of XML
-func setAppXml(file []FileList) []FileList {
-	return saveFileList(file, `docProps/app.xml`, TEMPLATE_DOCPROPS_APP)
+func setAppXML(file []FileList) []FileList {
+	return saveFileList(file, `docProps/app.xml`, templateDocpropsApp)
 }
 
 // Some tools that read XLSX files have very strict requirements about
@@ -125,14 +125,14 @@ func replaceRelationshipsID(workbookMarshal string) string {
 	return strings.Replace(rids, `<drawing rid="`, `<drawing r:id="`, -1)
 }
 
-// Set default active sheet of XLSX by given index
+// SetActiveSheet provide function to set default active sheet of XLSX by given index
 func SetActiveSheet(file []FileList, index int) []FileList {
 	var content xlsxWorkbook
 	if index < 1 {
 		index = 1
 	}
-	index -= 1
-	xml.Unmarshal([]byte(readXml(file, `xl/workbook.xml`)), &content)
+	index--
+	xml.Unmarshal([]byte(readXML(file, `xl/workbook.xml`)), &content)
 	if len(content.BookViews.WorkBookView) > 0 {
 		content.BookViews.WorkBookView[0].ActiveTab = index
 	} else {
@@ -146,12 +146,12 @@ func SetActiveSheet(file []FileList, index int) []FileList {
 		fmt.Println(err)
 	}
 	file = saveFileList(file, `xl/workbook.xml`, workBookCompatibility(replaceRelationshipsNameSpace(string(output))))
-	index += 1
+	index++
 	for i := 0; i < sheets; i++ {
 		xlsx := xlsxWorksheet{}
 		sheetIndex := i + 1
 		path := `xl/worksheets/sheet` + strconv.Itoa(sheetIndex) + `.xml`
-		xml.Unmarshal([]byte(readXml(file, path)), &xlsx)
+		xml.Unmarshal([]byte(readXML(file, path)), &xlsx)
 		if index == sheetIndex {
 			if len(xlsx.SheetViews.SheetView) > 0 {
 				xlsx.SheetViews.SheetView[0].TabSelected = true

Разлика између датотеке није приказан због своје велике величине
+ 9 - 8
templates.go


+ 4 - 4
xmlWorkbook.go

@@ -23,7 +23,7 @@ type xlsxWorkbookRels struct {
 
 // xmlxWorkbookRelation maps sheet id and xl/worksheets/sheet%d.xml
 type xlsxWorkbookRelation struct {
-	Id     string `xml:",attr"`
+	ID     string `xml:"Id,attr"`
 	Target string `xml:",attr"`
 	Type   string `xml:",attr"`
 }
@@ -118,8 +118,8 @@ type xlsxSheets struct {
 // as I need.
 type xlsxSheet struct {
 	Name    string `xml:"name,attr,omitempty"`
-	SheetId string `xml:"sheetId,attr,omitempty"`
-	Id      string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
+	SheetID string `xml:"sheetId,attr,omitempty"`
+	ID      string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
 	State   string `xml:"state,attr,omitempty"`
 }
 
@@ -161,7 +161,7 @@ type xlsxDefinedName struct {
 // currently I have not checked it for completeness - it does as much
 // as I need.
 type xlsxCalcPr struct {
-	CalcId       string  `xml:"calcId,attr,omitempty"`
+	CalcID       string  `xml:"calcId,attr,omitempty"`
 	IterateCount int     `xml:"iterateCount,attr,omitempty"`
 	RefMode      string  `xml:"refMode,attr,omitempty"`
 	Iterate      bool    `xml:"iterate,attr,omitempty"`

+ 3 - 3
xmlWorksheet.go

@@ -28,7 +28,7 @@ type xlsxWorksheet struct {
 
 // xlsxDrawing change r:id to rid in the namespace
 type xlsxDrawing struct {
-	RId string `xml:"rid,attr"`
+	RID string `xml:"rid,attr"`
 }
 
 // xlsxHeaderFooter directly maps the headerFooter element in the namespace
@@ -144,7 +144,7 @@ type xlsxSheetView struct {
 	// ZoomScale               float64         `xml:"zoomScale,attr"`
 	// ZoomScaleNormal         float64         `xml:"zoomScaleNormal,attr"`
 	// ZoomScalePageLayoutView float64         `xml:"zoomScalePageLayoutView,attr"`
-	WorkbookViewId int             `xml:"workbookViewId,attr"`
+	WorkbookViewID int             `xml:"workbookViewId,attr"`
 	Selection      []xlsxSelection `xml:"selection"`
 	Pane           *xlsxPane       `xml:"pane,omitempty"`
 }
@@ -156,7 +156,7 @@ type xlsxSheetView struct {
 type xlsxSelection struct {
 	Pane         string `xml:"pane,attr,omitempty"`
 	ActiveCell   string `xml:"activeCell,attr"`
-	ActiveCellId int    `xml:"activeCellId,attr"`
+	ActiveCellID int    `xml:"activeCellId,attr"`
 	SQRef        string `xml:"sqref,attr"`
 }
 

Неке датотеке нису приказане због велике количине промена