func (f *File) SetColVisible(sheet string, columns string, visible bool) error
package main
import (
"fmt"
"github.com/xuri/excelize/v2"
)
func main() {
f := excelize.NewFile()
// 向表中单元格写入数据
f.SetCellValue("sheet1", "A1", "LiuBei")
f.SetCellValue("sheet1", "B1", "GuanYu")
f.SetCellValue("sheet1", "C1", "ZhangFei")
f.SetColVisible("sheet1","B",false)
// 根据指定路径保存文件
if err := f.SaveAs("sanGuo.xlsx"); err != nil {
fmt.Println(err)
}
}
结果显示
如下可见,B列被隐藏
func (f *File) GetColVisible(sheet string, col string) (bool, error)
status,_ := f.GetColVisible("sheet1","B")
package main
import (
"fmt"
"github.com/xuri/excelize/v2"
)
func main() {
f := excelize.NewFile()
// 向表中单元格写入数据
f.SetCellValue("sheet1", "A1", "LiuBei")
f.SetCellValue("sheet1", "B1", "GuanYu")
f.SetCellValue("sheet1", "C1", "ZhangFei")
f.SetColVisible("sheet1","B",false)
status,_ := f.GetColVisible("sheet1","B")
fmt.Println(status)
}
func (f *File) SetRowVisible(sheet string, row int, visible bool) error
err := f.SetRowVisible("Sheet1", 2, false)
func (f *File) GetRowVisible(sheet string, row int) (bool, error)
err := f.GetRowVisible("Sheet1", 2)
func (f *File) SetColWidth(sheet string, startCol string, endCol string, width float64) error
package main
import (
"fmt"
"github.com/xuri/excelize/v2"
)
func main() {
f := excelize.NewFile()
// 向表中单元格写入数据
f.SetCellValue("sheet1", "A1", "LiuBei")
f.SetCellValue("sheet1", "B1", "GuanYu")
f.SetCellValue("sheet1", "C1", "ZhangFei")
f.SetColWidth("sheet1","B","C",30)
// 根据指定路径保存文件
if err := f.SaveAs("sanGuo.xlsx"); err != nil {
fmt.Println(err)
}
}
func (f *File) GetColWidth(sheet, col string) (float64, error)
func (f *File) SetRowHeight(sheet string, row int, height float64) error
f.SetRowHeight("sheet1",5,30)
package main
import (
"fmt"
"github.com/xuri/excelize/v2"
)
func main() {
f := excelize.NewFile()
// 向表中单元格写入数据
f.SetCellValue("sheet1", "A1", "LiuBei")
f.SetCellValue("sheet1", "B1", "GuanYu")
f.SetCellValue("sheet1", "C1", "ZhangFei")
f.SetRowHeight("sheet1",5,30)
// 根据指定路径保存文件
if err := f.SaveAs("sanGuo.xlsx"); err != nil {
fmt.Println(err)
}
}
func (f *File) GetRowHeight(sheet string, row int) (float64, error)
height, err := f.GetRowHeight("Sheet1", 1)
func (f *File) InsertCol(sheet string, col string) error
package main
import (
"fmt"
"github.com/xuri/excelize/v2"
)
func main() {
f := excelize.NewFile()
// 向表中单元格写入数据
f.SetCellValue("Sheet1", "A1", "liuBei")
f.SetCellValue("Sheet1", "B1", "guanYu")
f.SetCellValue("Sheet1", "C1", "zhangFei")
f.InsertCol("sheet1","B")
if err := f.SaveAs("sanGuo.xlsx"); err != nil {
fmt.Println(err)
}
}
如下可见,插入了B列。
func (f *File) RemoveCol(sheet string, col string) error
func (f *File) InsertRow(sheet string, row int) error
err := f.InsertRow("Sheet1", 3)
func (f *File) DuplicateRowTo(sheet string, row, row2 int) error
f.DuplicateRowTo("sheet1",2,6)
package main
import (
"fmt"
"github.com/xuri/excelize/v2"
)
func main() {
f := excelize.NewFile()
// 向表中单元格写入数据
f.SetCellValue("Sheet1", "A1", "liuBei")
f.SetCellValue("Sheet1", "A2", "guanYu")
f.SetCellValue("Sheet1", "A3", "zhangFei")
f.DuplicateRowTo("sheet1",2,6)
if err := f.SaveAs("sanGuo.xlsx"); err != nil {
fmt.Println(err)
}
}
将第n行复制,并插入到该行之后。
func (f *File) DuplicateRow(sheet string, row int) error
package main
import (
"fmt"
"github.com/xuri/excelize/v2"
)
func main() {
f := excelize.NewFile()
// 向表中单元格写入数据
f.SetCellValue("Sheet1", "A1", "liuBei")
f.SetCellValue("Sheet1", "A2", "guanYu")
f.SetCellValue("Sheet1", "A3", "zhangFei")
f.DuplicateRow("Sheet1",2)
if err := f.SaveAs("sanGuo.xlsx"); err != nil {
fmt.Println(err)
}
}
结果显示
如下可见,第二行被复制并插入到了第二行之后
func (f *File) RemoveRow(sheet string, row int) error
func (f *File) SetSheetRow(sheet string, axis string, slice interface{}) error
package main
import (
"fmt"
"github.com/xuri/excelize/v2"
)
func main() {
f := excelize.NewFile()
// 向表中单元格写入数据
f.SetSheetRow("Sheet1","B1",&[]interface{}{"姓名","年龄","性别"})
f.SetSheetRow("Sheet1","B2",&[]interface{}{"liuBei",25,"男"})
if err := f.SaveAs("sanGuo.xlsx"); err != nil {
fmt.Println(err)
}
}
func (f *File) SetRowOutlineLevel(sheet string, row int, level uint8) error
f.SetRowOutlineLevel("sheet1",2,1)
package main
import (
"fmt"
"github.com/xuri/excelize/v2"
)
func main() {
f := excelize.NewFile()
// 向表中单元格写入数据
f.SetCellValue("Sheet1", "A1", "name:")
f.SetCellValue("Sheet1", "A2", "- xiShu")
f.SetCellValue("Sheet1", "A3", "liuBei")
f.SetCellValue("Sheet1", "A4", "GuanYu")
f.SetCellValue("Sheet1", "A5", "zhangFei")
f.SetCellValue("Sheet1", "A6", "- dongWu:")
f.SetCellValue("Sheet1", "A7", "sunQuan")
f.SetRowOutlineLevel("sheet1",2,1)
f.SetRowOutlineLevel("sheet1",6,1)
f.SetRowOutlineLevel("sheet1",3,2)
f.SetRowOutlineLevel("sheet1",4,2)
f.SetRowOutlineLevel("sheet1",5,2)
f.SetRowOutlineLevel("sheet1",7,2)
if err := f.SaveAs("sanGuo.xlsx"); err != nil {
fmt.Println(err)
}
}
func (f *File) GetRowOutlineLevel(sheet string, row int) (uint8, error)
level,_ := f.GetRowOutlineLevel("Sheet1", 3)
package main
import (
"fmt"
"github.com/xuri/excelize/v2"
)
func main() {
f := excelize.NewFile()
// 向表中单元格写入数据
f.SetCellValue("Sheet1", "A1", "name:")
f.SetCellValue("Sheet1", "A2", "- xiShu")
f.SetCellValue("Sheet1", "A3", "liuBei")
f.SetCellValue("Sheet1", "A4", "GuanYu")
f.SetCellValue("Sheet1", "A5", "zhangFei")
f.SetCellValue("Sheet1", "A6", "- dongWu:")
f.SetCellValue("Sheet1", "A7", "sunQuan")
f.SetRowOutlineLevel("sheet1",2,1)
f.SetRowOutlineLevel("sheet1",6,1)
f.SetRowOutlineLevel("sheet1",3,2)
f.SetRowOutlineLevel("sheet1",4,2)
f.SetRowOutlineLevel("sheet1",5,2)
f.SetRowOutlineLevel("sheet1",7,2)
level,_ := f.GetRowOutlineLevel("Sheet1", 3)
fmt.Printf("第三行的级别是:%d\n",level)
}
第二行的级别是:2
func (f *File) SetColOutlineLevel(sheet, col string, level uint8) error
func (f *File) GetRowOutlineLevel(sheet string, row int) (uint8, error)