Skip to content

Commit

Permalink
Add ability to delete named range
Browse files Browse the repository at this point in the history
  • Loading branch information
asardak committed May 21, 2018
1 parent c31fae4 commit b27ebfc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 15 additions & 1 deletion defined_names.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ func (f *File) AddDefinedName(sheet, begin, end, name string) {
endCol, endRow := getCellColRow(end)
r.DefinedNames.DefinedName = append(r.DefinedNames.DefinedName, xlsxDefinedName{
Name: name,
Data: fmt.Sprintf("%s!$%s$%s:$%s$%s", sheet, beginCol, beginRow, endCol, endRow),
Data: fmt.Sprintf("'%s'!$%s$%s:$%s$%s", sheet, beginCol, beginRow, endCol, endRow),
})
}

func (f *File) DeleteDefinedName(name string) {
r := f.workbookReader()
if r.DefinedNames == nil {
r.DefinedNames = &xlsxDefinedNames{}
}

for i := 0; i < len(r.DefinedNames.DefinedName); i++ {
if r.DefinedNames.DefinedName[i].Name == name {
r.DefinedNames.DefinedName = append(r.DefinedNames.DefinedName[:i], r.DefinedNames.DefinedName[i+1:]...)
return
}
}
}
4 changes: 4 additions & 0 deletions excelize.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ func (f *File) setDefaultTimeStyle(sheet, axis string, format int) {
}
}

func (f *File) GetWorkSheetReader(sheet string) *xlsxWorksheet {
return f.workSheetReader(sheet)
}

// workSheetReader provides function to get the pointer to the structure after
// deserialization by given worksheet name.
func (f *File) workSheetReader(sheet string) *xlsxWorksheet {
Expand Down

0 comments on commit b27ebfc

Please sign in to comment.