DamianSzkuat 6 лет назад
Родитель
Сommit
1be083cc2b
4 измененных файлов с 14 добавлено и 13 удалено
  1. 1 0
      stream_file.go
  2. 4 4
      stream_style_test.go
  3. 7 7
      stream_test/stream_server.go
  4. 2 2
      style.go

+ 1 - 0
stream_file.go

@@ -218,6 +218,7 @@ func makeXlsxCell(cellType CellType, cellCoordinate string, cellStyleId int, cel
 	case CellTypeBool:
 		return xlsxC{XMLName: xml.Name{Local: "c"}, R: cellCoordinate, S: cellStyleId, T: "b", V: cellData}, nil
 	case CellTypeDate:
+		// Dates are better represented using CellTyleNumeric and the date formatting
 		return xlsxC{XMLName: xml.Name{Local: "c"}, R: cellCoordinate, S: cellStyleId, T: "d", V: cellData}, nil
 	case CellTypeError:
 		return xlsxC{XMLName: xml.Name{Local: "c"}, R: cellCoordinate, S: cellStyleId, T: "e", V: cellData}, nil

+ 4 - 4
stream_style_test.go

@@ -294,7 +294,7 @@ func (s *StreamStyleSuite) TestXlsxStreamWriteWithStyle(t *C) {
 		for j, _ := range testCase.workbookData {
 			expectedWorkbookDataStrings = append(expectedWorkbookDataStrings, [][]string{})
 			for k, _ := range testCase.workbookData[j] {
-				if len(testCase.workbookData[j][k])==0{
+				if len(testCase.workbookData[j][k]) == 0 {
 					expectedWorkbookDataStrings[j] = append(expectedWorkbookDataStrings[j], nil)
 				} else {
 					expectedWorkbookDataStrings[j] = append(expectedWorkbookDataStrings[j], []string{})
@@ -466,7 +466,7 @@ func (s *StreamStyleSuite) TestDates(t *C) {
 		monthString = "0" + monthString
 	}
 	expectedWorkbookDataStrings[0][1] = append(expectedWorkbookDataStrings[0][1],
-		monthString + "-" + strconv.Itoa(day) + "-" + strconv.Itoa(year-2000))
+		monthString+"-"+strconv.Itoa(day)+"-"+strconv.Itoa(year-2000))
 
 	if !reflect.DeepEqual(actualWorkbookData, expectedWorkbookDataStrings) {
 		t.Fatal("Expected workbook data to be equal")
@@ -667,7 +667,7 @@ func (s *StreamStyleSuite) TestAddSheetWithStyleErrorsAfterBuild(t *C) {
 func checkForCorrectCellStyles(actualCells [][][]Cell, expectedCells [][][]StreamCell) error {
 	for i, _ := range actualCells {
 		for j, _ := range actualCells[i] {
-			for k, actualCell := range actualCells[i][j]{
+			for k, actualCell := range actualCells[i][j] {
 				expectedCell := expectedCells[i][j][k]
 				if err := compareCellStyles(actualCell, expectedCell); err != nil {
 					return err
@@ -693,4 +693,4 @@ func compareCellStyles(cellA Cell, cellB StreamCell) error {
 	}
 
 	return nil
-}
+}

+ 7 - 7
stream_test/stream_server.go

@@ -3,14 +3,14 @@ package main
 import (
 	. "github.com/damianszkuat/xlsx"
 	"io"
+	"math/rand"
 	"net/http"
 	"strconv"
-	"math/rand"
 )
 
 func StreamFileWithDate(w http.ResponseWriter, r *http.Request) {
 	w.Header().Add("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
-	sheetNames, workbookData := generateExcelFile(1, 1000000, 10)
+	sheetNames, workbookData := generateExcelFile(2, 500000, 10)
 	writeStreamFileWithStyle(w, sheetNames, workbookData, []StreamStyle{})
 }
 
@@ -72,15 +72,15 @@ func writeStreamFileWithStyle(fileBuffer io.Writer, sheetNames []string,
 func generateExcelFile(numOfSheets int, numOfRows int, numOfCols int) ([]string, [][][]StreamCell) {
 	var sheetNames []string
 	var workbookData [][][]StreamCell
-	for i := 0; i<numOfSheets; i++{
+	for i := 0; i < numOfSheets; i++ {
 		sheetNames = append(sheetNames, strconv.Itoa(i))
 		workbookData = append(workbookData, [][]StreamCell{})
-		for j := 0; j<numOfRows; j++ {
+		for j := 0; j < numOfRows; j++ {
 			workbookData[i] = append(workbookData[i], []StreamCell{})
-			for k := 0; k<numOfCols; k++ {
+			for k := 0; k < numOfCols; k++ {
 				var style StreamStyle
 
-				if k%2==0 {
+				if k%2 == 0 {
 					style = StreamStyleDefaultInteger
 				} else if k%3 == 0 {
 					style = StreamStyleBoldInteger
@@ -90,7 +90,7 @@ func generateExcelFile(numOfSheets int, numOfRows int, numOfCols int) ([]string,
 					style = StreamStyleUnderlinedInteger
 				}
 
-				workbookData[i][j] = append(workbookData[i][j], NewStyledIntegerStreamCell(rand.Intn(100),style))
+				workbookData[i][j] = append(workbookData[i][j], NewStyledIntegerStreamCell(rand.Intn(100), style))
 			}
 		}
 	}

+ 2 - 2
style.go

@@ -17,8 +17,8 @@ const (
 	RGB_Dard_Green  = "FF006100"
 	RGB_Light_Red   = "FFFFC7CE"
 	RGB_Dark_Red    = "FF9C0006"
-	RGB_White 		= "00000000"
-	RGB_Black 		= "FFFFFFFF"
+	RGB_White       = "00000000"
+	RGB_Black       = "FFFFFFFF"
 )
 
 const (