Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

duplicate sheets #33

Closed
mhlo opened this issue Mar 28, 2017 · 3 comments
Closed

duplicate sheets #33

mhlo opened this issue Mar 28, 2017 · 3 comments
Labels
enhancement New feature or request

Comments

@mhlo
Copy link

mhlo commented Mar 28, 2017

Capability to duplicate a sheet, like PowerShell/excel's $wb.sheets.item(1).copy($wb.sheets.item(2)). Perhaps something like:

// sheet at index 1 already exists...
xlsx.NewSheet(2, "sheet2")
xlsx.CopySheet(1, 2)

@xuri xuri added the enhancement New feature or request label Mar 28, 2017
xuri added a commit that referenced this issue Apr 4, 2017
- Typo fixed;
- go test updated
@xuri xuri closed this as completed Apr 22, 2017
@muhrifqii
Copy link

@xuri in my case, copy sheet didn't work. I ran this using master branch on a526e90

n := "1"
last := f.NewSheet(n)
err := f.CopySheet(1, last)

above code will return error about wrong index. The actual excel only contain 1 sheet, but the value last returns 3.

when I ran this

n := "1"
last := f.NewSheet(n)
err := f.CopySheet(1, 2)

that will not return any error, but the sheets is not copied into newly created sheet. I will send the excel file via email if it have to.

@xuri
Copy link
Member

xuri commented Dec 22, 2019

Hi @muhrifqii, thanks for your feedback, you can send me the file with credential data masking. xuri.me[at]gmail.com

@xuri
Copy link
Member

xuri commented Dec 22, 2019

Hi @muhrifqii, I have fixed this issue. Please try to upgrade the library with the master branch code, and this bug fix will be published in the next release version. Also, we need to get the source worksheet index before copy to the target worksheet:

package main

import "github.com/xuri/excelize"

func main() {
	n := "1"
	f, err := excelize.OpenFile("blank.xlsx")
	if err != nil {
		panic(err)
	}
	last := f.NewSheet(n)
	if err := f.CopySheet(f.GetSheetIndex("Sheet2"), last); err != nil {
		panic(err)
	}
	f.SetActiveSheet(last)
	if err := f.SaveAs("./Book1.xlsx"); err != nil {
		panic(err)
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants