Skip to content

Two meanings return in NewSheet(name string) int #714

@Charnnarong

Description

@Charnnarong

I would like to thank to all contributors for creating such a great library. It is tremendous help in my work. I have a minor issue here.

https://github.com/360EntSecGroup-Skylar/excelize/blob/520aa679f34bafbc00626151075b0b123eceb516/sheet.go#L36

The comment says Returns the number of sheets in the workbook (file) after appending the new sheet. However, the return number has two meanings.

  1. sheet count
  2. sheet index

For instance

// f *excelize.File
totolSheet := f.NewSheet("newSheetName")
log.Println("create new sheet: ", totolSheet, f.SheetCount)

output.
totalSheet is always one less than f.SheeetCount if "newSheetName" hasn't existed before (succeed in appending a new sheet).
Both are equal in case of "newSheetName" is already exist.

I faced the problem by reading the comment and wrote my code as
tempIndex := f.NewSheet(tempName) - 1
now, I have to change to
tempIndex := f.NewSheet(tempName)
which isn't quite having the same meaning with the function comment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions