فهرست منبع

Get latest revision "github.com/tealeg/xlsx"

xormplus 8 سال پیش
والد
کامیت
e56fa43008

+ 46 - 0
vendor/github.com/tealeg/xlsx/CODE_OF_CONDUCT.md

@@ -0,0 +1,46 @@
+# Contributor Covenant Code of Conduct
+
+## Our Pledge
+
+In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
+
+## Our Standards
+
+Examples of behavior that contributes to creating a positive environment include:
+
+* Using welcoming and inclusive language
+* Being respectful of differing viewpoints and experiences
+* Gracefully accepting constructive criticism
+* Focusing on what is best for the community
+* Showing empathy towards other community members
+
+Examples of unacceptable behavior by participants include:
+
+* The use of sexualized language or imagery and unwelcome sexual attention or advances
+* Trolling, insulting/derogatory comments, and personal or political attacks
+* Public or private harassment
+* Publishing others' private information, such as a physical or electronic address, without explicit permission
+* Other conduct which could reasonably be considered inappropriate in a professional setting
+
+## Our Responsibilities
+
+Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
+
+Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
+
+## Scope
+
+This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
+
+## Enforcement
+
+Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at tealeg@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
+
+Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
+
+## Attribution
+
+This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
+
+[homepage]: http://contributor-covenant.org
+[version]: http://contributor-covenant.org/version/1/4/

+ 29 - 0
vendor/github.com/tealeg/xlsx/LICENSE

@@ -0,0 +1,29 @@
+BSD 3-Clause License
+
+Copyright (c) 2011-2017, Geoffrey J. Teale
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+  list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+  this list of conditions and the following disclaimer in the documentation
+  and/or other materials provided with the distribution.
+
+* Neither the name of the copyright holder nor the names of its
+  contributors may be used to endorse or promote products derived from
+  this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ 71 - 11
vendor/github.com/tealeg/xlsx/cell.go

@@ -67,9 +67,15 @@ func (c *Cell) SetString(s string) {
 	c.cellType = CellTypeString
 	c.cellType = CellTypeString
 }
 }
 
 
-// String returns the value of a Cell as a string.
-func (c *Cell) String() (string, error) {
-	return c.FormattedValue()
+// String returns the value of a Cell as a string.  If you'd like to
+// see errors returned from formatting then please use
+// Cell.FormattedValue() instead.
+func (c *Cell) String() string {
+	// To preserve the String() interface we'll throw away errors.
+	// Not that using FormattedValue is therefore strongly
+	// preferred.
+	value, _ := c.FormattedValue()
+	return value
 }
 }
 
 
 // SetFloat sets the value of a cell to a float.
 // SetFloat sets the value of a cell to a float.
@@ -77,6 +83,15 @@ func (c *Cell) SetFloat(n float64) {
 	c.SetValue(n)
 	c.SetValue(n)
 }
 }
 
 
