Skip to content

Commit b45c4b0

Browse files
committed
Add a check for maximum limit hyperlinks in a worksheet
typo fixed
1 parent 0660f30 commit b45c4b0

File tree

5 files changed

+472
-454
lines changed

5 files changed

+472
-454
lines changed

cell.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ func (f *File) GetCellHyperLink(sheet, axis string) (bool, string, error) {
336336
// SetCellHyperLink provides a function to set cell hyperlink by given
337337
// worksheet name and link URL address. LinkType defines two types of
338338
// hyperlink "External" for web site or "Location" for moving to one of cell
339-
// in this workbook. The below is example for external link.
339+
// in this workbook. Maximum limit hyperlinks in a worksheet is 65530. The
340+
// below is example for external link.
340341
//
341342
// err := f.SetCellHyperLink("Sheet1", "A3", "https://github.com/360EntSecGroup-Skylar/excelize", "External")
342343
// // Set underline and font color style for the cell.
@@ -364,6 +365,14 @@ func (f *File) SetCellHyperLink(sheet, axis, link, linkType string) error {
364365

365366
var linkData xlsxHyperlink
366367

368+
if xlsx.Hyperlinks == nil {
369+
xlsx.Hyperlinks = new(xlsxHyperlinks)
370+
}
371+
372+
if len(xlsx.Hyperlinks.Hyperlink) > 65529 {
373+
return errors.New("over maximum limit hyperlinks in a worksheet")
374+
}
375+
367376
switch linkType {
368377
case "External":
369378
linkData = xlsxHyperlink{
@@ -380,9 +389,6 @@ func (f *File) SetCellHyperLink(sheet, axis, link, linkType string) error {
380389
return fmt.Errorf("invalid link type %q", linkType)
381390
}
382391

383-
if xlsx.Hyperlinks == nil {
384-
xlsx.Hyperlinks = new(xlsxHyperlinks)
385-
}
386392
xlsx.Hyperlinks.Hyperlink = append(xlsx.Hyperlinks.Hyperlink, linkData)
387393
return nil
388394
}

chart.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -314,16 +314,20 @@ func parseFormatChartSet(formatSet string) (*formatChart, error) {
314314
// func main() {
315315
// categories := map[string]string{"A2": "Small", "A3": "Normal", "A4": "Large", "B1": "Apple", "C1": "Orange", "D1": "Pear"}
316316
// values := map[string]int{"B2": 2, "C2": 3, "D2": 3, "B3": 5, "C3": 2, "D3": 4, "B4": 6, "C4": 7, "D4": 8}
317-
// xlsx := excelize.NewFile()
317+
// f := excelize.NewFile()
318318
// for k, v := range categories {
319-
// xlsx.SetCellValue("Sheet1", k, v)
319+
// f.SetCellValue("Sheet1", k, v)
320320
// }
321321
// for k, v := range values {
322-
// xlsx.SetCellValue("Sheet1", k, v)
322+
// f.SetCellValue("Sheet1", k, v)
323+
// }
324+
// err := f.AddChart("Sheet1", "E1", `{"type":"col3DClustered","dimension":{"width":640,"height":480},"series":[{"name":"Sheet1!$A$2","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$2:$D$2"},{"name":"Sheet1!$A$3","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$3:$D$3"},{"name":"Sheet1!$A$4","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"}],"format":{"x_scale":1.0,"y_scale":1.0,"x_offset":15,"y_offset":10,"print_obj":true,"lock_aspect_ratio":false,"locked":false},"legend":{"position":"bottom","show_legend_key":false},"title":{"name":"Fruit 3D Clustered Column Chart"},"plotarea":{"show_bubble_size":true,"show_cat_name":false,"show_leader_lines":false,"show_percent":true,"show_series_name":true,"show_val":true},"show_blanks_as":"zero","x_axis":{"reverse_order":true},"y_axis":{"maximum":7.5,"minimum":0.5}}`)
325+
// if err != nil {
326+
// fmt.Println(err)
327+
// return
323328
// }
324-
// xlsx.AddChart("Sheet1", "E1", `{"type":"col3DClustered","dimension":{"width":640,"height":480},"series":[{"name":"Sheet1!$A$2","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$2:$D$2"},{"name":"Sheet1!$A$3","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$3:$D$3"},{"name":"Sheet1!$A$4","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"}],"format":{"x_scale":1.0,"y_scale":1.0,"x_offset":15,"y_offset":10,"print_obj":true,"lock_aspect_ratio":false,"locked":false},"legend":{"position":"bottom","show_legend_key":false},"title":{"name":"Fruit 3D Clustered Column Chart"},"plotarea":{"show_bubble_size":true,"show_cat_name":false,"show_leader_lines":false,"show_percent":true,"show_series_name":true,"show_val":true},"show_blanks_as":"zero","x_axis":{"reverse_order":true},"y_axis":{"maximum":7.5,"minimum":0.5}}`)
325329
// // Save xlsx file by the given path.
326-
// err := xlsx.SaveAs("./Book1.xlsx")
330+
// err = xlsx.SaveAs("./Book1.xlsx")
327331
// if err != nil {
328332
// fmt.Println(err)
329333
// }

comment.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (f *File) getSheetComments(sheetID int) string {
7272
// author length is 255 and the max text length is 32512. For example, add a
7373
// comment in Sheet1!$A$30:
7474
//
75-
// err := xlsx.AddComment("Sheet1", "A30", `{"author":"Excelize: ","text":"This is a comment."}`)
75+
// err := f.AddComment("Sheet1", "A30", `{"author":"Excelize: ","text":"This is a comment."}`)
7676
//
7777
func (f *File) AddComment(sheet, cell, format string) error {
7878
formatSet, err := parseFormatCommentsSet(format)

0 commit comments

Comments
 (0)