本文整理汇总了Golang中github.com/tealeg/xlsx.File.Save方法的典型用法代码示例。如果您正苦于以下问题:Golang File.Save方法的具体用法?Golang File.Save怎么用?Golang File.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/tealeg/xlsx.File
的用法示例。
在下文中一共展示了File.Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
var file *xlsx.File
var sheet *xlsx.Sheet
var row *xlsx.Row
var cell *xlsx.Cell
var err error
var RawNbr int = 6
file = xlsx.NewFile()
sheet = file.AddSheet("Sheet1")
// 每列标题
text := [6]string{"ID", "鱼类型", "出现帧", "脚本ID", "X", "Y"}
for i := 0; i < RawNbr; i++ {
if i == 0 {
row = sheet.AddRow()
}
cell = row.AddCell()
cell.Value = text[i]
}
files, err := ListDir("../data/timeline", ".dat")
for j := 0; j < len(files); j++ {
write(files[j], sheet, 6)
}
err = file.Save("../outexcel/巡游鱼路径.xlsx")
if err != nil {
fmt.Printf(err.Error())
}
}
示例2: main
func main() {
var file *xlsx.File
var sheet *xlsx.Sheet
var row *xlsx.Row
var cell *xlsx.Cell
var err error
var RawNbr int = 4
file = xlsx.NewFile()
sheetName := [2]string{"Big", "Small"}
datafile := [2]string{"../data/moveline/big", "../data/moveline/small"}
for i, v := range sheetName {
sheet = file.AddSheet(v)
// 每列标题
text := [4]string{"ID", "X", "Y", "Angle"}
for i := 0; i < RawNbr; i++ {
if i == 0 {
row = sheet.AddRow()
}
cell = row.AddCell()
cell.Value = text[i]
}
files, _ := ListDir(datafile[i], ".dat")
for j := 0; j < len(files); j++ {
write(files[j], sheet, RawNbr)
}
}
fmt.Println("正在向excel写数据......")
err = file.Save("../outexcel/单条鱼路径.xlsx")
if err != nil {
fmt.Printf(err.Error())
}
}
示例3: savetoxlsx0
//экспорт данных datas в файл xlsx используя сортировку keys - массив указывающий в каком порядке выводить в таблицу
func savetoxlsx0(namef string, datas map[string]DataTelMans, keys []string) {
var file *xlsx.File
var sheet *xlsx.Sheet
var row *xlsx.Row
var cell *xlsx.Cell
var err error
file = xlsx.NewFile()
sheet, err = file.AddSheet("лог звонков")
if err != nil {
fmt.Println(err.Error())
}
//заголовок таблицы
row = sheet.AddRow() // добавить строку
cell = row.AddCell() // добавить ячейку в текущей строке
cell.Value = "выгружено: " + time.Now().String()
row = sheet.AddRow() // добавить строку
titletab := []string{"ФИО РГ",
"номер телефона",
"ФИО менеджера",
"всего продолжит-ть",
"всего кол-во звонков",
"кол-во уникальных телефонов",
"кол-во результ. звонков",
"продолжительность уникальных",
"средняя время звонка"}
for i := 0; i < len(titletab); i++ {
cell = row.AddCell() // добавить ячейку в текущей строке
cell.Value = titletab[i]
}
for i := 0; i < len(keys); i++ {
key := keys[i]
row = sheet.AddRow()
cell = row.AddCell()
cell.Value = datas[key].fio_rg
cell = row.AddCell()
cell.Value = key
cell = row.AddCell()
cell.Value = datas[key].fio_man
cell = row.AddCell()
cell.Value = sec_to_s(datas[key].totalsec)
cell = row.AddCell()
cell.Value = strconv.Itoa(datas[key].totalzv)
cell = row.AddCell()
cell.Value = strconv.Itoa(datas[key].kolunik)
cell = row.AddCell()
cell.Value = strconv.Itoa(datas[key].kolresult)
cell = row.AddCell()
cell.Value = sec_to_s(datas[key].secresult)
cell = row.AddCell()
cell.Value = sec_to_s(devidezero(datas[key].totalsec, datas[key].totalzv))
}
err = file.Save(namef)
if err != nil {
fmt.Println(err.Error())
}
}
示例4: main
func main() {
var file *xlsx.File
var sheet *xlsx.Sheet
var row *xlsx.Row
var cell *xlsx.Cell
var err error
file = xlsx.NewFile()
sheet = file.AddSheet("Sheet1")
row = sheet.AddRow()
cell = row.AddCell()
cell.Value = "I am a cell!"
err = file.Save("d:/Desktop/demo_write.xlsx")
if err != nil {
fmt.Printf(err.Error())
}
}
示例5: test2AddSheet
func test2AddSheet() {
var file *xlsx.File
var sheet *xlsx.Sheet
var row *xlsx.Row
var cell *xlsx.Cell
file, _ = xlsx.OpenFile("MyXLSXFile.xlsx")
sheet = file.AddSheet("addSheet")
row = sheet.AddRow()
cell = row.AddCell()
cell.Value = "addSheet000101"
cell = row.AddCell()
cell.Value = "addSheet中文1"
err := file.Save("MyXLSXFile.xlsx")
if err != nil {
fmt.Printf(err.Error())
}
}
示例6: test2
func test2() {
var file *xlsx.File
var sheet *xlsx.Sheet
var row *xlsx.Row
var cell *xlsx.Cell
var err error
file, _ = xlsx.OpenFile("MyXLSXFile.xlsx")
sheet = file.Sheet["Sheet1"]
row = sheet.AddRow()
cell = row.AddCell()
cell.Value = "000101"
cell = row.AddCell()
cell.Value = "中文1"
err = file.Save("MyXLSXFile1.xlsx")
if err != nil {
fmt.Printf(err.Error())
}
}
示例7: test1
func test1() {
var file *xlsx.File
var sheet *xlsx.Sheet
var row *xlsx.Row
var cell *xlsx.Cell
var err error
file = xlsx.NewFile()
sheet = file.AddSheet("Sheet1")
row = sheet.AddRow()
cell = row.AddCell()
cell.Value = "000101"
cell = row.AddCell()
cell.Value = "中文"
err = file.Save("MyXLSXFile.xlsx")
if err != nil {
fmt.Printf(err.Error())
}
}
示例8: createDonation
func createDonation() {
var currentYear = 0
var currentMonth = 0
r := helpcase.GetAllHelpcase()
var file *xlsx.File
var sheet1 *xlsx.Sheet
log.Println("donation export begin")
for _, hp := range r {
dt := helpcase.GetAllDonationDetail(hp.SerialNo)
if len(dt) == 0 {
continue
}
test, _ := time.Parse("2006/1/2", hp.Date)
var isCurrent = isCurrentYearMonthMatch(currentYear, currentMonth, test.Year(), int(test.Month()))
if !isCurrent {
if file != nil {
var err error
if currentMonth < 10 {
err = file.Save(outfolder + "/donation_" + strconv.Itoa(currentYear) + "0" + strconv.Itoa(currentMonth) + ".xlsx")
} else {
err = file.Save(outfolder + "/donation_" + strconv.Itoa(currentYear) + strconv.Itoa(currentMonth) + ".xlsx")
}
if err != nil {
fmt.Printf(err.Error())
}
}
file = xlsx.NewFile()
currentYear = test.Year()
currentMonth = int(test.Month())
}
sheet1 = file.AddSheet(hp.SerialNo)
var publishDate, _ = time.Parse("2006/1/2", hp.Date)
var cell *xlsx.Cell
var row *xlsx.Row
addHeader(sheet1)
for _, donator := range dt {
row = sheet1.AddRow()
cell = row.AddCell()
cell.SetString(donator.SerialNo)
cell = row.AddCell()
cell.Value = donator.Name
cell = row.AddCell()
cell.SetInt(donator.Amount)
cell.NumFmt = "#,##0 ;(#,##0)"
cell = row.AddCell()
cell.Value = donator.Date
cell = row.AddCell()
cell.SetFormula("weekday(\"" + donator.Date + "\",2)")
var dDate, _ = time.Parse("2006/1/2", donator.Date)
duration := dDate.Sub(publishDate)
cell = row.AddCell()
cell.Value = strconv.Itoa(int(duration.Hours() / 24))
cell = row.AddCell()
if donator.LongFour == 1 {
cell.Value = "YES"
} else {
cell.Value = "NO"
}
}
row = sheet1.AddRow()
row.AddCell()
row = sheet1.AddRow()
cell = row.AddCell()
cell.Value = "捐款頁面的URL"
cell = row.AddCell()
cell.SetFormula("HYPERLINK(\"http://search.appledaily.com.tw/charity/projdetail/proj/" + hp.SerialNo + "\",\"http://search.appledaily.com.tw/charity/projdetail/proj/" + hp.SerialNo + "\")")
row = sheet1.AddRow()
cell = row.AddCell()
cell.Value = "出刊日期"
cell = row.AddCell()
cell.Value = hp.Date
cell = row.AddCell()
cell.Value = "專案狀況"
cell = row.AddCell()
cell.Value = hp.Status
row = sheet1.AddRow()
cell = row.AddCell()
cell.Value = "捐款總計"
cell = row.AddCell()
cell.SetInt(hp.Amount)
cell.NumFmt = "#,##0 ;(#,##0)"
cell = row.AddCell()
cell.Value = "捐款筆數"
//.........这里部分代码省略.........
示例9: excel
/************************ excel 输出 ***************************/
func (self *Collector) excel(dataIndex int) {
defer func() {
if err := recover(); err != nil {
Log.Println(err)
}
}()
var file *xlsx.File
var sheet *xlsx.Sheet
var row *xlsx.Row
var cell *xlsx.Cell
var err error
folder1 := "data"
_folder2 := strings.Split(cache.StartTime.Format("2006-01-02 15:04:05"), ":")
folder2 := _folder2[0] + "时" + _folder2[1] + "分" + _folder2[2] + "秒"
folder2 = folder1 + "/" + folder2
filename := folder2 + "/" + self.Spider.GetName() + "_" + self.Spider.GetKeyword() + " " + strconv.Itoa(self.sum[0]) + "-" + strconv.Itoa(self.sum[1]) + ".xlsx"
file = xlsx.NewFile()
// 添加分类数据工作表
for Name, Rule := range self.GetRules() {
// 跳过不输出的数据
if len(Rule.GetOutFeild()) == 0 {
continue
}
sheet = file.AddSheet(Name)
row = sheet.AddRow()
for _, title := range Rule.GetOutFeild() {
cell = row.AddCell()
cell.Value = title
}
cell = row.AddCell()
cell.Value = "当前链接"
cell = row.AddCell()
cell.Value = "上级链接"
cell = row.AddCell()
cell.Value = "下载时间"
num := 0 //小计
for _, datacell := range self.DockerQueue.Dockers[dataIndex] {
if datacell["RuleName"].(string) == Name {
row = sheet.AddRow()
for _, title := range Rule.GetOutFeild() {
cell = row.AddCell()
vd := datacell["Data"].(map[string]interface{})
if v, ok := vd[title].(string); ok || vd[title] == nil {
cell.Value = v
} else {
j, _ := json.Marshal(vd[title])
cell.Value = string(j)
}
}
cell = row.AddCell()
cell.Value = datacell["Url"].(string)
cell = row.AddCell()
cell.Value = datacell["ParentUrl"].(string)
cell = row.AddCell()
cell.Value = datacell["DownloadTime"].(string)
num++
}
}
// Log.Printf("[任务:%v | 关键词:%v | 小类:%v] 输出 %v 条数据!!!\n", self.Spider.GetName(), self.Spider.GetKeyword(), Name, num)
}
// 创建/打开目录
f2, err := os.Stat(folder2)
if err != nil || !f2.IsDir() {
if err := os.MkdirAll(folder2, 0777); err != nil {
Log.Printf("Error: %v\n", err)
}
}
// 保存文件
err = file.Save(filename)
if err != nil {
Log.Println(err)
}
}
示例10: EnsureStatistic
func EnsureStatistic(toPath string) error {
var file *xlsx.File
var sheet *xlsx.Sheet
var row *xlsx.Row
var cell *xlsx.Cell
var err error
file = xlsx.NewFile()
type Source struct {
Name string `bson:"_id"`
}
sources := []Source{}
dbsWithOrders := getDbsWithOrders()
log.Printf("Databases with orders is: %+v", dbsWithOrders)
for _, dbName := range dbsWithOrders {
db := d.NewMainDb(config.Main.Database.ConnString, dbName)
sheet, err = file.AddSheet(dbName)
if err != nil {
log.Printf("Error at edding sheet to file")
continue
}
db.Orders.Collection.Pipe(
[]bson.M{bson.M{"$group": bson.M{"_id": "$source"}}},
).All(&sources)
for _, source := range sources {
row = sheet.AddRow()
cell = row.AddCell()
cell.Value = source.Name
row = sheet.AddRow()
for _, h_cell := range []string{"Телефон", "Статус", "Дата", "Стоимость", "Адрес подачи", "Адрес назначения", "Позывной автомобиля", "ФИО водителя"} {
cell = row.AddCell()
cell.Value = h_cell
}
orders, err := db.Orders.GetBy(bson.M{"source": source.Name})
if err != nil {
log.Printf("Error at getting orders from %+v is: %v", config.Main.Database, err)
return err
}
for _, order := range orders {
log.Printf("adding row for order %+v", order)
user, u_err := db.Users.GetUserById(order.Whom)
if u_err != nil || user == nil {
log.Printf("No user found at id: %v", order.Whom)
continue
}
row = sheet.AddRow()
ph_c := row.AddCell()
ph_c.SetString(user.Phone)
stat_c := row.AddCell()
if state, ok := t.InfinityStatusesName[order.OrderState]; ok {
stat_c.SetString(state)
} else {
stat_c.SetString("Не определен")
}
time_c := row.AddCell()
time_c.SetDateTime(order.When)
if len(order.OrderData.Content) > 0 {
log.Printf("we have additional data of order %v", order.OrderId)
cost := order.OrderData.Get("Cost")
if cost != nil {
cost_c := row.AddCell()
cost_c.SetInt(order.OrderData.Get("Cost").(int))
deliv_c := row.AddCell()
deliv_c.SetString(order.OrderData.Get("DeliveryStr").(string))
dest_c := row.AddCell()
dest_c.SetString(order.OrderData.Get("DestinationsStr").(string))
car_c := row.AddCell()
car_c.SetString(order.OrderData.Get("Car").(string))
driver_c := row.AddCell()
driver_c.SetString(order.OrderData.Get("Drivers").(string))
}
}
log.Printf("Added row: %+v", row)
}
}
}
fName := fmt.Sprintf("%v/statistic.xlsx", toPath)
file.Save(fName)
return nil
}
示例11: init
func init() {
defer func() {
// 获取输出方式列表
for out, _ := range Output {
OutputLib = append(OutputLib, out)
}
util.StringsSort(OutputLib)
}()
/************************ excel 输出 ***************************/
Output["excel"] = func(self *Collector, dataIndex int) {
defer func() {
if err := recover(); err != nil {
Log.Println(err)
}
}()
var file *xlsx.File
var sheet *xlsx.Sheet
var row *xlsx.Row
var cell *xlsx.Cell
var err error
folder1 := "result/data"
folder2 := folder1 + "/" + self.startTime.Format("2006年01月02日 15时04分05秒")
filename := folder2 + "/" + util.FileNameReplace(self.Spider.GetName()+"_"+self.Spider.GetKeyword()+" "+fmt.Sprintf("%v", self.sum[0])+"-"+fmt.Sprintf("%v", self.sum[1])) + ".xlsx"
// 创建文件
file = xlsx.NewFile()
// 添加分类数据工作表
for Name, Rule := range self.GetRules() {
// 跳过不输出的数据
if len(Rule.GetOutFeild()) == 0 {
continue
}
// 添加工作表
sheet = file.AddSheet(util.ExcelSheetNameReplace(Name))
// 写入表头
row = sheet.AddRow()
for _, title := range Rule.GetOutFeild() {
cell = row.AddCell()
cell.Value = title
}
cell = row.AddCell()
cell.Value = "当前链接"
cell = row.AddCell()
cell.Value = "上级链接"
cell = row.AddCell()
cell.Value = "下载时间"
num := 0 //小计
for _, datacell := range self.DockerQueue.Dockers[dataIndex] {
if datacell["RuleName"].(string) == Name {
row = sheet.AddRow()
for _, title := range Rule.GetOutFeild() {
cell = row.AddCell()
vd := datacell["Data"].(map[string]interface{})
if v, ok := vd[title].(string); ok || vd[title] == nil {
cell.Value = v
} else {
cell.Value = util.JsonString(vd[title])
}
}
cell = row.AddCell()
cell.Value = datacell["Url"].(string)
cell = row.AddCell()
cell.Value = datacell["ParentUrl"].(string)
cell = row.AddCell()
cell.Value = datacell["DownloadTime"].(string)
num++
}
}
// Log.Printf("[任务:%v | 关键词:%v | 小类:%v] 输出 %v 条数据!!!\n", self.Spider.GetName(), self.Spider.GetKeyword(), Name, num)
}
// 创建/打开目录
f2, err := os.Stat(folder2)
if err != nil || !f2.IsDir() {
if err := os.MkdirAll(folder2, 0777); err != nil {
Log.Printf("Error: %v\n", err)
}
}
// 保存文件
err = file.Save(filename)
if err != nil {
Log.Println(err)
}
}
/************************ CSV 输出 ***************************/
Output["csv"] = func(self *Collector, dataIndex int) {
defer func() {
if err := recover(); err != nil {
Log.Println(err)
//.........这里部分代码省略.........
示例12: CreateExcel
func (this *HistoryController) CreateExcel() {
path := beego.AppConfig.String("xlspath")
var file *xlsx.File
var sheet *xlsx.Sheet
var row *xlsx.Row
var cell *xlsx.Cell
var err error
file = xlsx.NewFile()
sheet, err = file.AddSheet("Sheet1")
if err != nil {
beego.Error(err)
return
}
row = sheet.AddRow()
cell = row.AddCell()
cell.Value = "客户"
cell = row.AddCell()
cell.Value = "订单号"
cell = row.AddCell()
cell.Value = "物料编码"
cell = row.AddCell()
cell.Value = "物料品名"
cell = row.AddCell()
cell.Value = "包装规格(kg/桶)"
cell = row.AddCell()
cell.Value = "日期"
cell = row.AddCell()
cell.Value = "数量"
cell = row.AddCell()
cell.Value = "单价"
cell = row.AddCell()
cell.Value = "金额"
cell = row.AddCell()
cell.Value = "备注"
for _, v := range Recode {
row = sheet.AddRow()
cell = row.AddCell()
cell.Value = GetCustomerObj(v.ClientId).Name
cell = row.AddCell()
cell.Value = v.OrderId
product := GetProductObj(v.ProductId)
cell = row.AddCell()
cell.Value = product.PId
cell = row.AddCell()
cell.Value = product.PName
cell = row.AddCell()
cell.Value = product.PType
cell = row.AddCell()
cell.Value = FormatTime(v.CTime)
cell = row.AddCell()
cell.Value = fmt.Sprintf("%0.1f", v.Count)
cell = row.AddCell()
cell.Value = fmt.Sprintf("%0.4f", v.Price)
cell = row.AddCell()
cell.Value = fmt.Sprintf("%0.4f", v.Price*v.Count)
cell = row.AddCell()
cell.Value = v.Remark
}
now := time.Now().Format("2006-01-02_15-04")
err = file.Save(path + "myrecod " + now + ".xlsx")
if err != nil {
beego.Error(err)
return
}
this.Redirect("/history", 302)
}
示例13: main
func main() {
var examFiles []string
var scoreFile *xlsx.File
var row *xlsx.Row
files, err := ioutil.ReadDir(fexamDir)
if err != nil {
log.Println("Error reading fexam directory!")
os.Exit(1)
}
for _, file := range files {
filename := file.Name()
if strings.HasSuffix(filename, ".xlsx") {
examFiles = append(examFiles, fexamDir+filename)
}
}
//create score xlsx file to save student score
scoreFile = xlsx.NewFile()
scoreSheet, err := scoreFile.AddSheet("Sheet1")
if err != nil {
log.Println(err.Error())
}
//loop student exam xlsx file ,read sheet1 col2 to judge
startTime := time.Now().UnixNano()
for _, examFile := range examFiles {
score := 0
xlFile, error := xlsx.OpenFile(examFile) //open excel file
if error != nil {
log.Println("Error reading examfile")
}
//get student's name,no,class
//example:-Unlicensed-13715050_袁慧敏_13医器_java.xlsx
s := strings.Split(examFile[20:strings.Index(examFile, ".xlsx")], "_")
stuNo := s[0]
stuName := s[1]
stuClass := s[2]
sheet := xlFile.Sheets[0]
var stuAnswer []string
for _, row := range sheet.Rows {
if row != nil {
cell := row.Cells[2]
stuAnswer = append(stuAnswer, fmt.Sprintf("%s", cell.String()))
}
}
fmt.Println(stuAnswer)
//get the choice right number
rightChoiceNum := right(stuAnswer[1:21], choiceAnswer)
//get the blank right number
rightBlankNum := right(stuAnswer[22:27], blankAnswer)
score = rightChoiceNum*3 + rightBlankNum*5
fmt.Println(score)
row = scoreSheet.AddRow()
//add student no
cellstuno := row.AddCell()
cellstuno.Value = stuNo
//add student name
cellname := row.AddCell()
cellname.Value = stuName
//add student class
cellclass := row.AddCell()
cellclass.Value = stuClass
//add student score
cellscore := row.AddCell()
cellscore.Value = strconv.Itoa(score)
}
err = scoreFile.Save("./score/score.xlsx")
endTime := time.Now().UnixNano()
log.Printf("试卷批改完成 共加载:%d 条记录, 所花时间:%.1f ms\n", len(examFiles), float64(endTime-startTime)/1000000)
if err != nil {
log.Println(err.Error())
}
}
示例14: genExcelFile
func (this *DataBrowserController) genExcelFile(header []string, selectedColumn []string, datas []tk.M, dataSummary []tk.M, DisplaySumList []SumList) (string, error) {
today := time.Now().UTC()
fileName := "files/databrowser_" + today.Format("2006-01-02T150405") + ".xlsx"
var file *xlsx.File
var sheet *xlsx.Sheet
var row *xlsx.Row
var cell *xlsx.Cell
var err error
file = xlsx.NewFile()
sheet, _ = file.AddSheet("Sheet1")
for i, data := range datas {
if i == 0 {
row = sheet.AddRow()
for _, hdr := range header {
cell = row.AddCell()
cell.Value = hdr
}
}
row = sheet.AddRow()
for _, field := range selectedColumn {
cell = row.AddCell()
cell.SetValue(this.getExcelValue(data, field))
}
}
if DisplaySumList != nil && len(DisplaySumList) > 0 {
var summary = dataSummary[0]
row = sheet.AddRow()
cell = row.AddCell()
cell.SetValue("Average")
cell.Merge(len(DisplaySumList)-1, 0)
row = sheet.AddRow()
for _, i := range DisplaySumList {
cell = row.AddCell()
if i.tipe == "string" || i.tipe == "date" {
cell.SetValue("-")
} else {
field := strings.Replace(i.field, ".", "", -1) + "avg"
cell.SetValue(summary.Get(field))
}
}
row = sheet.AddRow()
cell = row.AddCell()
cell.Merge(len(DisplaySumList)-1, 0)
cell.SetValue("Total")
row = sheet.AddRow()
for _, i := range DisplaySumList {
cell = row.AddCell()
if i.tipe == "string" || i.tipe == "date" {
cell.SetValue("-")
} else {
field := strings.Replace(i.field, ".", "", -1) + "sum"
cell.SetValue(summary.Get(field))
}
}
}
err = file.Save(fileName)
// file := xlsx.NewFile()
// sheet := file.AddSheet("Sheet1")
// // header := []string{"Matnr", "Matkl"}
// // for i, _ := range datas {
// // if i == 0 {
// // rowHeader := sheet.AddRow()
// // for _, hdr := range header {
// // cell := rowHeader.AddCell()
// // cell.Value = hdr
// // }
// // }
// // }
// err := file.Save(fileName)
return fileName, err
}
示例15: Run
func Run(ow func(output string), fetch int, isReset bool, isCheckDate bool, filterDate time.Time) {
if isRunning {
log.Println("isRunning is true ... Skip the exeuction")
return
} else {
isRunning = true
defer stopProcess()
}
helpcase.IsCheckDate = isCheckDate
helpcase.CheckDate = filterDate
init2()
outputWindow = ow
outputWindow("\n處理中\n")
go printProgress()
defer f.Close()
if isReset {
log.Println("Cleaning database ...")
helpcase.CleanDB()
log.Println("Cleaning database done")
}
go helpcase.SubHelpcaseTableParserListener()
go helpcase.SubHelpcaseDetailParserListener(fetch)
a := helpcase.New("http://search.appledaily.com.tw/charity/projlist/", 20)
var result = a.Parse()
if !result {
return
}
// helpcase.WaitGroupForMainTable.Wait()
helpcase.WaitGroupForDetail.Wait()
log.Println("Begin to retry failed request ...")
for _, sno := range helpcase.FailureQueue {
hp := helpcase.GetHelpcase(sno)
log.Println("retry " + hp.SerialNo)
if hp != nil {
helpcase.WaitGroupForDetail.Add(1)
helpcase.BeginToProcessHelpcase(hp)
}
}
outputWindow("\n\n")
outputWindow("\nParse結束,產生Excel檔案中\n")
var file *xlsx.File
var sheet1 *xlsx.Sheet
log.Println("Generating Excel ...")
file = xlsx.NewFile()
sheet1 = file.AddSheet("Sheet1")
createSheet1(sheet1)
sheet2 := file.AddSheet("Sheet2")
createSheet2(sheet2)
err := file.Save(outfolder + "/main.xlsx")
if err != nil {
outputWindow(err.Error())
}
log.Println("Generating Excel Done")
createDonation()
stopProcess()
outputWindow("\n")
outputWindow("完成!\n")
outputWindow("結束時間:" + time.Now().Format("2006/01/02 03:04:05") + "\n")
dir, _ := os.Getwd()
outputWindow("請在下列目錄取得檔案:" + dir + outfolder + "\n")
}