Skip to content

Commit

Permalink
spreadsheet: add support for setting the active sheet
Browse files Browse the repository at this point in the history
This is the tab that is initially selected when opening
a spreadsheet.
  • Loading branch information
tbaliance committed Sep 12, 2017
1 parent 58495a2 commit 1ff1b07
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions spreadsheet/workbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,26 @@ func (wb *Workbook) AddImage(i common.Image) (common.ImageRef, error) {
wb.wbRels.AddRelationship(fn, gooxml.ImageType)
return r, nil
}

// SetActiveSheet sets the active sheet which will be the tab displayed when the
// spreadsheet is initially opened.
func (wb *Workbook) SetActiveSheet(s Sheet) {
for i, st := range wb.xws {
if s.x == st {
wb.SetActiveSheetIndex(uint32(i))
}
}
}

// SetActiveSheetIndex sets the index of the active sheet (0-n) which will be
// the tab displayed when the spreadsheet is initially opened.
func (wb *Workbook) SetActiveSheetIndex(idx uint32) {
if wb.x.BookViews == nil {
wb.x.BookViews = sml.NewCT_BookViews()
}
if len(wb.x.BookViews.WorkbookView) == 0 {
wb.x.BookViews.WorkbookView = append(wb.x.BookViews.WorkbookView, sml.NewCT_BookView())
}

wb.x.BookViews.WorkbookView[0].ActiveTabAttr = gooxml.Uint32(idx)
}

0 comments on commit 1ff1b07

Please sign in to comment.