8
"github.com/xuri/excelize/v2"
9
"gonum.org/v1/gonum/mat"
13
func SafeToXlsx(sig []float64, Path, FileName string) {
14
file_graph := excelize.NewFile()
15
file_graph.NewSheet("main")
16
file_graph.DeleteSheet("Sheet1")
17
for ind, val := range sig {
18
file_graph.SetCellValue("main", "A"+strconv.Itoa(ind+1), val)
20
// "files" + OpSystemFilder + name + ".xlsx"
21
if err := file_graph.SaveAs(Path + FileName); err != nil {
25
func SafeToXlsxMatrix(X *mat.Dense, Path, FileName string) {
26
file_graph := excelize.NewFile()
27
file_graph.NewSheet("main")
28
file_graph.DeleteSheet("Sheet1")
30
for i := 0; i < n; i++ {
31
for j := 0; j < m; j++ {
32
file_graph.SetCellValue("main", GetColumnName(j+1)+strconv.Itoa(i+1), X.At(i, j))
35
// Path + "files" + OpSystemFilder + xlsxName + ".xlsx"
36
if err := file_graph.SaveAs(Path + FileName); err != nil {
41
func SafeToXlsxDualArray(X [][]float64, Path, FileName string) {
42
file_graph := excelize.NewFile()
43
file_graph.NewSheet("main")
44
file_graph.DeleteSheet("Sheet1")
45
for ind1, val1 := range X {
46
for ind2, val2 := range val1 {
47
file_graph.SetCellValue("main", GetColumnName(ind2+1)+strconv.Itoa(ind1), val2)
50
// Path + "files" + OpSystemFilder + xlsxName + ".xlsx"
51
if err := file_graph.SaveAs(Path + FileName); err != nil {
56
func SafeToXlsxM(X mat.Dense, FilePathName string) {
57
file_graph := excelize.NewFile()
58
file_graph.NewSheet("main")
59
file_graph.DeleteSheet("Sheet1")
61
for i := 0; i < n; i++ {
62
for j := 0; j < m; j++ {
63
file_graph.SetCellValue("main", GetColumnName(j+1)+strconv.Itoa(i+1), X.At(i, j))
66
// Path + "files" + OpSystemFilder + xlsxName + ".xlsx"
67
if err := file_graph.SaveAs(FilePathName); err != nil {
72
func GetColumnName(col int) string { /*
73
name := make([]byte, 0, 3) // max 16,384 columns (2022)
74
const aLen = 'Z' - 'A' + 1 // alphabet length
75
for ; col > 0; col /= aLen + 1 {
76
name = append(name, byte('A'+(col-1)%aLen))
78
for i, j := 0, len(name)-1; i < j; i, j = i+1, j-1 {
79
name[i], name[j] = name[j], name[i]
83
asd, _ := excelize.ColumnNumberToName(col)
87
// Создать вложенные подпапки, если их не существует
88
func СreateFolderIfNotExists(folderPath string) error {
89
_, err := os.Stat(folderPath)
90
if os.IsNotExist(err) {
91
err := os.MkdirAll(folderPath, os.ModePerm)
95
// fmt.Printf("Папка %s создана\n", folderPath)
96
} else if err != nil {
99
// else { fmt.Printf("Папка %s уже существует\n", folderPath) }