Explorar o código

Fix missing `oneCellAnchor` element after add picture in some cases.

Ri Xu %!s(int64=8) %!d(string=hai) anos
pai
achega
109d8adae3
Modificáronse 4 ficheiros con 36 adicións e 42 borrados
  1. 8 2
      picture.go
  2. 9 23
      templates.go
  3. 10 9
      xmlDecodeDrawing.go
  4. 9 8
      xmlDrawing.go

+ 8 - 2
picture.go

@@ -212,14 +212,20 @@ func (f *File) addDrawing(sheet, drawingXML, cell, file string, width, height, r
 		decodeWsDr := decodeWsDr{}
 		xml.Unmarshal([]byte(f.readXML(drawingXML)), &decodeWsDr)
 		cNvPrID = len(decodeWsDr.TwoCellAnchor) + 1
+		for _, v := range decodeWsDr.OneCellAnchor {
+			content.WsDr.OneCellAnchor = append(content.WsDr.OneCellAnchor, &xlsxCellAnchor{
+				EditAs:       v.EditAs,
+				GraphicFrame: v.Content,
+			})
+		}
 		for _, v := range decodeWsDr.TwoCellAnchor {
-			content.WsDr.TwoCellAnchor = append(content.WsDr.TwoCellAnchor, &xlsxTwoCellAnchor{
+			content.WsDr.TwoCellAnchor = append(content.WsDr.TwoCellAnchor, &xlsxCellAnchor{
 				EditAs:       v.EditAs,
 				GraphicFrame: v.Content,
 			})
 		}
 	}
-	twoCellAnchor := xlsxTwoCellAnchor{}
+	twoCellAnchor := xlsxCellAnchor{}
 	twoCellAnchor.EditAs = "oneCell"
 	from := xlsxFrom{}
 	from.Col = colStart

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 9 - 23
templates.go


+ 10 - 9
xmlDecodeDrawing.go

@@ -2,11 +2,11 @@ package excelize
 
 import "encoding/xml"
 
-// decodeTwoCellAnchor directly maps the twoCellAnchor (Two Cell Anchor Shape
-// Size). This element specifies a two cell anchor placeholder for a group, a
-// shape, or a drawing element. It moves with cells and its extents are in EMU
-// units.
-type decodeTwoCellAnchor struct {
+// decodeCellAnchor directly maps the oneCellAnchor (One Cell Anchor Shape Size)
+// and twoCellAnchor (Two Cell Anchor Shape Size). This element specifies a two
+// cell anchor placeholder for a group, a shape, or a drawing element. It moves
+// with cells and its extents are in EMU units.
+type decodeCellAnchor struct {
 	EditAs  string `xml:"editAs,attr,omitempty"`
 	Content string `xml:",innerxml"`
 }
@@ -16,8 +16,9 @@ type decodeTwoCellAnchor struct {
 // after serialization and deserialization, two different structures are
 // defined. decodeWsDr just for deserialization.
 type decodeWsDr struct {
-	A             string                 `xml:"xmlns a,attr"`
-	Xdr           string                 `xml:"xmlns xdr,attr"`
-	TwoCellAnchor []*decodeTwoCellAnchor `xml:"twoCellAnchor,omitempty"`
-	XMLName       xml.Name               `xml:"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing wsDr,omitempty"`
+	A             string              `xml:"xmlns a,attr"`
+	Xdr           string              `xml:"xmlns xdr,attr"`
+	OneCellAnchor []*decodeCellAnchor `xml:"oneCellAnchor,omitempty"`
+	TwoCellAnchor []*decodeCellAnchor `xml:"twoCellAnchor,omitempty"`
+	XMLName       xml.Name            `xml:"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing wsDr,omitempty"`
 }

+ 9 - 8
xmlDrawing.go

@@ -162,11 +162,11 @@ type xlsxClientData struct {
 	FPrintsWithSheet bool `xml:"fPrintsWithSheet,attr"`
 }
 
-// xlsxTwoCellAnchor directly maps the twoCellAnchor (Two Cell Anchor Shape
-// Size). This element specifies a two cell anchor placeholder for a group, a
-// shape, or a drawing element. It moves with cells and its extents are in EMU
-// units.
-type xlsxTwoCellAnchor struct {
+// xlsxCellAnchor directly maps the oneCellAnchor (One Cell Anchor Shape Size)
+// and twoCellAnchor (Two Cell Anchor Shape Size). This element specifies a two
+// cell anchor placeholder for a group, a shape, or a drawing element. It moves
+// with cells and its extents are in EMU units.
+type xlsxCellAnchor struct {
 	EditAs       string          `xml:"editAs,attr,omitempty"`
 	From         *xlsxFrom       `xml:"xdr:from"`
 	To           *xlsxTo         `xml:"xdr:to"`
@@ -178,9 +178,10 @@ type xlsxTwoCellAnchor struct {
 // xlsxWsDr directly maps the root element for a part of this content type shall
 // wsDr.
 type xlsxWsDr struct {
-	TwoCellAnchor []*xlsxTwoCellAnchor `xml:"xdr:twoCellAnchor"`
-	Xdr           string               `xml:"xmlns:xdr,attr"`
-	A             string               `xml:"xmlns:a,attr"`
+	OneCellAnchor []*xlsxCellAnchor `xml:"xdr:oneCellAnchor"`
+	TwoCellAnchor []*xlsxCellAnchor `xml:"xdr:twoCellAnchor"`
+	Xdr           string            `xml:"xmlns:xdr,attr"`
+	A             string            `xml:"xmlns:a,attr"`
 }
 
 // encodeWsDr directly maps the element xdr:wsDr.

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio