Browse Source

- Fix missing element in worksheet, workbook and styles. Related issue #81;
- Format code and update readme

Ri Xu 8 years ago
parent
commit
4f942255e4
5 changed files with 74 additions and 48 deletions
  1. 1 1
      README.md
  2. 10 10
      styles.go
  3. 24 14
      xmlStyles.go
  4. 2 2
      xmlWorkbook.go
  5. 37 21
      xmlWorksheet.go

+ 1 - 1
README.md

@@ -173,7 +173,7 @@ func main() {
 
 ## Contributing
 
-Contributions are welcome! Open a pull request to fix a bug, or open an issue to discuss a new feature or change.
+Contributions are welcome! Open a pull request to fix a bug, or open an issue to discuss a new feature or change. XML is compliant with [part 1 of the 5th edition of the ECMA-376 Standard for Office Open XML](http://www.ecma-international.org/publications/standards/Ecma-376.htm).
 
 ## Credits
 

+ 10 - 10
styles.go

@@ -50,7 +50,7 @@ var builtInNumFmt = map[int]string{
 // langNumFmt defined number format code (with unicode values provided for
 // language glyphs where they occur) in different language.
 var langNumFmt = map[string]map[int]string{
-	"zh-tw": map[int]string{
+	"zh-tw": {
 		27: "[$-404]e/m/d",
 		28: `[$-404]e"年"m"月"d"日"`,
 		29: `[$-404]e"年"m"月"d"日"`,
@@ -71,7 +71,7 @@ var langNumFmt = map[string]map[int]string{
 		57: "[$-404]e/m/d",
 		58: `[$-404]e"年"m"月"d"日"`,
 	},
-	"zh-cn": map[int]string{
+	"zh-cn": {
 		27: `yyyy"年"m"月"`,
 		28: `m"月"d"日"`,
 		29: `m"月"d"日"`,
@@ -92,7 +92,7 @@ var langNumFmt = map[string]map[int]string{
 		57: `yyyy"年"m"月"`,
 		58: `m"月"d"日"`,
 	},
-	"zh-tw_unicode": map[int]string{
+	"zh-tw_unicode": {
 		27: "[$-404]e/m/d",
 		28: `[$-404]e"5E74"m"6708"d"65E5"`,
 		29: `[$-404]e"5E74"m"6708"d"65E5"`,
@@ -113,7 +113,7 @@ var langNumFmt = map[string]map[int]string{
 		57: "[$-404]e/m/d",
 		58: `[$-404]e"5E74"m"6708"d"65E5"`,
 	},
-	"zh-cn_unicode": map[int]string{
+	"zh-cn_unicode": {
 		27: `yyyy"5E74"m"6708"`,
 		28: `m"6708"d"65E5"`,
 		29: `m"6708"d"65E5"`,
@@ -134,7 +134,7 @@ var langNumFmt = map[string]map[int]string{
 		57: `yyyy"5E74"m"6708"`,
 		58: `m"6708"d"65E5"`,
 	},
-	"ja-jp": map[int]string{
+	"ja-jp": {
 		27: "[$-411]ge.m.d",
 		28: `[$-411]ggge"年"m"月"d"日"`,
 		29: `[$-411]ggge"年"m"月"d"日"`,
@@ -155,7 +155,7 @@ var langNumFmt = map[string]map[int]string{
 		57: "[$-411]ge.m.d",
 		58: `[$-411]ggge"年"m"月"d"日"`,
 	},
-	"ko-kr": map[int]string{
+	"ko-kr": {
 		27: `yyyy"年" mm"月" dd"日"`,
 		28: "mm-dd",
 		29: "mm-dd",
@@ -176,7 +176,7 @@ var langNumFmt = map[string]map[int]string{
 		57: `yyyy"年" mm"月" dd"日"`,
 		58: "mm-dd",
 	},
-	"ja-jp_unicode": map[int]string{
+	"ja-jp_unicode": {
 		27: "[$-411]ge.m.d",
 		28: `[$-411]ggge"5E74"m"6708"d"65E5"`,
 		29: `[$-411]ggge"5E74"m"6708"d"65E5"`,
@@ -197,7 +197,7 @@ var langNumFmt = map[string]map[int]string{
 		57: "[$-411]ge.m.d",
 		58: `[$-411]ggge"5E74"m"6708"d"65E5"`,
 	},
-	"ko-kr_unicode": map[int]string{
+	"ko-kr_unicode": {
 		27: `yyyy"5E74" mm"6708" dd"65E5"`,
 		28: "mm-dd",
 		29: "mm-dd",
@@ -218,7 +218,7 @@ var langNumFmt = map[string]map[int]string{
 		57: `yyyy"5E74" mm"6708" dd"65E5"`,
 		58: "mm-dd",
 	},
-	"th-th": map[int]string{
+	"th-th": {
 		59: "t0",
 		60: "t0.00",
 		61: "t#,##0",
@@ -239,7 +239,7 @@ var langNumFmt = map[string]map[int]string{
 		80: "นน:ทท.0",
 		81: "d/m/bb",
 	},
-	"th-th_unicode": map[int]string{
+	"th-th_unicode": {
 		59: "t0",
 		60: "t0.00",
 		61: "t#,##0",

+ 24 - 14
xmlStyles.go

@@ -35,6 +35,15 @@ type xlsxAlignment struct {
 	WrapText        bool   `xml:"wrapText,attr,omitempty"`
 }
 
+// xlsxProtection (Protection Properties) contains protection properties
+// associated with the cell. Each cell has protection properties that can be
+// set. The cell protection properties do not take effect unless the sheet has
+// been protected.
+type xlsxProtection struct {
+	Hidden bool `xml:"hidden,attr"`
+	Locked bool `xml:"locked,attr"`
+}
+
 // xlsxLine directly maps the line style element in the namespace
 // http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
 // not checked it for completeness - it does as much as I need.
@@ -190,20 +199,21 @@ type xlsxCellStyleXfs struct {
 // xlsxXf directly maps the xf element. A single xf element describes all of the
 // formatting for a cell.
 type xlsxXf struct {
-	ApplyAlignment    bool           `xml:"applyAlignment,attr"`
-	ApplyBorder       bool           `xml:"applyBorder,attr"`
-	ApplyFill         bool           `xml:"applyFill,attr"`
-	ApplyFont         bool           `xml:"applyFont,attr"`
-	ApplyNumberFormat bool           `xml:"applyNumberFormat,attr"`
-	ApplyProtection   bool           `xml:"applyProtection,attr"`
-	BorderID          int            `xml:"borderId,attr"`
-	FillID            int            `xml:"fillId,attr"`
-	FontID            int            `xml:"fontId,attr"`
-	NumFmtID          int            `xml:"numFmtId,attr"`
-	PivotButton       bool           `xml:"pivotButton,attr,omitempty"`
-	QuotePrefix       bool           `xml:"quotePrefix,attr,omitempty"`
-	XfID              *int           `xml:"xfId,attr,omitempty"`
-	Alignment         *xlsxAlignment `xml:"alignment"`
+	ApplyAlignment    bool            `xml:"applyAlignment,attr"`
+	ApplyBorder       bool            `xml:"applyBorder,attr"`
+	ApplyFill         bool            `xml:"applyFill,attr"`
+	ApplyFont         bool            `xml:"applyFont,attr"`
+	ApplyNumberFormat bool            `xml:"applyNumberFormat,attr"`
+	ApplyProtection   bool            `xml:"applyProtection,attr"`
+	BorderID          int             `xml:"borderId,attr"`
+	FillID            int             `xml:"fillId,attr"`
+	FontID            int             `xml:"fontId,attr"`
+	NumFmtID          int             `xml:"numFmtId,attr"`
+	PivotButton       bool            `xml:"pivotButton,attr,omitempty"`
+	QuotePrefix       bool            `xml:"quotePrefix,attr,omitempty"`
+	XfID              *int            `xml:"xfId,attr,omitempty"`
+	Alignment         *xlsxAlignment  `xml:"alignment"`
+	Protection        *xlsxProtection `xml:"protection"`
 }
 
 // xlsxCellXfs directly maps the cellXfs element. This element contains the

+ 2 - 2
xmlWorkbook.go

@@ -203,7 +203,7 @@ type xlsxDefinedName struct {
 	FunctionGroupID   int    `xml:"functionGroupId,attr,omitempty"`
 	Help              string `xml:"help,attr,omitempty"`
 	Hidden            bool   `xml:"hidden,attr,omitempty"`
-	LocalSheetID      int    `xml:"localSheetId,attr,omitempty"`
+	LocalSheetID      int    `xml:"localSheetId,attr"`
 	Name              string `xml:"name,attr,omitempty"`
 	PublishToServer   bool   `xml:"publishToServer,attr,omitempty"`
 	ShortcutKey       string `xml:"shortcutKey,attr,omitempty"`
@@ -223,7 +223,7 @@ type xlsxCalcPr struct {
 	CalcID                string  `xml:"calcId,attr,omitempty"`
 	CalcMode              string  `xml:"calcMode,attr,omitempty"`
 	CalcOnSave            bool    `xml:"calcOnSave,attr,omitempty"`
-	ConcurrentCalc        bool    `xml:"concurrentCalc,attr,omitempty"`
+	ConcurrentCalc        *bool   `xml:"concurrentCalc,attr"`
 	ConcurrentManualCount int     `xml:"concurrentManualCount,attr,omitempty"`
 	ForceFullCalc         bool    `xml:"forceFullCalc,attr,omitempty"`
 	FullCalcOnLoad        bool    `xml:"fullCalcOnLoad,attr,omitempty"`

+ 37 - 21
xmlWorksheet.go

@@ -15,7 +15,8 @@ type xlsxWorksheet struct {
 	SheetData             xlsxSheetData                `xml:"sheetData"`
 	SheetProtection       *xlsxSheetProtection         `xml:"sheetProtection"`
 	AutoFilter            *xlsxAutoFilter              `xml:"autoFilter"`
-	MergeCells            *xlsxMergeCells              `xml:"mergeCells,omitempty"`
+	MergeCells            *xlsxMergeCells              `xml:"mergeCells"`
+	PhoneticPr            *xlsxPhoneticPr              `xml:"phoneticPr"`
 	ConditionalFormatting []*xlsxConditionalFormatting `xml:"conditionalFormatting"`
 	DataValidations       *xlsxDataValidations         `xml:"dataValidations"`
 	Hyperlinks            *xlsxHyperlinks              `xml:"hyperlinks"`
@@ -73,7 +74,7 @@ type xlsxPageSetUp struct {
 	Draft              bool    `xml:"draft,attr,omitempty"`
 	Errors             string  `xml:"errors,attr,omitempty"`
 	FirstPageNumber    int     `xml:"firstPageNumber,attr,omitempty"`
-	FitToHeight        int     `xml:"fitToHeight,attr,omitempty"`
+	FitToHeight        *int    `xml:"fitToHeight,attr"`
 	FitToWidth         int     `xml:"fitToWidth,attr,omitempty"`
 	HorizontalDPI      float32 `xml:"horizontalDpi,attr,omitempty"`
 	RID                string  `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
@@ -144,24 +145,26 @@ type xlsxSheetViews struct {
 // multiple windows are viewing the same sheet, multiple sheetView elements
 // (with corresponding workbookView entries) are saved.
 type xlsxSheetView struct {
-	WindowProtection        bool             `xml:"windowProtection,attr,omitempty"`
-	ShowFormulas            bool             `xml:"showFormulas,attr,omitempty"`
-	ShowGridLines           string           `xml:"showGridLines,attr,omitempty"`
-	ShowRowColHeaders       bool             `xml:"showRowColHeaders,attr,omitempty"`
-	ShowZeros               bool             `xml:"showZeros,attr,omitempty"`
-	RightToLeft             bool             `xml:"rightToLeft,attr,omitempty"`
-	TabSelected             bool             `xml:"tabSelected,attr,omitempty"`
-	ShowOutlineSymbols      bool             `xml:"showOutlineSymbols,attr,omitempty"`
-	DefaultGridColor        bool             `xml:"defaultGridColor,attr"`
-	View                    string           `xml:"view,attr,omitempty"`
-	TopLeftCell             string           `xml:"topLeftCell,attr,omitempty"`
-	ColorID                 int              `xml:"colorId,attr,omitempty"`
-	ZoomScale               float64          `xml:"zoomScale,attr,omitempty"`
-	ZoomScaleNormal         float64          `xml:"zoomScaleNormal,attr,omitempty"`
-	ZoomScalePageLayoutView float64          `xml:"zoomScalePageLayoutView,attr,omitempty"`
-	WorkbookViewID          int              `xml:"workbookViewId,attr"`
-	Pane                    *xlsxPane        `xml:"pane,omitempty"`
-	Selection               []*xlsxSelection `xml:"selection"`
+	WindowProtection         bool             `xml:"windowProtection,attr,omitempty"`
+	ShowFormulas             bool             `xml:"showFormulas,attr,omitempty"`
+	ShowGridLines            string           `xml:"showGridLines,attr,omitempty"`
+	ShowRowColHeaders        bool             `xml:"showRowColHeaders,attr,omitempty"`
+	ShowZeros                bool             `xml:"showZeros,attr,omitempty"`
+	RightToLeft              bool             `xml:"rightToLeft,attr,omitempty"`
+	TabSelected              bool             `xml:"tabSelected,attr,omitempty"`
+	ShowWhiteSpace           *bool            `xml:"showWhiteSpace,attr"`
+	ShowOutlineSymbols       bool             `xml:"showOutlineSymbols,attr,omitempty"`
+	DefaultGridColor         bool             `xml:"defaultGridColor,attr"`
+	View                     string           `xml:"view,attr,omitempty"`
+	TopLeftCell              string           `xml:"topLeftCell,attr,omitempty"`
+	ColorID                  int              `xml:"colorId,attr,omitempty"`
+	ZoomScale                float64          `xml:"zoomScale,attr,omitempty"`
+	ZoomScaleNormal          float64          `xml:"zoomScaleNormal,attr,omitempty"`
+	ZoomScalePageLayoutView  float64          `xml:"zoomScalePageLayoutView,attr,omitempty"`
+	ZoomScaleSheetLayoutView float64          `xml:"zoomScaleSheetLayoutView,attr,omitempty"`
+	WorkbookViewID           int              `xml:"workbookViewId,attr"`
+	Pane                     *xlsxPane        `xml:"pane,omitempty"`
+	Selection                []*xlsxSelection `xml:"selection"`
 }
 
 // xlsxSelection directly maps the selection element in the namespace
@@ -189,7 +192,7 @@ type xlsxPane struct {
 type xlsxSheetPr struct {
 	XMLName                           xml.Name         `xml:"sheetPr"`
 	CodeName                          string           `xml:"codeName,attr,omitempty"`
-	EnableFormatConditionsCalculation bool             `xml:"enableFormatConditionsCalculation,attr,omitempty"`
+	EnableFormatConditionsCalculation *bool            `xml:"enableFormatConditionsCalculation,attr"`
 	FilterMode                        bool             `xml:"filterMode,attr,omitempty"`
 	Published                         bool             `xml:"published,attr,omitempty"`
 	SyncHorizontal                    bool             `xml:"syncHorizontal,attr,omitempty"`
@@ -344,6 +347,19 @@ type xlsxSheetProtection struct {
 	SpinCount          int    `xml:"spinCount,attr,omitempty"`
 }
 
+// xlsxPhoneticPr (Phonetic Properties) represents a collection of phonetic
+// properties that affect the display of phonetic text for this String Item
+// (si). Phonetic text is used to give hints as to the pronunciation of an East
+// Asian language, and the hints are displayed as text within the spreadsheet
+// cells across the top portion of the cell. Since the phonetic hints are text,
+// every phonetic hint is expressed as a phonetic run (rPh), and these
+// properties specify how to display that phonetic run.
+type xlsxPhoneticPr struct {
+	Alignment string `xml:"alignment,attr,omitempty"`
+	FontID    int    `xml:"fontId,attr,omitempty"`
+	Type      string `xml:"type,attr,omitempty"`
+}
+
 // A Conditional Format is a format, such as cell shading or font color, that a
 // spreadsheet application can automatically apply to cells if a specified
 // condition is true. This collection expresses conditional formatting rules