forked from p30928647/excelize
Bugfix: deep copy issue with function `CopySheet()`, relate PR #108.
This commit is contained in:
parent
77af25295e
commit
1ec2661dda
|
@ -682,6 +682,10 @@ func TestCopySheet(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
xlsx.SetCellValue("Sheet4", "F1", "Hello")
|
||||
if xlsx.GetCellValue("Sheet1", "F1") == "Hello" {
|
||||
t.Error("Invalid value \"Hello\" in Sheet1")
|
||||
}
|
||||
err = xlsx.Save()
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
|
|
12
lib.go
12
lib.go
|
@ -3,6 +3,7 @@ package excelize
|
|||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"io"
|
||||
"log"
|
||||
"math"
|
||||
|
@ -104,3 +105,14 @@ func intOnlyMapF(rune rune) rune {
|
|||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
// deepCopy provides method to creates a deep copy of whatever is passed to it
|
||||
// and returns the copy in an interface. The returned value will need to be
|
||||
// asserted to the correct type.
|
||||
func deepCopy(dst, src interface{}) error {
|
||||
var buf bytes.Buffer
|
||||
if err := gob.NewEncoder(&buf).Encode(src); err != nil {
|
||||
return err
|
||||
}
|
||||
return gob.NewDecoder(bytes.NewBuffer(buf.Bytes())).Decode(dst)
|
||||
}
|
||||
|
|
3
sheet.go
3
sheet.go
|
@ -435,7 +435,8 @@ func (f *File) CopySheet(from, to int) error {
|
|||
// target worksheet index.
|
||||
func (f *File) copySheet(from, to int) {
|
||||
sheet := f.workSheetReader("sheet" + strconv.Itoa(from))
|
||||
worksheet := *sheet
|
||||
worksheet := xlsxWorksheet{}
|
||||
deepCopy(&worksheet, &sheet)
|
||||
path := "xl/worksheets/sheet" + strconv.Itoa(to) + ".xml"
|
||||
if len(worksheet.SheetViews.SheetView) > 0 {
|
||||
worksheet.SheetViews.SheetView[0].TabSelected = false
|
||||
|
|
Loading…
Reference in New Issue