Skip to content

Generating big tables with time cells results with corrupted file #643

@ludmanp

Description

@ludmanp

Description

Generating big table with time columns output file is corrupted.

Steps to reproduce the issue:
here is example script
`package main

import (
"flag"
"fmt"
"github.com/360EntSecGroup-Skylar/excelize"
"math/rand"
"reflect"
"strconv"
"time"
)

type NullTime struct {
Time time.Time
Valid bool // Valid is true if Time is not NULL
}

func main() {
r := rand.New(rand.NewSource(99))

excel := excelize.NewFile()

sheetName := "Test sheet"
sheetIndex := excel.GetActiveSheetIndex()
excel.SetSheetName(excel.GetSheetName(sheetIndex), sheetName)

dateStyle, _ := excel.NewStyle(`{"custom_number_format": "yyyy-mm-dd"}`)
floatStyle, _ := excel.NewStyle(`{"number_format": 2}`)

rowsCount := flag.Int("rows", 100, "Number of rows")
flag.Parse()
for row := 1; row <= *rowsCount; row++ {
	for col := 1; col <= 10; col++ {
		val := randate()
		t := reflect.ValueOf(val)
		_ = excel.SetCellValue(sheetName, intToCharIndex(col)+strconv.Itoa(row), t.Interface())
		_ = excel.SetCellStyle(sheetName, intToCharIndex(col)+strconv.Itoa(row), intToCharIndex(col)+strconv.Itoa(row), dateStyle)
	}
	for col := 11; col <= 101; col++ {
		_ = excel.SetCellValue(sheetName, intToCharIndex(col)+strconv.Itoa(row), r.Float64())
		_ = excel.SetCellStyle(sheetName, intToCharIndex(col)+strconv.Itoa(row), intToCharIndex(col)+strconv.Itoa(row), floatStyle)
	}
}
if err := excel.SaveAs("Test.xlsx"); err != nil {
	fmt.Println(err)
}

}

func intToCharIndex(i int) string {
col, _ := excelize.ColumnNumberToName(i+1)
return col
}

func randate() time.Time {
min := time.Date(2010, 1, 0, 0, 0, 0, 0, time.UTC).Unix()
max := time.Date(2020, 1, 0, 0, 0, 0, 0, time.UTC).Unix()
delta := max - min

sec := rand.Int63n(delta) + min
return time.Unix(sec, 0).UTC()

}

`

making some 100 or 1000 rows output file is ok, making 10k rows file is corrupted.

Describe the results you received:

Describe the results you expected:

Output of go version:

go version go1.14.2 darwin/amd64

Excelize version or commit ID:

v2.2.0

Environment details (OS, Microsoft Excel™ version, physical, etc.):

macOS Catalina, MS Excel for Mac 16.37

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions