|
|
@@ -163,56 +163,34 @@ func (sf *StreamFile) writeS(cells []StreamCell) error {
|
|
|
|
|
|
// Add cells one by one
|
|
|
for colIndex, cell := range cells {
|
|
|
- // Get the cell reference (location)
|
|
|
- cellCoordinate := GetCellIDStringFromCoords(colIndex, sf.currentSheet.rowCount-1)
|
|
|
-
|
|
|
- // Get the cell type string
|
|
|
- cellType, err := getCellTypeAsString(cell.cellType)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
-
|
|
|
- // Build the XML cell opening
|
|
|
- cellOpen := `<c r="` + cellCoordinate + `" t="` + cellType + `"`
|
|
|
- // Add in the style id of the stream cell.
|
|
|
- if idx, ok := sf.styleIdMap[cell.cellStyle]; ok {
|
|
|
- cellOpen += ` s="` + strconv.Itoa(idx) + `"`
|
|
|
- } else {
|
|
|
- return errors.New("trying to make use of a style that has not been added")
|
|
|
- }
|
|
|
- cellOpen += `>`
|
|
|
|
|
|
- // The XML cell contents
|
|
|
- cellContentsOpen, cellContentsClose, err := getCellContentOpenAncCloseTags(cell.cellType)
|
|
|
- if err != nil {
|
|
|
+ cellParts, err := sf.marshallCell(cell, colIndex)
|
|
|
+ if err != nil{
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- // The XMl cell ending
|
|
|
- cellClose := `</c>`
|
|
|
-
|
|
|
// Write the cell opening
|
|
|
- if err := sf.currentSheet.write(cellOpen); err != nil {
|
|
|
+ if err := sf.currentSheet.write(cellParts["cellOpen"]); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
// Write the cell contents opening
|
|
|
- if err := sf.currentSheet.write(cellContentsOpen); err != nil {
|
|
|
+ if err := sf.currentSheet.write(cellParts["cellContentsOpen"]); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
// Write cell contents
|
|
|
- if err := xml.EscapeText(sf.currentSheet.writer, []byte(cell.cellData)); err != nil {
|
|
|
+ if err := xml.EscapeText(sf.currentSheet.writer, []byte(cellParts["cellContents"])); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
// Write cell contents ending
|
|
|
- if err := sf.currentSheet.write(cellContentsClose); err != nil {
|
|
|
+ if err := sf.currentSheet.write(cellParts["cellContentsClose"]); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
// Write the cell ending
|
|
|
- if err := sf.currentSheet.write(cellClose); err != nil {
|
|
|
+ if err := sf.currentSheet.write(cellParts["cellClose"]); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
@@ -223,6 +201,52 @@ func (sf *StreamFile) writeS(cells []StreamCell) error {
|
|
|
return sf.zipWriter.Flush()
|
|
|
}
|
|
|
|
|
|
+func (sf *StreamFile) marshallCell(cell StreamCell, colIndex int) (map[string]string, error) {
|
|
|
+ // Get the cell reference (location)
|
|
|
+ cellCoordinate := GetCellIDStringFromCoords(colIndex, sf.currentSheet.rowCount-1)
|
|
|
+
|
|
|
+ // Get the cell type string
|
|
|
+ cellType, err := getCellTypeAsString(cell.cellType)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ cellParts := make(map[string]string)
|
|
|
+
|
|
|
+ // Build the XML cell opening
|
|
|
+ cellOpen := `<c r="` + cellCoordinate + `" t="` + cellType + `"`
|
|
|
+ // Add in the style id of the stream cell. If the streamStyle is empty, don't add a style,
|
|
|
+ // default column style will be used
|
|
|
+ if cell.cellStyle != (StreamStyle{}){
|
|
|
+ if idx, ok := sf.styleIdMap[cell.cellStyle]; ok {
|
|
|
+ cellOpen += ` s="` + strconv.Itoa(idx) + `"`
|
|
|
+ } else {
|
|
|
+ return nil, errors.New("trying to make use of a style that has not been added")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ cellOpen += `>`
|
|
|
+
|
|
|
+ cellParts["cellOpen"] = cellOpen
|
|
|
+
|
|
|
+ // The XML cell contents
|
|
|
+ cellContentsOpen, cellContentsClose, err := getCellContentOpenAncCloseTags(cell.cellType)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ cellParts["cellContentsOpen"] = cellContentsOpen
|
|
|
+ cellParts["cellContentsClose"] = cellContentsClose
|
|
|
+
|
|
|
+ cellParts["cellContents"] = cell.cellData
|
|
|
+
|
|
|
+ // The XMl cell ending
|
|
|
+ cellClose := `</c>`
|
|
|
+
|
|
|
+ cellParts["cellClose"] = cellClose
|
|
|
+
|
|
|
+ return cellParts, nil
|
|
|
+}
|
|
|
+
|
|
|
func getCellTypeAsString(cellType CellType) (string, error) {
|
|
|
// documentation for the c.t (cell.Type) attribute:
|
|
|
// b (Boolean): Cell containing a boolean.
|