File tree Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -682,6 +682,10 @@ func TestCopySheet(t *testing.T) {
682682 if err != nil {
683683 t .Log (err )
684684 }
685+ xlsx .SetCellValue ("Sheet4" , "F1" , "Hello" )
686+ if xlsx .GetCellValue ("Sheet1" , "F1" ) == "Hello" {
687+ t .Error ("Invalid value \" Hello\" in Sheet1" )
688+ }
685689 err = xlsx .Save ()
686690 if err != nil {
687691 t .Log (err )
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package excelize
33import (
44 "archive/zip"
55 "bytes"
6+ "encoding/gob"
67 "io"
78 "log"
89 "math"
@@ -104,3 +105,14 @@ func intOnlyMapF(rune rune) rune {
104105 }
105106 return - 1
106107}
108+
109+ // deepCopy provides method to creates a deep copy of whatever is passed to it
110+ // and returns the copy in an interface. The returned value will need to be
111+ // asserted to the correct type.
112+ func deepCopy (dst , src interface {}) error {
113+ var buf bytes.Buffer
114+ if err := gob .NewEncoder (& buf ).Encode (src ); err != nil {
115+ return err
116+ }
117+ return gob .NewDecoder (bytes .NewBuffer (buf .Bytes ())).Decode (dst )
118+ }
Original file line number Diff line number Diff line change @@ -435,7 +435,8 @@ func (f *File) CopySheet(from, to int) error {
435435// target worksheet index.
436436func (f * File ) copySheet (from , to int ) {
437437 sheet := f .workSheetReader ("sheet" + strconv .Itoa (from ))
438- worksheet := * sheet
438+ worksheet := xlsxWorksheet {}
439+ deepCopy (& worksheet , & sheet )
439440 path := "xl/worksheets/sheet" + strconv .Itoa (to ) + ".xml"
440441 if len (worksheet .SheetViews .SheetView ) > 0 {
441442 worksheet .SheetViews .SheetView [0 ].TabSelected = false
You can’t perform that action at this time.
0 commit comments