Created
January 6, 2020 17:23
-
-
Save mlh758/b486e4fe39badf5b2becf59062a00b82 to your computer and use it in GitHub Desktop.
Excel Delete SheetID Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/360EntSecGroup-Skylar/excelize/v2" | |
) | |
func main() { | |
xlsx := excelize.NewFile() | |
xlsx.SetSheetName("Sheet1", "First Sheet") | |
xlsx.NewSheet("Second Sheet") | |
xlsx.NewSheet("Third Sheet") | |
xlsx.NewSheet("Fourth Sheet") | |
xlsx.DeleteSheet("Third Sheet") | |
names := make([]string, 3) | |
for i := 1; i <= 3; i++ { | |
name := xlsx.GetSheetName(i) | |
names[i-1] = name | |
fmt.Printf("%d => %s\n", i, name) | |
} | |
for _, name := range names { | |
fmt.Printf("Index: %d, name: %s\n", xlsx.GetSheetIndex(name), name) | |
} | |
} |
Using GetSheetMap
would be a workaround for now but GetSheetMap
not being broken doesn't make GetSheetName
and GetSheetIndex
not broken.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use
GetSheetMap
instead of handle sheet index manuly: