DamianSzkuat %!s(int64=6) %!d(string=hai) anos
pai
achega
1fe1bb9ca7
Modificáronse 5 ficheiros con 43 adicións e 73 borrados
  1. 1 2
      row.go
  2. 3 3
      stream_cell.go
  3. 23 50
      stream_file_builder.go
  4. 15 15
      stream_style.go
  5. 1 3
      xmlWorksheet.go

+ 1 - 2
row.go

@@ -35,7 +35,6 @@ func (r *Row) AddStreamCell(streamCell StreamCell) {
 	cell.NumFmt = builtInNumFmt[streamCell.cellStyle.xNumFmtId]
 	cell.cellType = streamCell.cellType
 	r.Cells = append(r.Cells, cell)
+	// TODO
 	r.Sheet.maybeAddCol(len(r.Cells))
 }
-
-

+ 3 - 3
stream_cell.go

@@ -13,7 +13,7 @@ type StreamCell struct {
 }
 
 // NewStreamCell creates a new StreamCell
-func NewStreamCell(cellData string, cellStyle StreamStyle, cellType CellType) StreamCell{
+func NewStreamCell(cellData string, cellStyle StreamStyle, cellType CellType) StreamCell {
 	return StreamCell{
 		cellData:  cellData,
 		cellStyle: cellStyle,
@@ -22,7 +22,7 @@ func NewStreamCell(cellData string, cellStyle StreamStyle, cellType CellType) St
 }
 
 // MakeStringStreamCell creates a new cell that holds string data, is of type string and uses general formatting
-func MakeStringStreamCell(cellData string) StreamCell{
+func MakeStringStreamCell(cellData string) StreamCell {
 	return NewStreamCell(cellData, Strings, CellTypeString)
 }
 
@@ -48,4 +48,4 @@ func MakeStyledIntegerStreamCell(cellData int, cellStyle StreamStyle) StreamCell
 func MakeDateStreamCell(t time.Time) StreamCell {
 	excelTime := TimeToExcelTime(t, false)
 	return NewStreamCell(strconv.Itoa(int(excelTime)), Dates, CellTypeNumeric)
-}
+}

+ 23 - 50
stream_file_builder.go

@@ -33,16 +33,16 @@ import (
 )
 
 type StreamFileBuilder struct {
-	built              	bool
-	firstSheetAdded    	bool
-	customStylesAdded  	bool
-	xlsxFile           	*File
-	zipWriter          	*zip.Writer
-	cellTypeToStyleIds 	map[CellType]int
-	maxStyleId         	int
-	styleIds           	[][]int
-	customStreamStyles	map[StreamStyle]struct{}
-	styleIdMap		   	map[StreamStyle]int
+	built              bool
+	firstSheetAdded    bool
+	customStylesAdded  bool
+	xlsxFile           *File
+	zipWriter          *zip.Writer
+	cellTypeToStyleIds map[CellType]int
+	maxStyleId         int
+	styleIds           [][]int
+	customStreamStyles map[StreamStyle]struct{}
+	styleIdMap         map[StreamStyle]int
 }
 
 const (
@@ -66,7 +66,7 @@ func NewStreamFileBuilder(writer io.Writer) *StreamFileBuilder {
 		cellTypeToStyleIds: make(map[CellType]int),
 		maxStyleId:         initMaxStyleId,
 		customStreamStyles: make(map[StreamStyle]struct{}),
-		styleIdMap:			make(map[StreamStyle]int),
+		styleIdMap:         make(map[StreamStyle]int),
 	}
 }
 
@@ -143,7 +143,7 @@ func (sb *StreamFileBuilder) AddSheetWithStyle(name string, cells []StreamCell)
 	sb.firstSheetAdded = true
 
 	// Check if all styles in the headers have been created
-	for _,cell := range cells{
+	for _, cell := range cells {
 		if _, ok := sb.customStreamStyles[cell.cellStyle]; !ok {
 			return errors.New("trying to make use of a style that has not been added")
 		}
@@ -153,12 +153,13 @@ func (sb *StreamFileBuilder) AddSheetWithStyle(name string, cells []StreamCell)
 	sb.styleIds = append(sb.styleIds, []int{})
 
 	// Set the values of the first row and the the number of columns
-	row := sheet.AddRow()
-	if count := row.WriteCellSlice(cells, -1); count != len(cells) {
-		// Set built on error so that all subsequent calls to the builder will also fail.
-		sb.built = true
-		return errors.New("failed to write headers")
-	}
+	//row := sheet.AddRow()
+	//if count := row.WriteCellSlice(cells, -1); count != len(cells) {
+	//	// Set built on error so that all subsequent calls to the builder will also fail.
+	//	sb.built = true
+	//	return errors.New("failed to write headers")
+	//}
+	sheet.maybeAddCol(len(cells))
 
 	// Set default column types based on the cel types in the first row
 	for i, cell := range cells {
@@ -176,23 +177,12 @@ func (sb *StreamFileBuilder) Build() (*StreamFile, error) {
 	}
 	sb.built = true
 
-	//// Marshall Parts resets the style sheet, so to keep style information that has been added by the user
-	//// we have to marshal it beforehand and add it again after the entire file has been marshaled
-	//var xmlStylesSheetString string
-	//var err error
-	//if sb.customStylesAdded{
-	//	xmlStylesSheetString, err = sb.marshalStyles()
-	//	if err != nil {
-	//		return nil, err
-	//	}
-	//}
-
 	parts, err := sb.xlsxFile.MarshallParts()
 	if err != nil {
 		return nil, err
 	}
 
-	if sb.customStylesAdded{
+	if sb.customStylesAdded {
 		parts["xl/styles.xml"], err = sb.marshalStyles()
 		if err != nil {
 			return nil, err
@@ -242,7 +232,7 @@ func (sb *StreamFileBuilder) marshalStyles() (string, error) {
 	}
 
 	styleSheetXMLString, err := sb.xlsxFile.styles.Marshal()
-	if err!=nil {
+	if err != nil {
 		return "", err
 	}
 	return styleSheetXMLString, nil
@@ -264,23 +254,6 @@ func (sb *StreamFileBuilder) AddStreamStyle(streamStyle StreamStyle) error {
 	return nil
 }
 
-// AddStreamStyle adds a new style to the style sheet.
-// Only Styles that have been added through either this function or AddStreamStyleList will be usable.
-// This function cannot be used after AddSheetWithStyle has been called, and if it is
-// called after AddSheetWithStyle it will return an error.
-//func (sb *StreamFileBuilder) AddStreamStyle(streamStyle StreamStyle) error {
-//	if sb.firstSheetAdded {
-//		return errors.New("the style file has been built, cannot add new styles anymore")
-//	}
-//	if sb.xlsxFile.styles == nil {
-//		sb.xlsxFile.styles = newXlsxStyleSheet(sb.xlsxFile.theme)
-//	}
-//	XfId := handleStyleForXLSX(streamStyle.style, streamStyle.xNumFmtId, sb.xlsxFile.styles)
-//	sb.styleIdMap[streamStyle] = XfId
-//	sb.customStylesAdded = true
-//	return nil
-//}
-
 // AddStreamStyleList adds a list of new styles to the style sheet.
 // Only Styles that have been added through either this function or AddStreamStyle will be usable.
 // This function cannot be used after AddSheetWithStyle and Build has been called, and if it is
@@ -288,7 +261,7 @@ func (sb *StreamFileBuilder) AddStreamStyle(streamStyle StreamStyle) error {
 func (sb *StreamFileBuilder) AddStreamStyleList(streamStyles []StreamStyle) error {
 	for _, streamStyle := range streamStyles {
 		err := sb.AddStreamStyle(streamStyle)
-		if err != nil{
+		if err != nil {
 			return err
 		}
 	}
@@ -375,4 +348,4 @@ func splitSheetIntoPrefixAndSuffix(data string) (string, string, error) {
 		return "", "", errors.New("unexpected Sheet XML: SheetData close tag not found")
 	}
 	return sheetParts[0], sheetParts[1], nil
-}
+}

+ 15 - 15
stream_style.go

@@ -3,16 +3,16 @@ package xlsx
 // StreamStyle has style and formatting information.
 // Used to store a style for streaming
 type StreamStyle struct {
-	xNumFmtId	int
-	style 		*Style
+	xNumFmtId int
+	style     *Style
 }
 
 const (
-	GeneralFormat				= 0
-	IntegerFormat				= 1
-	DecimalFormat 				= 2
-	DateFormat_dd_mm_yy 		= 14
-	DateTimeFormat_d_m_yy_h_mm 	= 22
+	GeneralFormat              = 0
+	IntegerFormat              = 1
+	DecimalFormat              = 2
+	DateFormat_dd_mm_yy        = 14
+	DateTimeFormat_d_m_yy_h_mm = 22
 )
 
 var Strings StreamStyle
@@ -37,7 +37,7 @@ var GreenCell *Fill
 var RedCell *Fill
 var WhiteCel *Fill
 
-func init(){
+func init() {
 	// Init Fonts
 	Bold = DefaultFont()
 	Bold.Bold = true
@@ -86,8 +86,8 @@ func MakeStyle(formatStyleId int, font *Font, fill *Fill, alignment *Alignment,
 	newStyle.ApplyBorder = true
 
 	newStreamStyle := StreamStyle{
-		xNumFmtId: 	formatStyleId,
-		style: 		newStyle,
+		xNumFmtId: formatStyleId,
+		style:     newStyle,
 	}
 
 	// DefaultStyles = append(DefaultStyles, newStreamStyle)
@@ -96,25 +96,25 @@ func MakeStyle(formatStyleId int, font *Font, fill *Fill, alignment *Alignment,
 
 // MakeStringStyle creates a new style that can be used on cells with string data.
 // If used on other data the formatting might be wrong.
-func MakeStringStyle(font *Font, fill *Fill, alignment *Alignment, border *Border) StreamStyle{
+func MakeStringStyle(font *Font, fill *Fill, alignment *Alignment, border *Border) StreamStyle {
 	return MakeStyle(GeneralFormat, font, fill, alignment, border)
 }
 
 // MakeIntegerStyle creates a new style that can be used on cells with integer data.
 // If used on other data the formatting might be wrong.
-func MakeIntegerStyle(font *Font, fill *Fill, alignment *Alignment, border *Border) StreamStyle{
+func MakeIntegerStyle(font *Font, fill *Fill, alignment *Alignment, border *Border) StreamStyle {
 	return MakeStyle(IntegerFormat, font, fill, alignment, border)
 }
 
 // MakeDecimalStyle creates a new style that can be used on cells with decimal numeric data.
 // If used on other data the formatting might be wrong.
-func MakeDecimalStyle(font *Font, fill *Fill, alignment *Alignment, border *Border) StreamStyle{
+func MakeDecimalStyle(font *Font, fill *Fill, alignment *Alignment, border *Border) StreamStyle {
 	return MakeStyle(DecimalFormat, font, fill, alignment, border)
 }
 
 // MakeDateStyle creates a new style that can be used on cells with Date data.
 // The formatting used is: dd_mm_yy
 // If used on other data the formatting might be wrong.
-func MakeDateStyle(font *Font, fill *Fill, alignment *Alignment, border *Border) StreamStyle{
+func MakeDateStyle(font *Font, fill *Fill, alignment *Alignment, border *Border) StreamStyle {
 	return MakeStyle(DateFormat_dd_mm_yy, font, fill, alignment, border)
-}
+}

+ 1 - 3
xmlWorksheet.go

@@ -203,8 +203,6 @@ 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"`
 }
 
@@ -248,7 +246,7 @@ type xlsxMergeCell struct {
 }
 
 type xlsxMergeCells struct {
-	XMLName xml.Name        //`xml:"mergeCells,omitempty"`
+	XMLName xml.Name //`xml:"mergeCells,omitempty"`
 	Count   int             `xml:"count,attr,omitempty"`
 	Cells   []xlsxMergeCell `xml:"mergeCell,omitempty"`
 }