+//GetTime returns the value of a Cell as a time.Time
+func (c *Cell) GetTime(date1904 bool) (t time.Time, err error) {
+	f, err := c.Float()
+	if err != nil {
+		return t, err
+	}
+	return TimeFromExcelTime(f, date1904), nil
+}
+
 /*
 /*
 	The following are samples of format samples.
 	The following are samples of format samples.
 
 
@@ -105,21 +120,51 @@ func (c *Cell) SetFloatWithFormat(n float64, format string) {
 
 
 var timeLocationUTC, _ = time.LoadLocation("UTC")
 var timeLocationUTC, _ = time.LoadLocation("UTC")
 
 
-func timeToUTCTime(t time.Time) time.Time {
+func TimeToUTCTime(t time.Time) time.Time {
 	return time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), t.Nanosecond(), timeLocationUTC)
 	return time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), t.Nanosecond(), timeLocationUTC)
 }
 }
 
 
-func timeToExcelTime(t time.Time) float64 {
-	return float64(t.Unix())/86400.0 + 25569.0
+func TimeToExcelTime(t time.Time) float64 {
+	return float64(t.UnixNano())/8.64e13 + 25569.0
 }
 }
 
 
+// DateTimeOptions are additional options for exporting times
+type DateTimeOptions struct {
+	// Location allows calculating times in other timezones/locations
+	Location *time.Location
+	// ExcelTimeFormat is the string you want excel to use to format the datetime
+	ExcelTimeFormat string
+}
+
+var (
+	DefaultDateFormat     = builtInNumFmt[14]
+	DefaultDateTimeFormat = builtInNumFmt[22]
+
+	DefaultDateOptions = DateTimeOptions{
+		Location:        timeLocationUTC,
+		ExcelTimeFormat: DefaultDateFormat,
+	}
+
+	DefaultDateTimeOptions = DateTimeOptions{
+		Location:        timeLocationUTC,
+		ExcelTimeFormat: DefaultDateTimeFormat,
+	}
+)
+
 // SetDate sets the value of a cell to a float.
 // SetDate sets the value of a cell to a float.
 func (c *Cell) SetDate(t time.Time) {
 func (c *Cell) SetDate(t time.Time) {
-	c.SetDateTimeWithFormat(float64(int64(timeToExcelTime(timeToUTCTime(t)))), builtInNumFmt[14])
+	c.SetDateWithOptions(t, DefaultDateOptions)
 }
 }
 
 
 func (c *Cell) SetDateTime(t time.Time) {
 func (c *Cell) SetDateTime(t time.Time) {
-	c.SetDateTimeWithFormat(timeToExcelTime(timeToUTCTime(t)), builtInNumFmt[22])
+	c.SetDateWithOptions(t, DefaultDateTimeOptions)
+}
+
+// SetDateWithOptions allows for more granular control when exporting dates and times
+func (c *Cell) SetDateWithOptions(t time.Time, options DateTimeOptions) {
+	_, offset := t.In(options.Location).Zone()
+	t = time.Unix(t.Unix()+int64(offset), 0)
+	c.SetDateTimeWithFormat(TimeToExcelTime(t.In(timeLocationUTC)), options.ExcelTimeFormat)
 }
 }
 
 
 func (c *Cell) SetDateTimeWithFormat(n float64, format string) {
 func (c *Cell) SetDateTimeWithFormat(n float64, format string) {
@@ -352,8 +397,6 @@ func parseTime(c *Cell) (string, error) {
 		{"mmm", "Jan"},
 		{"mmm", "Jan"},
 		{"mmss", "0405"},
 		{"mmss", "0405"},
 		{"ss", "05"},
 		{"ss", "05"},
-		{"hh", "15"},
-		{"h", "3"},
 		{"mm:", "04:"},
 		{"mm:", "04:"},
 		{":mm", ":04"},
 		{":mm", ":04"},
 		{"mm", "01"},
 		{"mm", "01"},
@@ -362,6 +405,16 @@ func parseTime(c *Cell) (string, error) {
 		{"%%%%", "January"},
 		{"%%%%", "January"},
 		{"&&&&", "Monday"},
 		{"&&&&", "Monday"},
 	}
 	}
+	// It is the presence of the "am/pm" indicator that determins
+	// if this is a 12 hour or 24 hours time format, not the
+	// number of 'h' characters.
+	if is12HourTime(format) {
+		format = strings.Replace(format, "hh", "03", 1)
+		format = strings.Replace(format, "h", "3", 1)
+	} else {
+		format = strings.Replace(format, "hh", "15", 1)
+		format = strings.Replace(format, "h", "15", 1)
+	}
 	for _, repl := range replacements {
 	for _, repl := range replacements {
 		format = strings.Replace(format, repl.xltime, repl.gotime, 1)
 		format = strings.Replace(format, repl.xltime, repl.gotime, 1)
 	}
 	}
@@ -369,6 +422,7 @@ func parseTime(c *Cell) (string, error) {
 	// possible dangling colon that would remain.
 	// possible dangling colon that would remain.
 	if val.Hour() < 1 {
 	if val.Hour() < 1 {
 		format = strings.Replace(format, "]:", "]", 1)
 		format = strings.Replace(format, "]:", "]", 1)
+		format = strings.Replace(format, "[03]", "", 1)
 		format = strings.Replace(format, "[3]", "", 1)
 		format = strings.Replace(format, "[3]", "", 1)
 		format = strings.Replace(format, "[15]", "", 1)
 		format = strings.Replace(format, "[15]", "", 1)
 	} else {
 	} else {
@@ -382,7 +436,7 @@ func parseTime(c *Cell) (string, error) {
 // a time.Time.
 // a time.Time.
 func isTimeFormat(format string) bool {
 func isTimeFormat(format string) bool {
 	dateParts := []string{
 	dateParts := []string{
-		"yy", "hh", "am", "pm", "ss", "mm", ":",
+		"yy", "hh", "h", "am/pm", "AM/PM", "A/P", "a/p", "ss", "mm", ":",
 	}
 	}
 	for _, part := range dateParts {
 	for _, part := range dateParts {
 		if strings.Contains(format, part) {
 		if strings.Contains(format, part) {
@@ -391,3 +445,9 @@ func isTimeFormat(format string) bool {
 	}
 	}
 	return false
 	return false
 }
 }
+
+// is12HourTime checks whether an Excel time format string is a 12
+// hours form.
+func is12HourTime(format string) bool {
+	return strings.Contains(format, "am/pm") || strings.Contains(format, "AM/PM") || strings.Contains(format, "a/p") || strings.Contains(format, "A/P")
+}

+ 29 - 2
vendor/github.com/tealeg/xlsx/file.go

@@ -4,6 +4,7 @@ import (
 	"archive/zip"
 	"archive/zip"
 	"bytes"
 	"bytes"
 	"encoding/xml"
 	"encoding/xml"
+	"errors"
 	"fmt"
 	"fmt"
 	"io"
 	"io"
 	"os"
 	"os"
@@ -122,6 +123,9 @@ func (f *File) AddSheet(sheetName string) (*Sheet, error) {
 	if _, exists := f.Sheet[sheetName]; exists {
 	if _, exists := f.Sheet[sheetName]; exists {
 		return nil, fmt.Errorf("duplicate sheet name '%s'.", sheetName)
 		return nil, fmt.Errorf("duplicate sheet name '%s'.", sheetName)
 	}
 	}
+	if len(sheetName) >= 31 {
+		return nil, fmt.Errorf("sheet name must be less than 31 characters long.  It is currently '%d' characters long", len(sheetName))
+	}
 	sheet := &Sheet{
 	sheet := &Sheet{
 		Name:     sheetName,
 		Name:     sheetName,
 		File:     f,
 		File:     f,
@@ -132,6 +136,19 @@ func (f *File) AddSheet(sheetName string) (*Sheet, error) {
 	return sheet, nil
 	return sheet, nil
 }
 }
 
 
+// Appends an existing Sheet, with the provided name, to a File
+func (f *File) AppendSheet(sheet Sheet, sheetName string) (*Sheet, error) {
+	if _, exists := f.Sheet[sheetName]; exists {
+		return nil, fmt.Errorf("duplicate sheet name '%s'.", sheetName)
+	}
+	sheet.Name = sheetName
+	sheet.File = f
+	sheet.Selected = len(f.Sheets) == 0
+	f.Sheet[sheetName] = &sheet
+	f.Sheets = append(f.Sheets, &sheet)
+	return &sheet, nil
+}
+
 func (f *File) makeWorkbook() xlsxWorkbook {
 func (f *File) makeWorkbook() xlsxWorkbook {
 	return xlsxWorkbook{
 	return xlsxWorkbook{
 		FileVersion: xlsxFileVersion{AppName: "Go XLSX"},
 		FileVersion: xlsxFileVersion{AppName: "Go XLSX"},
@@ -205,6 +222,10 @@ func (f *File) MarshallParts() (map[string]string, error) {
 		f.styles = newXlsxStyleSheet(f.theme)
 		f.styles = newXlsxStyleSheet(f.theme)
 	}
 	}
 	f.styles.reset()
 	f.styles.reset()
+	if len(f.Sheets) == 0 {
+		err := errors.New("Workbook must contains atleast one worksheet")
+		return nil, err
+	}
 	for _, sheet := range f.Sheets {
 	for _, sheet := range f.Sheets {
 		xSheet := sheet.makeXLSXSheet(refTable, f.styles)
 		xSheet := sheet.makeXLSXSheet(refTable, f.styles)
 		rId := fmt.Sprintf("rId%d", sheetIndex)
 		rId := fmt.Sprintf("rId%d", sheetIndex)
@@ -294,9 +315,15 @@ func (file *File) ToSlice() (output [][][]string, err error) {
 			}
 			}
 			r := []string{}
 			r := []string{}
 			for _, cell := range row.Cells {
 			for _, cell := range row.Cells {
-				str, err := cell.String()
+				str, err := cell.FormattedValue()
 				if err != nil {
 				if err != nil {
-					return output, err
+					// Recover from strconv.NumError if the value is an empty string,
+					// and insert an empty string in the output.
+					if numErr, ok := err.(*strconv.NumError); ok && numErr.Num == "" {
+						str = ""
+					} else {
+						return output, err
+					}
 				}
 				}
 				r = append(r, str)
 				r = append(r, str)
 			}
 			}

+ 132 - 0
vendor/github.com/tealeg/xlsx/read.go

@@ -0,0 +1,132 @@
+package xlsx
+
+import (
+	"errors"
+	"reflect"
+	"strconv"
+	"time"
+)
+
+var (
+	errNilInterface     = errors.New("nil pointer is not a valid argument")
+	errNotStructPointer = errors.New("argument must be a pointer to struct")
+	errInvalidTag       = errors.New(`invalid tag: must have the format xlsx:idx`)
+)
+
+//XLSXUnmarshaler is the interface implemented for types that can unmarshal a Row
+//as a representation of themselves.
+type XLSXUnmarshaler interface {
+	Unmarshal(*Row) error
+}
+
+//ReadStruct reads a struct from r to ptr. Accepts a ptr
+//to struct. This code expects a tag xlsx:"N", where N is the index
+//of the cell to be used. Basic types like int,string,float64 and bool
+//are supported
+func (r *Row) ReadStruct(ptr interface{}) error {
+	if ptr == nil {
+		return errNilInterface
+	}
+	//check if the type implements XLSXUnmarshaler. If so,
+	//just let it do the work.
+	unmarshaller, ok := ptr.(XLSXUnmarshaler)
+	if ok {
+		return unmarshaller.Unmarshal(r)
+	}
+	v := reflect.ValueOf(ptr)
+	if v.Kind() != reflect.Ptr {
+		return errNotStructPointer
+	}
+	v = v.Elem()
+	if v.Kind() != reflect.Struct {
+		return errNotStructPointer
+	}
+	n := v.NumField()
+	for i := 0; i < n; i++ {
+		field := v.Type().Field(i)
+		idx := field.Tag.Get("xlsx")
+		//do a recursive check for the field if it is a struct or a pointer
+		//even if it doesn't have a tag
+		//ignore if it has a - or empty tag
+		isTime := false
+		switch {
+		case idx == "-":
+			continue
+		case field.Type.Kind() == reflect.Ptr || field.Type.Kind() == reflect.Struct:
+			var structPtr interface{}
+			if !v.Field(i).CanSet() {
+				continue
+			}
+			if field.Type.Kind() == reflect.Struct {
+				structPtr = v.Field(i).Addr().Interface()
+			} else {
+				structPtr = v.Field(i).Interface()
+			}
+			//check if the container is a time.Time
+			_, isTime = structPtr.(*time.Time)
+			if isTime {
+				break
+			}
+			err := r.ReadStruct(structPtr)
+			if err != nil {
+				return err
+			}
+			continue
+		case len(idx) == 0:
+			continue
+		}
+		pos, err := strconv.Atoi(idx)
+		if err != nil {
+			return errInvalidTag
+		}
+
+		//check if desired position is not out of bounds
+		if pos > len(r.Cells)-1 {
+			continue
+		}
+		cell := r.Cells[pos]
+		fieldV := v.Field(i)
+		//continue if the field is not settable
+		if !fieldV.CanSet() {
+			continue
+		}
+		if isTime {
+			t, err := cell.GetTime(false)
+			if err != nil {
+				return err
+			}
+			if field.Type.Kind() == reflect.Ptr {
+				fieldV.Set(reflect.ValueOf(&t))
+			} else {
+				fieldV.Set(reflect.ValueOf(t))
+			}
+			continue
+		}
+		switch field.Type.Kind() {
+		case reflect.String:
+			value, err := cell.FormattedValue()
+			if err != nil {
+				return err
+			}
+			fieldV.SetString(value)
+		case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
+			value, err := cell.Int64()
+			if err != nil {
+				return err
+			}
+			fieldV.SetInt(value)
+		case reflect.Float64:
+			value, err := cell.Float()
+			if err != nil {
+				return err
+			}
+			fieldV.SetFloat(value)
+		case reflect.Bool:
+			value := cell.Bool()
+			fieldV.SetBool(value)
+		}
+	}
+	value := v.Interface()
+	ptr = &value
+	return nil
+}

+ 5 - 0
vendor/github.com/tealeg/xlsx/row.go

@@ -9,6 +9,11 @@ type Row struct {
 	isCustom     bool
 	isCustom     bool
 }
 }
 
 
+func (r *Row) SetHeight(ht float64) {
+	r.Height = ht
+	r.isCustom = true
+}
+
 func (r *Row) SetHeightCM(ht float64) {
 func (r *Row) SetHeightCM(ht float64) {
 	r.Height = ht * 28.3464567 // Convert CM to postscript points
 	r.Height = ht * 28.3464567 // Convert CM to postscript points
 	r.isCustom = true
 	r.isCustom = true

+ 15 - 3
vendor/github.com/tealeg/xlsx/sheet.go

@@ -18,6 +18,7 @@ type Sheet struct {
 	Selected    bool
 	Selected    bool
 	SheetViews  []SheetView
 	SheetViews  []SheetView
 	SheetFormat SheetFormat
 	SheetFormat SheetFormat
+	AutoFilter  *AutoFilter
 }
 }
 
 
 type SheetView struct {
 type SheetView struct {
@@ -39,6 +40,11 @@ type SheetFormat struct {
 	OutlineLevelRow  uint8
 	OutlineLevelRow  uint8
 }
 }
 
 
+type AutoFilter struct {
+	TopLeftCell     string
+	BottomRightCell string
+}
+
 // Add a new Row to a Sheet
 // Add a new Row to a Sheet
 func (s *Sheet) AddRow() *Row {
 func (s *Sheet) AddRow() *Row {
 	row := &Row{Sheet: s}
 	row := &Row{Sheet: s}
@@ -147,7 +153,7 @@ func (s *Sheet) handleMerged() {
 		mainstyle.Border.Right = "none"
 		mainstyle.Border.Right = "none"
 		mainstyle.Border.Bottom = "none"
 		mainstyle.Border.Bottom = "none"
 
 
-		maincol, mainrow, _ := getCoordsFromCellIDString(key)
+		maincol, mainrow, _ := GetCoordsFromCellIDString(key)
 		for rownum := 0; rownum <= cell.VMerge; rownum++ {
 		for rownum := 0; rownum <= cell.VMerge; rownum++ {
 			for colnum := 0; colnum <= cell.HMerge; colnum++ {
 			for colnum := 0; colnum <= cell.HMerge; colnum++ {
 				tmpcell := s.Cell(mainrow+rownum, maincol+colnum)
 				tmpcell := s.Cell(mainrow+rownum, maincol+colnum)
@@ -227,11 +233,13 @@ func (s *Sheet) makeXLSXSheet(refTable *RefTable, styles *xlsxStyleSheet) *xlsxW
 		}
 		}
 		colsXfIdList[c] = XfId
 		colsXfIdList[c] = XfId
 
 
-		var customWidth int
+		var customWidth bool
 		if col.Width == 0 {
 		if col.Width == 0 {
 			col.Width = ColWidth
 			col.Width = ColWidth
+			customWidth = false
+
 		} else {
 		} else {
-			customWidth = 1
+			customWidth = true
 		}
 		}
 		worksheet.Cols.Col = append(worksheet.Cols.Col,
 		worksheet.Cols.Col = append(worksheet.Cols.Col,
 			xlsxCol{Min: col.Min,
 			xlsxCol{Min: col.Min,
@@ -342,6 +350,10 @@ func (s *Sheet) makeXLSXSheet(refTable *RefTable, styles *xlsxStyleSheet) *xlsxW
 		worksheet.MergeCells.Count = len(worksheet.MergeCells.Cells)
 		worksheet.MergeCells.Count = len(worksheet.MergeCells.Cells)
 	}
 	}
 
 
+	if s.AutoFilter != nil {
+		worksheet.AutoFilter = &xlsxAutoFilter{Ref: fmt.Sprintf("%v:%v", s.AutoFilter.TopLeftCell, s.AutoFilter.BottomRightCell)}
+	}
+
 	worksheet.SheetData = xSheet
 	worksheet.SheetData = xSheet
 	dimension := xlsxDimension{}
 	dimension := xlsxDimension{}
 	dimension.Ref = fmt.Sprintf("A1:%s%d",
 	dimension.Ref = fmt.Sprintf("A1:%s%d",

+ 9 - 3
vendor/github.com/tealeg/xlsx/xmlStyle.go

@@ -8,6 +8,7 @@
 package xlsx
 package xlsx
 
 
 import (
 import (
+	"bytes"
 	"encoding/xml"
 	"encoding/xml"
 	"fmt"
 	"fmt"
 	"strconv"
 	"strconv"
@@ -57,9 +58,9 @@ var builtInNumFmt = map[int]string{
 	49: "@",
 	49: "@",
 }
 }
 
 
-var builtInNumFmtInv = make(map[string]int,40)
+var builtInNumFmtInv = make(map[string]int, 40)
 
 
-func init () {
+func init() {
 	for k, v := range builtInNumFmt {
 	for k, v := range builtInNumFmt {
 		builtInNumFmtInv[v] = k
 		builtInNumFmtInv[v] = k
 	}
 	}
@@ -451,7 +452,12 @@ type xlsxNumFmt struct {
 }
 }
 
 
 func (numFmt *xlsxNumFmt) Marshal() (result string, err error) {
 func (numFmt *xlsxNumFmt) Marshal() (result string, err error) {
-	return fmt.Sprintf(`<numFmt numFmtId="%d" formatCode="%s"/>`, numFmt.NumFmtId, numFmt.FormatCode), nil
+	formatCode := &bytes.Buffer{}
+	if err := xml.EscapeText(formatCode, []byte(numFmt.FormatCode)); err != nil {
+		return "", err
+	}
+
+	return fmt.Sprintf(`<numFmt numFmtId="%d" formatCode="%s"/>`, numFmt.NumFmtId, formatCode), nil
 }
 }
 
 
 // xlsxFonts directly maps the fonts element in the namespace
 // xlsxFonts directly maps the fonts element in the namespace

+ 14 - 8
vendor/github.com/tealeg/xlsx/xmlWorksheet.go

@@ -17,6 +17,7 @@ type xlsxWorksheet struct {
 	SheetFormatPr xlsxSheetFormatPr `xml:"sheetFormatPr"`
 	SheetFormatPr xlsxSheetFormatPr `xml:"sheetFormatPr"`
 	Cols          *xlsxCols         `xml:"cols,omitempty"`
 	Cols          *xlsxCols         `xml:"cols,omitempty"`
 	SheetData     xlsxSheetData     `xml:"sheetData"`
 	SheetData     xlsxSheetData     `xml:"sheetData"`
+	AutoFilter    *xlsxAutoFilter   `xml:"autoFilter,omitempty"`
 	MergeCells    *xlsxMergeCells   `xml:"mergeCells,omitempty"`
 	MergeCells    *xlsxMergeCells   `xml:"mergeCells,omitempty"`
 	PrintOptions  xlsxPrintOptions  `xml:"printOptions"`
 	PrintOptions  xlsxPrintOptions  `xml:"printOptions"`
 	PageMargins   xlsxPageMargins   `xml:"pageMargins"`
 	PageMargins   xlsxPageMargins   `xml:"pageMargins"`
@@ -201,7 +202,7 @@ type xlsxCol struct {
 	Min          int     `xml:"min,attr"`
 	Min          int     `xml:"min,attr"`
 	Style        int     `xml:"style,attr"`
 	Style        int     `xml:"style,attr"`
 	Width        float64 `xml:"width,attr"`
 	Width        float64 `xml:"width,attr"`
-	CustomWidth  int     `xml:"customWidth,attr,omitempty"`
+	CustomWidth  bool    `xml:"customWidth,attr,omitempty"`
 	OutlineLevel uint8   `xml:"outlineLevel,attr,omitempty"`
 	OutlineLevel uint8   `xml:"outlineLevel,attr,omitempty"`
 }
 }
 
 
@@ -236,6 +237,10 @@ type xlsxRow struct {
 	OutlineLevel uint8   `xml:"outlineLevel,attr,omitempty"`
 	OutlineLevel uint8   `xml:"outlineLevel,attr,omitempty"`
 }
 }
 
 
+type xlsxAutoFilter struct {
+	Ref string `xml:"ref,attr"`
+}
+
 type xlsxMergeCell struct {
 type xlsxMergeCell struct {
 	Ref string `xml:"ref,attr"` // ref: horiz "A1:C1", vert "B3:B6", both  "D3:G4"
 	Ref string `xml:"ref,attr"` // ref: horiz "A1:C1", vert "B3:B6", both  "D3:G4"
 }
 }
@@ -255,11 +260,11 @@ func (mc *xlsxMergeCells) getExtent(cellRef string) (int, int, error) {
 	for _, cell := range mc.Cells {
 	for _, cell := range mc.Cells {
 		if strings.HasPrefix(cell.Ref, cellRef+":") {
 		if strings.HasPrefix(cell.Ref, cellRef+":") {
 			parts := strings.Split(cell.Ref, ":")
 			parts := strings.Split(cell.Ref, ":")
-			startx, starty, err := getCoordsFromCellIDString(parts[0])
+			startx, starty, err := GetCoordsFromCellIDString(parts[0])
 			if err != nil {
 			if err != nil {
 				return -1, -1, err
 				return -1, -1, err
 			}
 			}
-			endx, endy, err := getCoordsFromCellIDString(parts[1])
+			endx, endy, err := GetCoordsFromCellIDString(parts[1])
 			if err != nil {
 			if err != nil {
 				return -2, -2, err
 				return -2, -2, err
 			}
 			}
@@ -274,11 +279,12 @@ func (mc *xlsxMergeCells) getExtent(cellRef string) (int, int, error) {
 // currently I have not checked it for completeness - it does as much
 // currently I have not checked it for completeness - it does as much
 // as I need.
 // as I need.
 type xlsxC struct {
 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.
-	F *xlsxF `xml:"f,omitempty"`      // Formula
-	V string `xml:"v,omitempty"`      // Value
+	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.
+	F  *xlsxF  `xml:"f,omitempty"`      // Formula
+	V  string  `xml:"v,omitempty"`      // Value
+	Is *xlsxSI `xml:"is,omitempty"`     // Inline String.
 }
 }
 
 
 // xlsxF directly maps the f element in the namespace
 // xlsxF directly maps the f element in the namespace