Pārlūkot izejas kodu

make empty value to be empty at xml(omitempty v node)

blackss2 10 gadi atpakaļ
vecāks
revīzija
d4f71e635c
2 mainītis faili ar 4 papildinājumiem un 2 dzēšanām
  1. 3 1
      sheet.go
  2. 1 1
      xmlWorksheet.go

+ 3 - 1
sheet.go

@@ -178,7 +178,9 @@ func (s *Sheet) makeXLSXSheet(refTable *RefTable, styles *xlsxStyleSheet) *xlsxW
 			xC.R = fmt.Sprintf("%s%d", numericToLetters(c), r+1)
 			switch cell.cellType {
 			case CellTypeString:
-				xC.V = strconv.Itoa(refTable.AddString(cell.Value))
+				if len(cell.Value) > 0 {
+					xC.V = strconv.Itoa(refTable.AddString(cell.Value))
+				}
 				xC.T = "s"
 				xC.S = XfId
 			case CellTypeBool:

+ 1 - 1
xmlWorksheet.go

@@ -249,7 +249,7 @@ type xlsxC struct {
 	R string `xml:"r,attr"`           // Cell ID, e.g. A1
 	S int    `xml:"s,attr,omitempty"` // Style reference.
 	T string `xml:"t,attr,omitempty"` // Type.
-	V string `xml:"v"`                // Value
+	V string `xml:"v,omitempty"`      // Value
 	F *xlsxF `xml:"f,omitempty"`      // Formula
 }