优化excel文件插入数据

This commit is contained in:
李超 2025-02-27 15:10:41 +08:00
parent 90757d58ce
commit 19a3373980

View File

@ -16,8 +16,9 @@ import (
) )
var cookieStr string var cookieStr string
var Counts int //存储总条数
var err error // var Counts int //存储总条数
// var err error
// 传入cookie // 传入cookie
func Fw_event(cookieStr string) { func Fw_event(cookieStr string) {
@ -74,24 +75,14 @@ func Fw_event(cookieStr string) {
body := conn.DT_POST("https://11.2.68.146/wnm/get.j", header, bytes.NewBufferString(values_1.Encode())) body := conn.DT_POST("https://11.2.68.146/wnm/get.j", header, bytes.NewBufferString(values_1.Encode()))
var bodys Person var bodys Person
json.Unmarshal(body, &bodys) json.Unmarshal(body, &bodys)
Counts, err = strconv.Atoi(bodys.LogPaging[0].TotalCounts) var Con int //插入总数
if err != nil {
log.Println(err)
}
// bodys := Person{
// LogPaging: []LogPaging{
// {
// TotalCounts: "899",
// },
// },
// }
//存储昨日攻击事件 //存储昨日攻击事件
if bodys.LogPaging[0].TotalCounts > "200" { if bodys.LogPaging[0].TotalCounts > "200" {
a, err := strconv.ParseFloat(bodys.LogPaging[0].TotalCounts, 64) a, err := strconv.ParseFloat(bodys.LogPaging[0].TotalCounts, 64)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
} }
log.Println(a) log.Println("昨日查询到总条数:", a)
totalPages := int(math.Floor(float64(a))/float64(200) + 1) totalPages := int(math.Floor(float64(a))/float64(200) + 1)
log.Println(totalPages) log.Println(totalPages)
for i := 1; i < totalPages+1; i++ { for i := 1; i < totalPages+1; i++ {
@ -102,22 +93,26 @@ func Fw_event(cookieStr string) {
var bodys Person var bodys Person
json.Unmarshal(body, &bodys) json.Unmarshal(body, &bodys)
log.Println(values_1, i) log.Println(values_1, i)
for v, k := range bodys.LogPaging {
Con = v + 2
sheet.Cell("A" + strconv.Itoa(Con)).SetString(strconv.Itoa(Con)) // 第一列 (A1)
sheet.Cell("B" + strconv.Itoa(Con)).SetString(k.OutputJSON.Time)
sheet.Cell("C" + strconv.Itoa(Con)).SetString(k.OutputJSON.SrcZoneName)
sheet.Cell("D" + strconv.Itoa(Con)).SetString(k.OutputJSON.DestZoneName)
sheet.Cell("E" + strconv.Itoa(Con)).SetString(k.OutputJSON.SrcIPAddr)
sheet.Cell("F" + strconv.Itoa(Con)).SetString(k.OutputJSON.DestIPAddr)
sheet.Cell("G" + strconv.Itoa(Con)).SetString(k.OutputJSON.DestPort)
sheet.Cell("H" + strconv.Itoa(Con)).SetString(k.OutputJSON.ThreatName)
sheet.Cell("I" + strconv.Itoa(Con)).SetString(k.OutputJSON.MethodNameCN)
sheet.Cell("J" + strconv.Itoa(Con)).SetString(k.OutputJSON.MethodSubNameCN)
sheet.Cell("K" + strconv.Itoa(Con)).SetString(k.OutputJSON.Application)
sheet.Cell("L" + strconv.Itoa(Con)).SetString(k.OutputJSON.HttpHost)
}
} }
for v, k := range bodys.LogPaging {
sheet.Cell("A" + strconv.Itoa(v+1)).SetString(strconv.Itoa(v)) // 第一列 (A1)
sheet.Cell("B" + strconv.Itoa(v+1)).SetString(k.OutputJSON.Time)
sheet.Cell("C" + strconv.Itoa(v+1)).SetString(k.OutputJSON.SrcZoneName)
sheet.Cell("D" + strconv.Itoa(v+1)).SetString(k.OutputJSON.DestZoneName)
sheet.Cell("E" + strconv.Itoa(v+1)).SetString(k.OutputJSON.SrcIPAddr)
sheet.Cell("F" + strconv.Itoa(v+1)).SetString(k.OutputJSON.DestIPAddr)
sheet.Cell("G" + strconv.Itoa(v+1)).SetString(k.OutputJSON.DestPort)
sheet.Cell("H" + strconv.Itoa(v+1)).SetString(k.OutputJSON.ThreatName)
sheet.Cell("I" + strconv.Itoa(v+1)).SetString(k.OutputJSON.MethodNameCN)
sheet.Cell("J" + strconv.Itoa(v+1)).SetString(k.OutputJSON.MethodSubNameCN)
sheet.Cell("K" + strconv.Itoa(v+1)).SetString(k.OutputJSON.Application)
sheet.Cell("L" + strconv.Itoa(v+1)).SetString(k.OutputJSON.HttpHost)
}
} }
Con = Con + 1
//存储今日攻击事件 //存储今日攻击事件
body_1 := conn.DT_POST("https://11.2.68.146/wnm/get.j", header, bytes.NewBufferString(values_1.Encode())) body_1 := conn.DT_POST("https://11.2.68.146/wnm/get.j", header, bytes.NewBufferString(values_1.Encode()))
var bodys_1 Person var bodys_1 Person
@ -127,7 +122,7 @@ func Fw_event(cookieStr string) {
if err != nil { if err != nil {
log.Println(err) log.Println(err)
} }
log.Println(a) log.Println("今日查询到总条数:", a)
totalPages := int(math.Floor(float64(a))/float64(200) + 1) totalPages := int(math.Floor(float64(a))/float64(200) + 1)
log.Println(totalPages) log.Println(totalPages)
for i := 1; i < totalPages+1; i++ { for i := 1; i < totalPages+1; i++ {
@ -138,20 +133,21 @@ func Fw_event(cookieStr string) {
var bodys Person var bodys Person
json.Unmarshal(body, &bodys) json.Unmarshal(body, &bodys)
log.Println(values_1, i) log.Println(values_1, i)
} for v, k := range bodys.LogPaging {
for v, k := range bodys.LogPaging { Con = v + Con
sheet.Cell("A" + strconv.Itoa(v+Counts)).SetString(strconv.Itoa(v)) // 第一列 (A1) sheet.Cell("A" + strconv.Itoa(Con)).SetString(strconv.Itoa(Con)) // 第一列 (A1)
sheet.Cell("B" + strconv.Itoa(v+Counts)).SetString(k.OutputJSON.Time) sheet.Cell("B" + strconv.Itoa(Con)).SetString(k.OutputJSON.Time)
sheet.Cell("C" + strconv.Itoa(v+Counts)).SetString(k.OutputJSON.SrcZoneName) sheet.Cell("C" + strconv.Itoa(Con)).SetString(k.OutputJSON.SrcZoneName)
sheet.Cell("D" + strconv.Itoa(v+Counts)).SetString(k.OutputJSON.DestZoneName) sheet.Cell("D" + strconv.Itoa(Con)).SetString(k.OutputJSON.DestZoneName)
sheet.Cell("E" + strconv.Itoa(v+Counts)).SetString(k.OutputJSON.SrcIPAddr) sheet.Cell("E" + strconv.Itoa(Con)).SetString(k.OutputJSON.SrcIPAddr)
sheet.Cell("F" + strconv.Itoa(v+Counts)).SetString(k.OutputJSON.DestIPAddr) sheet.Cell("F" + strconv.Itoa(Con)).SetString(k.OutputJSON.DestIPAddr)
sheet.Cell("G" + strconv.Itoa(v+Counts)).SetString(k.OutputJSON.DestPort) sheet.Cell("G" + strconv.Itoa(Con)).SetString(k.OutputJSON.DestPort)
sheet.Cell("H" + strconv.Itoa(v+Counts)).SetString(k.OutputJSON.ThreatName) sheet.Cell("H" + strconv.Itoa(Con)).SetString(k.OutputJSON.ThreatName)
sheet.Cell("I" + strconv.Itoa(v+Counts)).SetString(k.OutputJSON.MethodNameCN) sheet.Cell("I" + strconv.Itoa(Con)).SetString(k.OutputJSON.MethodNameCN)
sheet.Cell("J" + strconv.Itoa(v+Counts)).SetString(k.OutputJSON.MethodSubNameCN) sheet.Cell("J" + strconv.Itoa(Con)).SetString(k.OutputJSON.MethodSubNameCN)
sheet.Cell("K" + strconv.Itoa(v+Counts)).SetString(k.OutputJSON.Application) sheet.Cell("K" + strconv.Itoa(Con)).SetString(k.OutputJSON.Application)
sheet.Cell("L" + strconv.Itoa(v+Counts)).SetString(k.OutputJSON.HttpHost) sheet.Cell("L" + strconv.Itoa(Con)).SetString(k.OutputJSON.HttpHost)
}
} }
} }