瀏覽代碼

Testing dates adn bestFit

- Dates work but show ##### on default column width because they do not fit inside the columns.
- Increasing the column width fixes that // TODO
- BestFit is succesfully added to colums in xlsx but excel ignores it. This is probably because there is already a width given but the documentation is a little vague here
DamianSzkuat 6 年之前
父節點
當前提交
2485369328
共有 5 個文件被更改,包括 12 次插入1 次删除
  1. 二進制
      Workbook_Date_test.xlsx
  2. 1 0
      col.go
  3. 7 1
      sheet.go
  4. 2 0
      stream_file_builder.go
  5. 2 0
      xmlWorksheet.go

二進制
Workbook_Date_test.xlsx


+ 1 - 0
col.go

@@ -8,6 +8,7 @@ type Col struct {
 	Max          int
 	Hidden       bool
 	Width        float64
+	BestFit		 bool
 	Collapsed    bool
 	OutlineLevel uint8
 	numFmt       string

+ 7 - 1
sheet.go

@@ -255,10 +255,15 @@ func (s *Sheet) makeXLSXSheet(refTable *RefTable, styles *xlsxStyleSheet) *xlsxW
 		colsXfIdList[c] = XfId
 
 		var customWidth bool
+		// TODO test
+		var bestFit bool
 		if col.Width == 0 {
 			col.Width = ColWidth
 			customWidth = false
-
+			// TODO test
+			if col.BestFit{
+				bestFit = true
+			}
 		} else {
 			customWidth = true
 		}
@@ -267,6 +272,7 @@ func (s *Sheet) makeXLSXSheet(refTable *RefTable, styles *xlsxStyleSheet) *xlsxW
 				Max:          col.Max,
 				Hidden:       col.Hidden,
 				Width:        col.Width,
+				BestFit:	  bestFit,
 				CustomWidth:  customWidth,
 				Collapsed:    col.Collapsed,
 				OutlineLevel: col.OutlineLevel,

+ 2 - 0
stream_file_builder.go

@@ -162,6 +162,8 @@ func (sb *StreamFileBuilder) AddSheetWithStyle(name string, cells []StreamCell)
 	// Set default column types based on the cel types in the first row
 	for i, cell := range cells {
 		sheet.Cols[i].SetType(cell.cellType)
+		// TODO test
+		sheet.Cols[i].BestFit = true
 	}
 	return nil
 }

+ 2 - 0
xmlWorksheet.go

@@ -203,6 +203,8 @@ type xlsxCol struct {
 	Style        int     `xml:"style,attr"`
 	Width        float64 `xml:"width,attr"`
 	CustomWidth  bool    `xml:"customWidth,attr,omitempty"`
+	// TODO test
+	BestFit 	 bool    `xml:"bestFit,attr,omitempty"`
 	OutlineLevel uint8   `xml:"outlineLevel,attr,omitempty"`
 }