Autoindex

This commit is contained in:
2021-12-17 11:24:51 -06:00
parent e19a630a8b
commit 0fb12e189c
4 changed files with 55 additions and 8 deletions

16
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "main.go",
"args": ["-file","data.xlsx"]
}
]
}

BIN
data.xlsx

Binary file not shown.

View File

@@ -37,32 +37,63 @@ func (r *Runner) ProcessExcel(path string) {
f, err := excelize.OpenFile(path)
checkErr(err)
rows, err := f.GetRows("Sheet1")
rows, err := f.GetRows("Export")
checkErr(err)
const offset = 3
indexs := make(map[string]int)
var offset = 0
for _, row := range rows {
offset += 1
for i, header := range row {
switch header {
case "FiscalYearMonth":
indexs["Date"] = i
case "Level2":
indexs["Level2"] = i
case "Level3":
indexs["Level3"] = i
case "MaterialEntered":
indexs["SKU"] = i
case "Quantity":
indexs["Quantity"] = i
case "SalesRevenue":
indexs["Revenue"] = i
case "CostOfGoodsSold":
indexs["Cost"] = i
case "ProductDescription":
indexs["Description"] = i
}
}
if len(indexs) == 8 {
break
}
}
data := []Data{}
for i, row := range rows {
if i >= offset {
new_data := Data{SKU: row[34], Level2: row[30], Level3: row[31], Description: row[45]}
if i >= offset {
if len(row[indexs["SKU"]]) == 0 {
break
}
new_data := Data{SKU: row[indexs["SKU"]], Level2: row[indexs["Level2"]], Level3: row[indexs["Level3"]], Description: row[indexs["Description"]]}
//Parse Rev
rev, err := strconv.ParseFloat(row[75], 64)
rev, err := strconv.ParseFloat(row[indexs["Revenue"]], 64)
checkErr(err)
new_data.Revenue = rev
//Parse Cost
cost, err := strconv.ParseFloat(row[16], 64)
cost, err := strconv.ParseFloat(row[indexs["Cost"]], 64)
checkErr(err)
new_data.Cost = cost
//Parse Quantity
qty, err := strconv.ParseInt(row[74], 10, 64)
qty, err := strconv.ParseInt(row[indexs["Quantity"]], 10, 64)
checkErr(err)
new_data.Quantity = qty
//Parse Time
day, err := time.Parse("2006-01", row[27])
day, err := time.Parse("2006-01", row[indexs["Date"]])
checkErr(err)
new_data.Year = int64(day.Year())
new_data.Month = int64(day.Month())

BIN
xl Executable file

Binary file not shown.