Kaynağa Gözat

Merge branch 'master' of https://github.com/achernyak/xlsx into achernyak-master

Geoffrey J. Teale 11 yıl önce
ebeveyn
işleme
5d3f06af61
5 değiştirilmiş dosya ile 14 ekleme ve 8 silme
  1. 1 0
      col.go
  2. 1 1
      file_test.go
  3. 5 1
      sheet.go
  4. 3 3
      sheet_test.go
  5. 4 3
      xmlWorksheet.go

+ 1 - 0
col.go

@@ -4,4 +4,5 @@ type Col struct {
 	Min    int
 	Max    int
 	Hidden bool
+	Width  float64
 }

+ 1 - 1
file_test.go

@@ -288,7 +288,7 @@ func (l *FileSuite) TestMarshalFile(c *C) {
   <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
     <dimension ref="A1:A1"></dimension>
     <cols>
-      <col min="1" max="1"></col>
+      <col min="1" max="1" width="9.5"></col>
     </cols>
     <sheetData>
       <row r="1">

+ 5 - 1
sheet.go

@@ -5,6 +5,9 @@ import (
 	"strconv"
 )
 
+// Default column width in excel
+const colWidth = 9.5
+
 // Sheet is a high level structure intended to provide user access to
 // the contents of a particular sheet within an XLSX file.
 type Sheet struct {
@@ -97,7 +100,8 @@ func (s *Sheet) makeXLSXSheet(refTable *RefTable, styles *xlsxStyles) *xlsxWorks
 		worksheet.Cols.Col = append(worksheet.Cols.Col,
 			xlsxCol{Min: col.Min,
 				Max:    col.Max,
-				Hidden: col.Hidden})
+				Hidden: col.Hidden,
+				Width:  colWidth})
 	}
 	worksheet.SheetData = xSheet
 	dimension := xlsxDimension{}

+ 3 - 3
sheet_test.go

@@ -138,7 +138,7 @@ func (s *SheetSuite) TestMarshalSheet(c *C) {
   <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
     <dimension ref="A1:A1"></dimension>
     <cols>
-      <col min="1" max="1"></col>
+      <col min="1" max="1" width="9.5"></col>
     </cols>
     <sheetData>
       <row r="1">
@@ -173,8 +173,8 @@ func (s *SheetSuite) TestMarshalSheetWithMultipleCells(c *C) {
   <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
     <dimension ref="A1:B1"></dimension>
     <cols>
-      <col min="1" max="1"></col>
-      <col min="2" max="2"></col>
+      <col min="1" max="1" width="9.5"></col>
+      <col min="2" max="2" width="9.5"></col>
     </cols>
     <sheetData>
       <row r="1">

+ 4 - 3
xmlWorksheet.go

@@ -28,9 +28,10 @@ type xlsxCols struct {
 // currently I have not checked it for completeness - it does as much
 // as I need.
 type xlsxCol struct {
-	Min    int  `xml:"min,attr"`
-	Max    int  `xml:"max,attr"`
-	Hidden bool `xml:"hidden,attr,omitempty"`
+	Min    int     `xml:"min,attr"`
+	Max    int     `xml:"max,attr"`
+	Hidden bool    `xml:"hidden,attr,omitempty"`
+	Width  float64 `xml:"width,attr,omitempty"`
 }
 
 // xlsxDimension directly maps the dimension element in the namespace