Browse Source

Stype Api test

DamianSzkuat 6 years ago
parent
commit
37a275d5ca
3 changed files with 87 additions and 0 deletions
  1. BIN
      Workbook_newStyle.xlsx
  2. 74 0
      stream_test.go
  3. 13 0
      style.go

BIN
Workbook_newStyle.xlsx


+ 74 - 0
stream_test.go

@@ -556,3 +556,77 @@ func (s *StreamSuite) TestCloseWithNothingWrittenToSheets(t *C) {
 		t.Fatal("Expected workbook data to be equal")
 	}
 }
+
+func (s *StreamSuite) TestMakeNewStyleAndUseIt(t *C){
+	var filePath string
+	var buffer bytes.Buffer
+	if TestsShouldMakeRealFiles {
+		filePath = fmt.Sprintf("Workbook_newStyle.xlsx")
+	}
+
+	timesNewRoman12 := NewFont(12,TimesNewRoman)
+	timesNewRoman12.Color = RGB_Dard_Green
+	courier20:= NewFont(12, Courier)
+	courier20.Color = RGB_Dark_Red
+
+	greenFill := NewFill(Solid_Cell_Fill, RGB_Light_Green, RGB_White)
+	redFill   := NewFill(Solid_Cell_Fill, RGB_Light_Red,   RGB_White)
+
+	greenStyle := MakeStyle(0, *timesNewRoman12, *greenFill, *DefaultAlignment() , *DefaultBorder())
+	redStyle :=   MakeStyle(0, *courier20, *redFill, *DefaultAlignment(), *DefaultBorder())
+
+	sheetNames := []string{"Sheet1"}
+	workbookData := [][][]string{
+		{
+			{"Header1", "Header2"},
+			{"Good", "Bad"},
+		},
+	}
+	cellStyles := [][][]*StreamStyle{
+		{
+			{DefaultStringStyle, DefaultStringStyle},
+			{greenStyle,         redStyle},
+		},
+	}
+	cellTypes := [][][]*CellType{
+		{
+			{CellTypeString.Ptr(), CellTypeString.Ptr()},
+			{CellTypeString.Ptr(), CellTypeString.Ptr()},
+		},
+	}
+
+	err := writeStreamFile(filePath, &buffer, sheetNames, workbookData, cellStyles, cellTypes, TestsShouldMakeRealFiles)
+
+	if err != nil {
+		t.Fatal("Error during writing")
+	}
+
+	// read the file back with the xlsx package
+	var bufReader *bytes.Reader
+	var size int64
+	if !TestsShouldMakeRealFiles {
+		bufReader = bytes.NewReader(buffer.Bytes())
+		size = bufReader.Size()
+	}
+	actualSheetNames, actualWorkbookData := readXLSXFile(t, filePath, bufReader, size, TestsShouldMakeRealFiles)
+	// check if data was able to be read correctly
+	if !reflect.DeepEqual(actualSheetNames, sheetNames) {
+		t.Fatal("Expected sheet names to be equal")
+	}
+	if !reflect.DeepEqual(actualWorkbookData, workbookData) {
+		t.Fatal("Expected workbook data to be equal")
+	}
+}
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 13 - 0
style.go

@@ -12,6 +12,19 @@ const (
 	Courier = "Courier"
 )
 
+const (
+	RGB_Light_Green = "FFC6EFCE"
+	RGB_Dard_Green  = "FF006100"
+	RGB_Light_Red   = "FFFFC7CE"
+	RGB_Dark_Red     = "FF9C0006"
+	RGB_White 		= "00000000"
+	RGB_Black 		= "FFFFFFFF"
+)
+
+const (
+	Solid_Cell_Fill = "solid"
+)
+
 // Style is a high level structure intended to provide user access to
 // the contents of Style within an XLSX file.
 type Style struct {