Skip to content

Instantly share code, notes, and snippets.

@ihsanbudiman
Created February 2, 2023 13:47
Show Gist options
  • Save ihsanbudiman/dcefa42214095a0f0dabb00964f9d1db to your computer and use it in GitHub Desktop.
Save ihsanbudiman/dcefa42214095a0f0dabb00964f9d1db to your computer and use it in GitHub Desktop.
test
for _, row := range data {
for idx2, row2 := range row {
row2map := row2.(map[string]any)
cell, _ := excelize.CoordinatesToCellName(activeCol, activeRow)
f.SetCellValue("Sheet1", cell, idx2)
bRow2 := activeRow
aRow2 := activeRow
zCol2 := activeCol
activeCol++
for idx3, row3 := range row2map {
row3map := row3.(map[string]any)
cell, _ := excelize.CoordinatesToCellName(activeCol, activeRow)
f.SetCellValue("Sheet1", cell, idx3)
bRow3 := activeRow
aRow3 := activeRow
zCol3 := activeCol
activeCol++
for idx4, row4 := range row3map {
row4arr := row4.([]string)
cell, _ := excelize.CoordinatesToCellName(activeCol, activeRow)
f.SetCellValue("Sheet1", cell, idx4)
bRow4 := activeRow
aRow4 := activeRow + len(row4arr) - 1
aRow3 = aRow4
aRow2 = aRow4
zCol4 := activeCol
activeCol++
for _, row5 := range row4arr {
cell, _ := excelize.CoordinatesToCellName(activeCol, activeRow)
f.SetCellValue("Sheet1", cell, row5)
f.SetCellStyle("Sheet1", cell, cell, border)
activeRow++
}
bCell4, _ := excelize.CoordinatesToCellName(zCol4, bRow4)
aCell4, _ := excelize.CoordinatesToCellName(zCol4, aRow4)
f.MergeCell("Sheet1", bCell4, aCell4)
// align to center
f.SetCellStyle("Sheet1", bCell4, aCell4, style)
activeCol--
}
bCell3, _ := excelize.CoordinatesToCellName(zCol3, bRow3)
aCell3, _ := excelize.CoordinatesToCellName(zCol3, aRow3)
f.MergeCell("Sheet1", bCell3, aCell3)
// align to center
f.SetCellStyle("Sheet1", bCell3, aCell3, style)
activeCol--
}
bCell2, _ := excelize.CoordinatesToCellName(zCol2, bRow2)
aCell2, _ := excelize.CoordinatesToCellName(zCol2, aRow2)
f.MergeCell("Sheet1", bCell2, aCell2)
// align to center
f.SetCellStyle("Sheet1", bCell2, aCell2, style)
activeCol--
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment