Browse Source

Apply customWidth attribute to <row> when it has been modified

Mathias Fredriksson 10 years ago
parent
commit
69d6b65351
2 changed files with 17 additions and 13 deletions
  1. 10 7
      sheet.go
  2. 7 6
      xmlWorksheet.go

+ 10 - 7
sheet.go

@@ -54,8 +54,7 @@ func (s *Sheet) maybeAddCol(cellCount int) {
 			Min:       cellCount,
 			Max:       cellCount,
 			Hidden:    false,
-			Collapsed: false,
-			Width:     ColWidth}
+			Collapsed: false}
 		s.Cols = append(s.Cols, col)
 		s.MaxCol = cellCount
 	}
@@ -128,16 +127,20 @@ func (s *Sheet) makeXLSXSheet(refTable *RefTable, styles *xlsxStyleSheet) *xlsxW
 		}
 		colsXfIdList[c] = XfId
 
+		var customWidth int
 		if col.Width == 0 {
 			col.Width = ColWidth
+		} else {
+			customWidth = 1
 		}
 		worksheet.Cols.Col = append(worksheet.Cols.Col,
 			xlsxCol{Min: col.Min,
-				Max:       col.Max,
-				Hidden:    col.Hidden,
-				Width:     col.Width,
-				Collapsed: col.Collapsed,
-				Style:     XfId,
+				Max:         col.Max,
+				Hidden:      col.Hidden,
+				Width:       col.Width,
+				CustomWidth: customWidth,
+				Collapsed:   col.Collapsed,
+				Style:       XfId,
 			})
 	}
 

+ 7 - 6
xmlWorksheet.go

@@ -192,12 +192,13 @@ 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"`
-	Max       int     `xml:"max,attr"`
-	Min       int     `xml:"min,attr"`
-	Style     int     `xml:"style,attr"`
-	Width     float64 `xml:"width,attr"`
+	Collapsed   bool    `xml:"collapsed,attr"`
+	Hidden      bool    `xml:"hidden,attr"`
+	Max         int     `xml:"max,attr"`
+	Min         int     `xml:"min,attr"`
+	Style       int     `xml:"style,attr"`
+	Width       float64 `xml:"width,attr"`
+	CustomWidth int     `xml:"customWidth,attr,omitempty"`
 }
 
 // xlsxDimension directly maps the dimension element in the namespace