• R/O
  • HTTP
  • SSH
  • HTTPS

excelize: 提交

Go language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets


Commit MetaInfo

修订版1ec2661dda1ef16f58b2a3d614b11a2bcd0a2f2f (tree)
时间2017-08-19 14:37:15
作者Ri Xu <xuri.me@gmai...>
CommiterRi Xu

Log Message

Bugfix: deep copy issue with function CopySheet(), relate PR #108.

更改概述

差异

--- a/excelize_test.go
+++ b/excelize_test.go
@@ -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)
--- a/lib.go
+++ b/lib.go
@@ -3,6 +3,7 @@ package excelize
33 import (
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+}
--- a/sheet.go
+++ b/sheet.go
@@ -435,7 +435,8 @@ func (f *File) CopySheet(from, to int) error {
435435 // target worksheet index.
436436 func (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
Show on old repository browser