Skip to content

Commit 52796f6

Browse files
committed
Format commants, break comments after 80 characters.
1 parent f05df2a commit 52796f6

14 files changed

+342
-346
lines changed

cell.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"strings"
77
)
88

9-
// GetCellValue provide function get value from cell by given sheet index and axis in XLSX file.
10-
// The value of the merged cell is not available currently.
9+
// GetCellValue provide function get value from cell by given sheet index and
10+
// axis in XLSX file. The value of the merged cell is not available currently.
1111
func (f *File) GetCellValue(sheet string, axis string) string {
1212
axis = strings.ToUpper(axis)
1313
var xlsx xlsxWorksheet
@@ -50,7 +50,8 @@ func (f *File) GetCellValue(sheet string, axis string) string {
5050
return ""
5151
}
5252

53-
// GetCellFormula provide function get formula from cell by given sheet index and axis in XLSX file.
53+
// GetCellFormula provide function get formula from cell by given sheet index
54+
// and axis in XLSX file.
5455
func (f *File) GetCellFormula(sheet string, axis string) string {
5556
axis = strings.ToUpper(axis)
5657
var xlsx xlsxWorksheet

col.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"strings"
66
)
77

8-
// SetColWidth provides function to set the width of a single column or multiple columns.
9-
// For example:
8+
// SetColWidth provides function to set the width of a single column or multiple
9+
// columns. For example:
1010
//
1111
// xlsx := excelize.CreateFile()
1212
// xlsx.SetColWidth("Sheet1", "A", "H", 20)

excelize.go

+12-8
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import (
88
"strings"
99
)
1010

11-
// File define a populated xlsx.File struct.
11+
// File define a populated XLSX file struct.
1212
type File struct {
1313
XLSX map[string]string
1414
Path string
1515
SheetCount int
1616
}
1717

18-
// OpenFile take the name of an XLSX file and returns a populated
19-
// xlsx.File struct for it.
18+
// OpenFile take the name of an XLSX file and returns a populated XLSX file
19+
// struct for it.
2020
func OpenFile(filename string) (*File, error) {
2121
var f *zip.ReadCloser
2222
var err error
@@ -110,7 +110,8 @@ func (f *File) SetCellStr(sheet string, axis string, value string) {
110110
f.saveFileList(name, replaceWorkSheetsRelationshipsNameSpace(string(output)))
111111
}
112112

113-
// SetCellDefault provides function to set string type value of a cell as default format without escaping the cell.
113+
// SetCellDefault provides function to set string type value of a cell as
114+
// default format without escaping the cell.
114115
func (f *File) SetCellDefault(sheet string, axis string, value string) {
115116
axis = strings.ToUpper(axis)
116117
var xlsx xlsxWorksheet
@@ -203,15 +204,16 @@ func completeRow(xlsx xlsxWorksheet, row int, cell int) xlsxWorksheet {
203204
return xlsx
204205
}
205206

206-
// Replace xl/worksheets/sheet%d.xml XML tags to self-closing for compatible Office Excel 2007.
207+
// Replace xl/worksheets/sheet%d.xml XML tags to self-closing for compatible
208+
// Office Excel 2007.
207209
func replaceWorkSheetsRelationshipsNameSpace(workbookMarshal string) string {
208210
oldXmlns := `<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">`
209211
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">`
210212
workbookMarshal = strings.Replace(workbookMarshal, oldXmlns, newXmlns, -1)
211213
return workbookMarshal
212214
}
213215

214-
// Check XML tags and fix discontinuous case, for example:
216+
// Check XML tags and fix discontinuous case. For example:
215217
//
216218
// <row r="15" spans="1:22" x14ac:dyDescent="0.2">
217219
// <c r="A15" s="2" />
@@ -232,7 +234,8 @@ func replaceWorkSheetsRelationshipsNameSpace(workbookMarshal string) string {
232234
// <c r="G15" s="1" />
233235
// </row>
234236
//
235-
// Noteice: this method could be very slow for large spreadsheets (more than 3000 rows one sheet).
237+
// Noteice: this method could be very slow for large spreadsheets (more than
238+
// 3000 rows one sheet).
236239
func checkRow(xlsx xlsxWorksheet) xlsxWorksheet {
237240
buffer := bytes.Buffer{}
238241
for k, v := range xlsx.SheetData.Row {
@@ -267,7 +270,8 @@ func checkRow(xlsx xlsxWorksheet) xlsxWorksheet {
267270

268271
// UpdateLinkedValue fix linked values within a spreadsheet are not updating in
269272
// Office Excel 2007 and 2010. This function will be remove value tag when met a
270-
// cell have a linked value. Reference https://social.technet.microsoft.com/Forums/office/en-US/e16bae1f-6a2c-4325-8013-e989a3479066/excel-2010-linked-cells-not-updating?forum=excel
273+
// cell have a linked value. Reference
274+
// https://social.technet.microsoft.com/Forums/office/en-US/e16bae1f-6a2c-4325-8013-e989a3479066/excel-2010-linked-cells-not-updating?forum=excel
271275
//
272276
// Notice: after open XLSX file Excel will be update linked value and generate
273277
// new value and will prompt save file or not.

excelize_test.go

+23-23
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,12 @@ func TestOpenFile(t *testing.T) {
112112
if err != nil {
113113
t.Log(err)
114114
}
115+
}
115116

117+
func TestBrokenFile(t *testing.T) {
116118
// Test write file with broken file struct.
117119
f2 := File{}
118-
err = f2.Save()
120+
err := f2.Save()
119121
if err != nil {
120122
t.Log(err)
121123
}
@@ -124,41 +126,39 @@ func TestOpenFile(t *testing.T) {
124126
if err != nil {
125127
t.Log(err)
126128
}
127-
}
128129

129-
func TestCreateFile(t *testing.T) {
130-
// Test create a XLSX file.
131-
f3 := CreateFile()
132-
f3.NewSheet(2, "XLSXSheet2")
133-
f3.NewSheet(3, "XLSXSheet3")
134-
f3.SetCellInt("Sheet2", "A23", 56)
135-
f3.SetCellStr("SHEET1", "B20", "42")
136-
f3.SetActiveSheet(0)
137-
// Test add picture to sheet.
138-
err := f3.AddPicture("Sheet1", "H2", "K12", "./test/images/excel.gif")
130+
// Test set active sheet without BookViews and Sheets maps in xl/workbook.xml.
131+
f3, err := OpenFile("./test/badWorkbook.xlsx")
132+
f3.SetActiveSheet(2)
139133
if err != nil {
140134
t.Log(err)
141135
}
142-
err = f3.AddPicture("Sheet1", "C2", "F12", "./test/images/excel.tif")
136+
137+
// Test open a XLSX file with given illegal path.
138+
_, err = OpenFile("./test/Workbook.xlsx")
143139
if err != nil {
144140
t.Log(err)
145141
}
146-
err = f3.WriteTo("./test/Workbook_3.xlsx")
142+
}
143+
144+
func TestCreateFile(t *testing.T) {
145+
// Test create a XLSX file.
146+
f4 := CreateFile()
147+
f4.NewSheet(2, "XLSXSheet2")
148+
f4.NewSheet(3, "XLSXSheet3")
149+
f4.SetCellInt("Sheet2", "A23", 56)
150+
f4.SetCellStr("SHEET1", "B20", "42")
151+
f4.SetActiveSheet(0)
152+
// Test add picture to sheet.
153+
err := f4.AddPicture("Sheet1", "H2", "K12", "./test/images/excel.gif")
147154
if err != nil {
148155
t.Log(err)
149156
}
150-
}
151-
152-
func TestBrokenFile(t *testing.T) {
153-
// Test set active sheet without BookViews and Sheets maps in xl/workbook.xml.
154-
f4, err := OpenFile("./test/badWorkbook.xlsx")
155-
f4.SetActiveSheet(2)
157+
err = f4.AddPicture("Sheet1", "C2", "F12", "./test/images/excel.tif")
156158
if err != nil {
157159
t.Log(err)
158160
}
159-
160-
// Test open a XLSX file with given illegal path.
161-
_, err = OpenFile("./test/Workbook.xlsx")
161+
err = f4.WriteTo("./test/Workbook_3.xlsx")
162162
if err != nil {
163163
t.Log(err)
164164
}

file.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import (
66
"os"
77
)
88

9-
// CreateFile provide function to create new file by default template.
10-
// For example:
11-
// xlsx := CreateFile()
9+
// CreateFile provides function to create new file by default template. For
10+
// example:
11+
//
12+
// xlsx := CreateFile()
13+
//
1214
func CreateFile() *File {
1315
file := make(map[string]string)
1416
file["_rels/.rels"] = templateRels
@@ -25,7 +27,7 @@ func CreateFile() *File {
2527
}
2628
}
2729

28-
// Save provide function override the xlsx file with origin path.
30+
// Save provides function override the xlsx file with origin path.
2931
func (f *File) Save() error {
3032
buf := new(bytes.Buffer)
3133
w := zip.NewWriter(buf)
@@ -51,7 +53,8 @@ func (f *File) Save() error {
5153
return err
5254
}
5355

54-
// WriteTo provide function create or update to an xlsx file at the provided path.
56+
// WriteTo provides function to create or update to an xlsx file at the provided
57+
// path.
5558
func (f *File) WriteTo(name string) error {
5659
buf := new(bytes.Buffer)
5760
w := zip.NewWriter(buf)

lib.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import (
99
"math"
1010
)
1111

12-
// ReadZip takes a pointer to a zip.ReadCloser and returns a
13-
// xlsx.File struct populated with its contents. In most cases
14-
// ReadZip is not used directly, but is called internally by OpenFile.
12+
// ReadZip takes a pointer to a zip.ReadCloser and returns a xlsx.File struct
13+
// populated with its contents. In most cases ReadZip is not used directly, but
14+
// is called internally by OpenFile.
1515
func ReadZip(f *zip.ReadCloser) (map[string]string, int, error) {
1616
defer f.Close()
1717
return ReadZipReader(&f.Reader)
1818
}
1919

20-
// ReadZipReader can be used to read an XLSX in memory without
21-
// touching the filesystem.
20+
// ReadZipReader can be used to read an XLSX in memory without touching the
21+
// filesystem.
2222
func ReadZipReader(r *zip.Reader) (map[string]string, int, error) {
2323
fileList := make(map[string]string)
2424
worksheets := 0
@@ -88,8 +88,8 @@ func titleToNumber(s string) int {
8888
return sum - 1
8989
}
9090

91-
// letterOnlyMapF is used in conjunction with strings.Map to return
92-
// only the characters A-Z and a-z in a string.
91+
// letterOnlyMapF is used in conjunction with strings.Map to return only the
92+
// characters A-Z and a-z in a string.
9393
func letterOnlyMapF(rune rune) rune {
9494
switch {
9595
case 'A' <= rune && rune <= 'Z':
@@ -100,8 +100,8 @@ func letterOnlyMapF(rune rune) rune {
100100
return -1
101101
}
102102

103-
// intOnlyMapF is used in conjunction with strings.Map to return only
104-
// the numeric portions of a string.
103+
// intOnlyMapF is used in conjunction with strings.Map to return only the
104+
// numeric portions of a string.
105105
func intOnlyMapF(rune rune) rune {
106106
if rune >= 48 && rune < 58 {
107107
return rune

picture.go

+26-20
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
"strings"
1414
)
1515

16-
// AddPicture provide the method to add picture in a sheet by given xAxis, yAxis and file path.
17-
// For example:
16+
// AddPicture provide the method to add picture in a sheet by given xAxis, yAxis
17+
// and file path. For example:
1818
//
1919
// xlsx := excelize.CreateFile()
2020
// err := xlsx.AddPicture("Sheet1", "A2", "H9", "./image.jpg")
@@ -63,8 +63,9 @@ func (f *File) AddPicture(sheet string, xAxis string, yAxis string, picture stri
6363
return err
6464
}
6565

66-
// addSheetRelationships provides function to add xl/worksheets/_rels/sheet%d.xml.rels by given
67-
// sheet name, relationship type and target.
66+
// addSheetRelationships provides function to add
67+
// xl/worksheets/_rels/sheet%d.xml.rels by given sheet name, relationship type
68+
// and target.
6869
func (f *File) addSheetRelationships(sheet string, relType string, target string) int {
6970
var rels = "xl/worksheets/_rels/" + strings.ToLower(sheet) + ".xml.rels"
7071
var sheetRels xlsxWorkbookRels
@@ -93,8 +94,8 @@ func (f *File) addSheetRelationships(sheet string, relType string, target string
9394
return rID
9495
}
9596

96-
// addSheetDrawing provides function to add drawing element to xl/worksheets/sheet%d.xml by
97-
// given sheet name and relationship index.
97+
// addSheetDrawing provides function to add drawing element to
98+
// xl/worksheets/sheet%d.xml by given sheet name and relationship index.
9899
func (f *File) addSheetDrawing(sheet string, rID int) {
99100
var xlsx xlsxWorksheet
100101
name := "xl/worksheets/" + strings.ToLower(sheet) + ".xml"
@@ -109,7 +110,8 @@ func (f *File) addSheetDrawing(sheet string, rID int) {
109110
f.saveFileList(name, string(output))
110111
}
111112

112-
// countDrawings provides function to get drawing files count storage in the folder xl/drawings.
113+
// countDrawings provides function to get drawing files count storage in the
114+
// folder xl/drawings.
113115
func (f *File) countDrawings() int {
114116
count := 0
115117
for k := range f.XLSX {
@@ -120,10 +122,10 @@ func (f *File) countDrawings() int {
120122
return count
121123
}
122124

123-
// addDrawing provides function to add picture by given drawingXML, xAxis, yAxis, file name
124-
// and relationship index. In order to solve the problem that the label structure is changed
125-
// after serialization and deserialization, two different structures: decodeWsDr and encodeWsDr
126-
// are defined.
125+
// addDrawing provides function to add picture by given drawingXML, xAxis,
126+
// yAxis, file name and relationship index. In order to solve the problem that
127+
// the label structure is changed after serialization and deserialization, two
128+
// different structures: decodeWsDr and encodeWsDr are defined.
127129
func (f *File) addDrawing(drawingXML string, xAxis string, yAxis string, file string, rID int) {
128130
xAxis = strings.ToUpper(xAxis)
129131
fromCol := string(strings.Map(letterOnlyMapF, xAxis))
@@ -186,8 +188,9 @@ func (f *File) addDrawing(drawingXML string, xAxis string, yAxis string, file st
186188
f.saveFileList(drawingXML, result)
187189
}
188190

189-
// addDrawingRelationships provides function to add image part relationships in the file
190-
// xl/drawings/_rels/drawing%d.xml.rels by given drawing index, relationship type and target.
191+
// addDrawingRelationships provides function to add image part relationships in
192+
// the file xl/drawings/_rels/drawing%d.xml.rels by given drawing index,
193+
// relationship type and target.
191194
func (f *File) addDrawingRelationships(index int, relType string, target string) int {
192195
var rels = "xl/drawings/_rels/drawing" + strconv.Itoa(index) + ".xml.rels"
193196
var drawingRels xlsxWorkbookRels
@@ -216,7 +219,8 @@ func (f *File) addDrawingRelationships(index int, relType string, target string)
216219
return rID
217220
}
218221

219-
// countMedia provides function to get media files count storage in the folder xl/media/image.
222+
// countMedia provides function to get media files count storage in the folder
223+
// xl/media/image.
220224
func (f *File) countMedia() int {
221225
count := 0
222226
for k := range f.XLSX {
@@ -227,17 +231,18 @@ func (f *File) countMedia() int {
227231
return count
228232
}
229233

230-
// addMedia provides function to add picture into folder xl/media/image by given file
231-
// name and extension name.
234+
// addMedia provides function to add picture into folder xl/media/image by given
235+
// file name and extension name.
232236
func (f *File) addMedia(file string, ext string) {
233237
count := f.countMedia()
234238
dat, _ := ioutil.ReadFile(file)
235239
media := "xl/media/image" + strconv.Itoa(count+1) + ext
236240
f.XLSX[media] = string(dat)
237241
}
238242

239-
// addDrawingContentTypePart provides function to add image part relationships in
240-
// http://purl.oclc.org/ooxml/officeDocument/relationships/image and appropriate content type.
243+
// addDrawingContentTypePart provides function to add image part relationships
244+
// in http://purl.oclc.org/ooxml/officeDocument/relationships/image and
245+
// appropriate content type.
241246
func (f *File) addDrawingContentTypePart(index int) {
242247
var imageTypes = map[string]bool{"jpeg": false, "png": false, "gif": false, "tiff": false}
243248
var content xlsxTypes
@@ -271,8 +276,9 @@ func (f *File) addDrawingContentTypePart(index int) {
271276
f.saveFileList(`[Content_Types].xml`, string(output))
272277
}
273278

274-
// getSheetRelationshipsTargetByID provides function to get Target attribute value
275-
// in xl/worksheets/_rels/sheet%d.xml.rels by given sheet name and relationship index.
279+
// getSheetRelationshipsTargetByID provides function to get Target attribute
280+
// value in xl/worksheets/_rels/sheet%d.xml.rels by given sheet name and
281+
// relationship index.
276282
func (f *File) getSheetRelationshipsTargetByID(sheet string, rID string) string {
277283
var rels = "xl/worksheets/_rels/" + strings.ToLower(sheet) + ".xml.rels"
278284
var sheetRels xlsxWorkbookRels

rows.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ func readXMLSST(f *File) (xlsxSST, error) {
4343
return shardStrings, err
4444
}
4545

46-
// getValueFrom return a value from a column/row cell,
47-
// this function is inteded to be used with for range on rows
48-
// an argument with the xlsx opened file.
46+
// getValueFrom return a value from a column/row cell, this function is inteded
47+
// to be used with for range on rows an argument with the xlsx opened file.
4948
func (xlsx *xlsxC) getValueFrom(f *File) (string, error) {
5049
switch xlsx.T {
5150
case "s":

0 commit comments

Comments
 (0)