DamianSzkuat 6 years ago
parent
commit
319ba3bd5f
4 changed files with 43 additions and 33 deletions
  1. 6 6
      stream_cell.go
  2. 0 1
      stream_file.go
  3. 13 5
      stream_file_builder.go
  4. 24 21
      stream_style.go

+ 6 - 6
stream_cell.go

@@ -5,14 +5,14 @@ import (
 	"time"
 )
 
-// StreamCell holds the data, style and type of cell for streaming
+// StreamCell holds the data, style and type of cell for streaming.
 type StreamCell struct {
 	cellData  string
 	cellStyle StreamStyle
 	cellType  CellType
 }
 
-// NewStreamCell creates a new StreamCell
+// NewStreamCell creates a new cell containing the given data with the given style and type.
 func NewStreamCell(cellData string, cellStyle StreamStyle, cellType CellType) StreamCell {
 	return StreamCell{
 		cellData:  cellData,
@@ -21,12 +21,12 @@ func NewStreamCell(cellData string, cellStyle StreamStyle, cellType CellType) St
 	}
 }
 
-// NewStringStreamCell creates a new cell that holds string data, is of type string and uses general formatting
+// NewStringStreamCell creates a new cell that holds string data, is of type string and uses general formatting.
 func NewStringStreamCell(cellData string) StreamCell {
 	return NewStreamCell(cellData, StreamStyleDefaultString, CellTypeString)
 }
 
-// NewStyledStringStreamCell creates a new cell that holds a string and is styled according to the given style
+// NewStyledStringStreamCell creates a new cell that holds a string and is styled according to the given style.
 func NewStyledStringStreamCell(cellData string, cellStyle StreamStyle) StreamCell {
 	return NewStreamCell(cellData, cellStyle, CellTypeString)
 }
@@ -43,8 +43,8 @@ func NewStyledIntegerStreamCell(cellData int, cellStyle StreamStyle) StreamCell
 	return NewStreamCell(strconv.Itoa(cellData), cellStyle, CellTypeNumeric)
 }
 
-// NewDateStreamCell creates a new cell that holds a date value and is formatted as dd-mm-yyyy and
-// and is of type numeric
+// NewDateStreamCell creates a new cell that holds a date value and is formatted as dd-mm-yyyy
+// and is of type numeric.
 func NewDateStreamCell(t time.Time) StreamCell {
 	excelTime := TimeToExcelTime(t, false)
 	return NewStreamCell(strconv.Itoa(int(excelTime)), StreamStyleDefaultDate, CellTypeNumeric)

+ 0 - 1
stream_file.go

@@ -229,7 +229,6 @@ func makeXlsxCell(cellType CellType, cellCoordinate string, cellStyleId int, cel
 	case CellTypeString:
 		// TODO Currently shared strings are types as inline strings
 		return xlsxC{XMLName: xml.Name{Local: "c"}, R: cellCoordinate, S: cellStyleId, T: "inlineStr", Is: &xlsxSI{T: cellData}}, nil
-		// return "s", nil
 	case CellTypeStringFormula:
 		// TODO currently not supported
 		return xlsxC{}, UnsupportedCellTypeError

+ 13 - 5
stream_file_builder.go

@@ -11,14 +11,22 @@
 // 5. Call NextSheet() to proceed to the next sheet. Once NextSheet() is called, the previous sheet can not be edited.
 // 6. Call Close() to finish.
 
+// Directions for using custom styles and different data types:
+// 1. Create a StreamFileBuilder with NewStreamFileBuilder() or NewStreamFileBuilderForPath().
+// 2. Use MakeStyle() to create the styles you want yo use in your document. Keep a list of these styles.
+// 3. Add all the styles you created by using AddStreamStyle() or AddStreamStyleList().
+// 4. Add the sheets and their column styles of data by calling AddSheetS().
+// 5. Call Build() to get a StreamFile. Once built, all functions on the builder will return an error.
+// 6. Write to the StreamFile with WriteS(). Writes begin on the first sheet. New rows are always written and flushed
+// to the io. All rows written to the same sheet must have the same number of cells as the number of column styles
+// provided when adding the sheet with AddSheetS() or an error will be returned.
+// 5. Call NextSheet() to proceed to the next sheet. Once NextSheet() is called, the previous sheet can not be edited.
+// 6. Call Close() to finish.
+
 // Future work suggestions:
-// Currently the only supported cell type is string, since the main reason this library was written was to prevent
-// strings from being interpreted as numbers. It would be nice to have support for numbers and money so that the exported
-// files could better take advantage of XLSX's features.
-// All text is written with the same text style. Support for additional text styles could be added to highlight certain
-// data in the file.
 // The current default style uses fonts that are not on Macs by default so opening the XLSX files in Numbers causes a
 // pop up that says there are missing fonts. The font could be changed to something that is usually found on Mac and PC.
+// Extend support for Formulas and Shared Strings.
 
 package xlsx
 

+ 24 - 21
stream_style.go

@@ -15,29 +15,33 @@ const (
 	DateTimeFormat_d_m_yy_h_mm = 22
 )
 
-var StreamStyleFromColumn StreamStyle
+var (
+	StreamStyleFromColumn StreamStyle
 
-var StreamStyleDefaultString StreamStyle
-var StreamStyleBoldString StreamStyle
-var StreamStyleItalicString StreamStyle
-var StreamStyleUnderlinedString StreamStyle
+	StreamStyleDefaultString    StreamStyle
+	StreamStyleBoldString       StreamStyle
+	StreamStyleItalicString     StreamStyle
+	StreamStyleUnderlinedString StreamStyle
 
-var StreamStyleDefaultInteger StreamStyle
-var StreamStyleBoldInteger StreamStyle
-var StreamStyleItalicInteger StreamStyle
-var StreamStyleUnderlinedInteger StreamStyle
+	StreamStyleDefaultInteger    StreamStyle
+	StreamStyleBoldInteger       StreamStyle
+	StreamStyleItalicInteger     StreamStyle
+	StreamStyleUnderlinedInteger StreamStyle
 
-var StreamStyleDefaultDate StreamStyle
+	StreamStyleDefaultDate StreamStyle
 
-var StreamStyleDefaultDecimal StreamStyle
-
-var FontBold *Font
-var FontItalic *Font
-var FontUnderlined *Font
-
-var FillGreen *Fill
-var FillRed *Fill
-var FillWhite *Fill
+	StreamStyleDefaultDecimal StreamStyle
+)
+var (
+	FontBold       *Font
+	FontItalic     *Font
+	FontUnderlined *Font
+)
+var (
+	FillGreen *Fill
+	FillRed   *Fill
+	FillWhite *Fill
+)
 
 func init() {
 	// Init Fonts
@@ -72,8 +76,7 @@ func init() {
 	StreamStyleDefaultDecimal = MakeDecimalStyle(DefaultFont(), DefaultFill(), DefaultAlignment(), DefaultBorder())
 }
 
-// MakeStyle creates a new StreamStyle and add it to the styles that will be streamed
-// This function returns a reference to the created StreamStyle
+// MakeStyle creates a new StreamStyle and add it to the styles that will be streamed.
 func MakeStyle(formatStyleId int, font *Font, fill *Fill, alignment *Alignment, border *Border) StreamStyle {
 	newStyle := NewStyle()