Prechádzať zdrojové kódy

prevent all tabSelected be true / prevent row.cell.V showing up when
Value is null / change default celltype to CellTypeGeneral from
CellTypeString

blackss2 10 rokov pred
rodič
commit
2c5b060124
4 zmenil súbory, kde vykonal 20 pridanie a 12 odobranie
  1. 9 4
      file.go
  2. 1 0
      row.go
  3. 4 2
      sheet.go
  4. 6 6
      xmlWorksheet.go

+ 9 - 4
file.go

@@ -175,8 +175,11 @@ func (f *File) MarshallParts() (map[string]string, error) {
 		f.styles = newXlsxStyleSheet(f.theme)
 	}
 	f.styles.reset()
-	for _, sheet := range f.Sheets {
+	for i, sheet := range f.Sheets {
 		xSheet := sheet.makeXLSXSheet(refTable, f.styles)
+		if i == 0 {
+			xSheet.SheetViews.SheetView[0].TabSelected = true
+		}
 		rId := fmt.Sprintf("rId%d", sheetIndex)
 		sheetId := strconv.Itoa(sheetIndex)
 		sheetPath := fmt.Sprintf("worksheets/sheet%d.xml", sheetIndex)
@@ -219,9 +222,11 @@ func (f *File) MarshallParts() (map[string]string, error) {
 	parts["xl/theme/theme1.xml"] = TEMPLATE_XL_THEME_THEME
 
 	xSST := refTable.makeXLSXSST()
-	parts["xl/sharedStrings.xml"], err = marshal(xSST)
-	if err != nil {
-		return parts, err
+	if xSST.Count > 0 || xSST.UniqueCount > 0 {
+		parts["xl/sharedStrings.xml"], err = marshal(xSST)
+		if err != nil {
+			return parts, err
+		}		
 	}
 
 	xWRel := workbookRels.MakeXLSXWorkbookRels()

+ 1 - 0
row.go

@@ -15,6 +15,7 @@ func (r *Row) SetHeightCM(ht float64) {
 
 func (r *Row) AddCell() *Cell {
 	cell := NewCell(r)
+	cell.cellType = CellTypeGeneral
 	r.Cells = append(r.Cells, cell)
 	r.Sheet.maybeAddCol(len(r.Cells))
 	return cell

+ 4 - 2
sheet.go

@@ -166,7 +166,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:
@@ -193,7 +195,7 @@ func (s *Sheet) makeXLSXSheet(refTable *RefTable, styles *xlsxStyleSheet) *xlsxW
 				xC.S = XfId
 			}
 			xRow.C = append(xRow.C, xC)
-
+			
 			if cell.HMerge > 0 || cell.VMerge > 0 {
 				// r == rownum, c == colnum
 				mc := xlsxMergeCell{}

+ 6 - 6
xmlWorksheet.go

@@ -125,7 +125,7 @@ type xlsxSheetView struct {
 	ShowRowColHeaders       bool            `xml:"showRowColHeaders,attr"`
 	ShowZeros               bool            `xml:"showZeros,attr"`
 	RightToLeft             bool            `xml:"rightToLeft,attr"`
-	TabSelected             bool            `xml:"tabSelected,attr"`
+	TabSelected             bool            `xml:"tabSelected,attr,omitempty"`
 	ShowOutlineSymbols      bool            `xml:"showOutlineSymbols,attr"`
 	DefaultGridColor        bool            `xml:"defaultGridColor,attr"`
 	View                    string          `xml:"view,attr"`
@@ -192,11 +192,11 @@ type xlsxCols struct {
 // currently I have not checked it for completeness - it does as much
 // as I need.
 type xlsxCol struct {
-	Collapsed bool    `xml:"collapsed,attr"`
-	Hidden    bool    `xml:"hidden,attr"`
+	Collapsed bool    `xml:"collapsed,attr,omitempty"`
+	Hidden    bool    `xml:"hidden,attr,omitempty"`
 	Max       int     `xml:"max,attr"`
 	Min       int     `xml:"min,attr"`
-	Style     int     `xml:"style,attr"`
+	Style     int     `xml:"style,attr,omitempty"`
 	Width     float64 `xml:"width,attr"`
 }
 
@@ -248,7 +248,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
 }
 
@@ -281,7 +281,7 @@ func newXlsxWorksheet() (worksheet *xlsxWorksheet) {
 		ShowOutlineSymbols:      true,
 		ShowRowColHeaders:       true,
 		ShowZeros:               true,
-		TabSelected:             true,
+		TabSelected:             false,
 		TopLeftCell:             "A1",
 		View:                    "normal",
 		WindowProtection:        false,