
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
github.com/heliangrui/excel
首先感谢 github.com/xuri/excelize/v2 基础库对excel表格的支持,本文在此基础上进行功能的api扩展方便,(web/其他)有结构体导出与导入需求的封装优化,当前版本 v0.0.2
go get github.com/heliangrui/excel
当前版本v0.0.2,也可指定版本安装,以防版本变化
go get github.com/heliangrui/excel@0.0.2
type NameStruct struct{
Name string `excelName:"姓名" excelIndex:"1" excelColWidth:"30"`
Age string `excelName:"年龄" excelIndex:"3"`
Sex int `excelName:"性别" excelIndex:"1" toExcelFormat:"ToExcelSexFormat"`
}
func (n NameStruct) ToExcelSexFormat() string{
if n.Sex == 0 {
return "女"
}
return "男"
}
func main() {
//创建数据源
data := createData()
//创建导出对象
export := excel.NewExcelExport("test", NameStruct{})
//销毁对象
defer export.Close()
//导出
err = export.ExportSmallExcelByStruct(data).WriteInFileName("test.xlsx").Error()
if err != nil {
fmt.Println("生成失败", err.Error())
}
}
func createData() []NameStruct {
var names []NameStruct
for i := 0; i < 10; i++ {
names = append(names, NameStruct{name: "hlr" + strconv.Itoa(i), age: strconv.Itoa(i),Sex: i})
}
return names
}
func main() {
//创建数据源
data := createData()
//创建导出对象
export := excel.NewExcelExport("test", NameStruct{})
//销毁对象
defer export.Close()
//导出 模拟分页
for i := 0; i < 10; i++ {
export.ExportData(result, i*10)
}
err = export.WriteInFileName("test.xlsx").Error()
if err != nil {
fmt.Println("生成失败", err.Error())
}
}
func main() {
//接受数据
var result []NameStruct
//创建导入对象
importFile := excel.NewExcelImportFile("111.xlsx", NameStruct{})
//对象销毁
defer importFile.Close()
//数据填充
err := importFile.ImportDataToStruct(&result).Error()
//数据显示
if err != nil {
fmt.Println("生成失败", err.Error())
} else {
marshal, _ := json.Marshal(result)
fmt.Println(string(marshal))
}
}
func main() {
//接受数据
var result []NameStruct
//创建导入对象
importFile := excel.NewExcelImportFile("111.xlsx", NameStruct{})
//对象销毁
defer importFile.Close()
// 方式二 逐行遍历
err := importFile.ImportRead(func(row NameStruct) {
fmt.Println(row.Name)
}).Error()
}
export := excel.NewExcelExport("test", NameStruct{})
//获取默认表头样式
header := excel.CreateDefaultHeader()
//编辑默认header
// .......
export.SetHeadStyle(header)
{
Border: []excelize.Border{
{Type: "left", Color: "050505", Style: 1},
{Type: "top", Color: "050505", Style: 1},
{Type: "bottom", Color: "050505", Style: 1},
{Type: "right", Color: "050505", Style: 1},
},
Fill: excelize.Fill{Type: "gradient", Color: []string{"#a6a6a6", "#a6a6a6"}, Shading: 1},
Font: nil,
Alignment: &excelize.Alignment{
Horizontal: "center",
Indent: 1,
JustifyLastLine: true,
ReadingOrder: 0,
RelativeIndent: 1,
ShrinkToFit: false,
TextRotation: 0,
Vertical: "",
WrapText: false,
},
Protection: nil,
NumFmt: 0,
DecimalPlaces: 0,
CustomNumFmt: nil,
Lang: "",
NegRed: false,
}
后续有时间,将支持多表头
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.