package main
import (
"fmt"
"github.com/360EntSecGroup-Skylar/excelize"
)
func main() {
f := excelize.NewFile()
index := f.NewSheet("Sheet2")
f.SetCellValue("Sheet2", "A2", "Hello world.")
style, err := f.NewStyle(`{
"font":
{
"bold": true,
"family": "font-family",
"size": 20,
"color": "#777777"
}
}`)
if err != nil {
fmt.Println(err)
}
f.SetCellStyle("Sheet1", "B1", "B1", style)
f.SetCellValue("Sheet1", "B1", "hello")
f.SetActiveSheet(index)
if err := f.SaveAs("Book1.xlsx"); err != nil {
fmt.Println(err)
}
}
package main
import (
"fmt"
_ "image/gif"
_ "image/jpeg"
_ "image/png"
"github.com/360EntSecGroup-Skylar/excelize"
)
func main() {
f, err := excelize.OpenFile("Book1.xlsx")
if err != nil {
fmt.Println(err)
return
}
if err := f.AddPicture("Sheet1", "A3", "004.jpeg", ""); err != nil {
fmt.Println(err)
}
if err := f.AddPicture("Sheet1", "D3", "1.jpg", `{"x_scale": 0.5, "y_scale": 0.5}`); err != nil {
fmt.Println(err)
}
if err := f.AddPicture("Sheet1", "H3", "2.jpeg", `{"x_scale": 0.1, "y_scale": 0.1,"x_offset": 15, "y_offset": 10, "print_obj": true, "lock_aspect_ratio": false, "locked": false}`); err != nil {
fmt.Println(err)
}
if err = f.Save(); err != nil {
fmt.Println(err)
}
}
package main
import (
"fmt"
"github.com/360EntSecGroup-Skylar/excelize"
)
func main() {
f, err := excelize.OpenFile("Book1.xlsx")
if err != nil {
fmt.Println(err)
return
}
cell := f.GetCellValue("Sheet1", "A3")
if cell == "" {
fmt.Println("获取内容为空")
}else {
fmt.Println("指定表格中内容为:", cell)
}
rows := f.GetRows("Sheet1")
for _, row := range rows {
for _, colCell := range row {
fmt.Print(colCell, "=")
}
fmt.Println()
}
}
package main
import (
"github.com/360EntSecGroup-Skylar/excelize"
"log"
"net/http"
)
func down(w http.ResponseWriter, r *http.Request) {
f := excelize.NewFile()
f.SetCellValue("Sheet1", "A2", "Hello world.")
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Disposition", "attachment; filename="+"100以内口算题.xlsx")
w.Header().Set("Content-Transfer-Encoding", "binary")
_ = f.Write(w)
}
func main() {
http.HandleFunc("/", down)
log.Fatal(http.ListenAndServe(":8080", nil))
}