enhanced reading dates
This commit is contained in:
@@ -3,17 +3,18 @@ package xls
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/tealeg/xlsx"
|
||||
"path"
|
||||
"math"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
//Compares xls and xlsx files
|
||||
func compareXlsXlsx(filepathname string) string {
|
||||
xlsFile, err := Open(path.Join("testdata", filepathname)+".xls", "utf-8")
|
||||
func compareXlsXlsx(xlsfilepathname string, xlsxfilepathname string) string {
|
||||
xlsFile, err := Open(xlsfilepathname, "utf-8")
|
||||
if err != nil {
|
||||
return fmt.Sprintf("Cant open xls file: %s", err)
|
||||
}
|
||||
|
||||
xlsxFile, err := xlsx.OpenFile(path.Join("testdata", filepathname) + ".xlsx")
|
||||
xlsxFile, err := xlsx.OpenFile(xlsxfilepathname)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("Cant open xlsx file: %s", err)
|
||||
}
|
||||
@@ -29,8 +30,22 @@ func compareXlsXlsx(filepathname string) string {
|
||||
xlsText := xlsRow.Col(cell)
|
||||
xlsxText := xlsxCell.String()
|
||||
if xlsText != xlsxText {
|
||||
return fmt.Sprintf("Sheet: %d, row: %d, col: %d, xlsx: (%s)[%d], xls: (%s)[%d].",
|
||||
sheet, row, cell, xlsxText, len(xlsxText), xlsText, len(xlsText))
|
||||
//try to convert to numbers
|
||||
xlsFloat, xlsErr := strconv.ParseFloat(xlsText, 64)
|
||||
xlsxFloat, xlsxErr := strconv.ParseFloat(xlsxText, 64)
|
||||
//check if numbers have no significant difference
|
||||
if xlsErr == nil && xlsxErr == nil {
|
||||
diff := math.Abs(xlsFloat - xlsxFloat)
|
||||
if diff > 0.0000001 {
|
||||
return fmt.Sprintf("sheet:%d, row/col: %d/%d, xlsx: (%s)[%d], xls: (%s)[%d], numbers difference: %f.",
|
||||
sheet, row, cell, xlsxText, len(xlsxText),
|
||||
xlsText, len(xlsText), diff)
|
||||
}
|
||||
} else {
|
||||
return fmt.Sprintf("sheet:%d, row/col: %d/%d, xlsx: (%s)[%d], xls: (%s)[%d].",
|
||||
sheet, row, cell, xlsxText, len(xlsxText),
|
||||
xlsText, len(xlsText))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user