forked from xuri/excelize-doc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the Portuguese version docs for the calendar example
- Loading branch information
Showing
2 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
# Calendário | ||
|
||
Crie um calendário com Excelize usando Go: | ||
|
||
<p align="center"><img width="934" src="../images/example_calendar.png" alt="Crie um calendário com Excelize usando Go:"></p> | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/xuri/excelize/v2" | ||
) | ||
|
||
func main() { | ||
// criar uma nova planilha | ||
f := excelize.NewFile() | ||
var ( | ||
monthStyle, titleStyle, dataStyle, blankStyle, | ||
grayBlankStyle, grayDataStyle, noteStyle, noteLineStyle int | ||
err error | ||
addr string | ||
sheet = "Sheet1" | ||
// valores de células | ||
data = map[int][]interface{}{ | ||
1: {"Março 2020"}, | ||
3: {"DOMINGO", "SEGUNDA", "TERÇA", "QUARTA", | ||
"QUINTA", "SEXTA", "SÁBADO"}, | ||
4: {26, 27, 28, 29, 30, 1, 2}, | ||
6: {3, 4, 5, 6, 7, 8, 9}, | ||
8: {10, 11, 12, 13, 14, 15, 16}, | ||
10: {17, 18, 19, 20, 21, 22, 23}, | ||
12: {24, 25, 26, 27, 28, 29, 30}, | ||
14: {31, 1, 2, 3, 4, 5, 6}, | ||
18: {"Notas"}, | ||
} | ||
// altura das linhas personalizadas | ||
height = map[int]float64{ | ||
1: 45, 3: 22, 5: 44, 7: 44, 9: 44, 11: 44, 13: 44, 15: 44, | ||
18: 24, 19: 24, 20: 24, 21: 24, 22: 24, 23: 24, 24: 24, | ||
} | ||
top = excelize.Border{Type: "top", Style: 1, Color: "DADEE0"} | ||
left = excelize.Border{Type: "left", Style: 1, Color: "DADEE0"} | ||
right = excelize.Border{Type: "right", Style: 1, Color: "DADEE0"} | ||
bottom = excelize.Border{Type: "bottom", Style: 1, Color: "DADEE0"} | ||
fill = excelize.Fill{Type: "pattern", Color: []string{"EFEFEF"}, Pattern: 1} | ||
) | ||
// definir cada valor de célula | ||
for r, row := range data { | ||
if addr, err = excelize.JoinCellName("B", r); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
if err = f.SetSheetRow(sheet, addr, &row); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
} | ||
// definir altura de linha personalizada | ||
for r, ht := range height { | ||
if err = f.SetRowHeight(sheet, r, ht); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
} | ||
// definir largura de coluna personalizada | ||
if err = f.SetColWidth(sheet, "B", "H", 16.5); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
// mesclar célula para o 'MÊS' | ||
if err = f.MergeCell(sheet, "B1", "D1"); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
// definir o estilo da fonte para o 'MÊS' | ||
if monthStyle, err = f.NewStyle(&excelize.Style{ | ||
Font: &excelize.Font{Color: "1f7f3b", Bold: true, Size: 22, Family: "Arial"}, | ||
}); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
// definir o estilo da fonte para o 'MÊS' | ||
if err = f.SetCellStyle(sheet, "B1", "D1", monthStyle); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
// definir estilo para 'DOMINGO' a 'SÁBADO' | ||
if titleStyle, err = f.NewStyle(&excelize.Style{ | ||
Font: &excelize.Font{Color: "1f7f3b", Bold: true, Family: "Arial"}, | ||
Fill: excelize.Fill{Type: "pattern", Color: []string{"E6F4EA"}, Pattern: 1}, | ||
Alignment: &excelize.Alignment{Vertical: "center", Horizontal: "center"}, | ||
Border: []excelize.Border{{Type: "top", Style: 2, Color: "1f7f3b"}}, | ||
}); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
// definir estilo de 'DOMINGO' para 'SÁBADO' | ||
if err = f.SetCellStyle(sheet, "B3", "H3", titleStyle); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
// definir a borda da célula para a célula de data no intervalo de datas | ||
if dataStyle, err = f.NewStyle(&excelize.Style{ | ||
Border: []excelize.Border{top, left, right}, | ||
}); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
// definir a borda da célula para a célula de data no intervalo de datas | ||
for _, r := range []int{4, 6, 8, 10, 12, 14} { | ||
if err = f.SetCellStyle(sheet, "B"+strconv.Itoa(r), | ||
"H"+strconv.Itoa(r), dataStyle); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
} | ||
// definir a borda da célula para a célula em branco no intervalo de datas | ||
if blankStyle, err = f.NewStyle(&excelize.Style{ | ||
Border: []excelize.Border{left, right, bottom}, | ||
}); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
// definir a borda da célula para a célula em branco no intervalo de datas | ||
for _, r := range []int{5, 7, 9, 11, 13, 15} { | ||
if err = f.SetCellStyle(sheet, "B"+strconv.Itoa(r), | ||
"H"+strconv.Itoa(r), blankStyle); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
} | ||
// definir a borda e o estilo de preenchimento da célula em branco no mês anterior e no próximo mês | ||
if grayBlankStyle, err = f.NewStyle(&excelize.Style{ | ||
Border: []excelize.Border{left, right, bottom}, | ||
Fill: fill}); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
// definir a borda e o estilo de preenchimento da célula em branco no mês anterior e no próximo mês | ||
if err = f.SetCellStyle(sheet, "B5", "F5", grayBlankStyle); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
if err = f.SetCellStyle(sheet, "C15", "H15", grayBlankStyle); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
// definir a borda e o estilo de preenchimento da célula de data no mês anterior e no próximo mês | ||
if grayDataStyle, err = f.NewStyle(&excelize.Style{ | ||
Border: []excelize.Border{left, right, top}, | ||
Font: &excelize.Font{Color: "777777"}, Fill: fill}); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
// definir a borda e o estilo de preenchimento para a célula de data no mês anterior e no próximo mês | ||
if err = f.SetCellStyle(sheet, "B4", "F4", grayDataStyle); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
if err = f.SetCellStyle(sheet, "C14", "H14", grayDataStyle); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
// definir o estilo da fonte para as 'Notas' | ||
if noteStyle, err = f.NewStyle(&excelize.Style{ | ||
Font: &excelize.Font{Color: "1f7f3b", Bold: true, Size: 14, Family: "Arial"}, | ||
}); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
// definir o estilo da fonte para as 'Notas' | ||
if err = f.SetCellStyle(sheet, "B18", "B18", noteStyle); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
// definir o estilo da célula para o intervalo de notas | ||
if noteLineStyle, err = f.NewStyle(&excelize.Style{ | ||
Border: []excelize.Border{{Type: "bottom", Style: 4, Color: "DDDDDD"}}, | ||
}); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
// definir o estilo da célula para o intervalo de notas | ||
for r := 19; r < 25; r++ { | ||
if err = f.SetCellStyle(sheet, "B"+strconv.Itoa(r), | ||
"H"+strconv.Itoa(r), noteLineStyle); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
} | ||
// ocultar linhas de grade da planilha | ||
disable := false | ||
if err := f.SetSheetView("Sheet1", 0, &excelize.ViewOptions{ | ||
ShowGridLines: &disable, | ||
}); err != nil { | ||
fmt.Println(err) | ||
} | ||
// renomear planilha | ||
f.SetSheetName(sheet, "Março 20") | ||
// salvar arquivo de planilha | ||
if err = f.SaveAs("Calendário.xlsx"); err != nil { | ||
fmt.Println(err) | ||
} | ||
} | ||
``` |