File tree 3 files changed +18
-1
lines changed
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) {
682
682
if err != nil {
683
683
t .Log (err )
684
684
}
685
+ xlsx .SetCellValue ("Sheet4" , "F1" , "Hello" )
686
+ if xlsx .GetCellValue ("Sheet1" , "F1" ) == "Hello" {
687
+ t .Error ("Invalid value \" Hello\" in Sheet1" )
688
+ }
685
689
err = xlsx .Save ()
686
690
if err != nil {
687
691
t .Log (err )
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package excelize
3
3
import (
4
4
"archive/zip"
5
5
"bytes"
6
+ "encoding/gob"
6
7
"io"
7
8
"log"
8
9
"math"
@@ -104,3 +105,14 @@ func intOnlyMapF(rune rune) rune {
104
105
}
105
106
return - 1
106
107
}
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 {
435
435
// target worksheet index.
436
436
func (f * File ) copySheet (from , to int ) {
437
437
sheet := f .workSheetReader ("sheet" + strconv .Itoa (from ))
438
- worksheet := * sheet
438
+ worksheet := xlsxWorksheet {}
439
+ deepCopy (& worksheet , & sheet )
439
440
path := "xl/worksheets/sheet" + strconv .Itoa (to ) + ".xml"
440
441
if len (worksheet .SheetViews .SheetView ) > 0 {
441
442
worksheet .SheetViews .SheetView [0 ].TabSelected = false
You can’t perform that action at this time.
0 commit comments