func writeFooterRowToSheet(totals []int64, sheet string) error { activeSheet, err := getActiveSheet(sheet) if err != nil { return err } footerFont := xlsx.NewFont(12, "Verdana") footerFont.Bold = true footerStyle := xlsx.NewStyle() footerStyle.Font = *footerFont var cell *xlsx.Cell row := activeSheet.AddRow() cell = row.AddCell() cell.SetStyle(footerStyle) cell.Value = "Total" for i := 1; i < len(totals); i++ { cell = row.AddCell() cell.SetStyle(footerStyle) cell.SetFloatWithFormat(float64(totals[i]), "#,##0") } activeSheet.AddRow() activeSheet.AddRow() return nil }
func writeRowToSheet(data [][]byte, sheet string, format map[string]string) ([]int, error) { activeSheet, err := getActiveSheet(sheet) if err != nil { return nil, err } var cell *xlsx.Cell counts := make([]int, len(data)) row := activeSheet.AddRow() for idx, bytes := range data { cell = row.AddCell() if num, err := strconv.Atoi(string(bytes)); err == nil { counts[idx] = num if val, ok := format[strconv.Itoa(idx)]; ok { cell.SetFloatWithFormat(float64(num), val) } else { cell.SetFloatWithFormat(float64(num), "#,##0") } } else { if bytes == nil { cell.Value = "Unknown" } else if empty(string(bytes)) { cell.Value = "Blank" } else { cell.Value = string(bytes) } } } return counts, nil }