xlsx文件第一列导出为TXT文件名,第二列导出为TXT文件内容
代码内容
package main import ( "fmt" "github.com/xuri/excelize/v2" "os" "strconv" ) var ( xlsxPath = "./xlsx/key.xlsx" content string txtPath string dNum int ) func main() { fmt.Print("转换数量:") fmt.Scan(&dNum) fmt.Println("加载xlsx文件...") dNum = dNum + 1 xTot() } func xTot() { xlsxFile, err := excelize.OpenFile(xlsxPath) if err != nil { fmt.Println("xlsx/key.xlsx 文件不存在!") } defer xlsxFile.Close() for num := 1; num < dNum; num++ { title, _ := xlsxFile.GetCellValue("Sheet1", "A"+strconv.Itoa(num)) if title == "" { fmt.Println("第", num, "行标题为空,进程结束!") num = 99999999 return } content, _ = xlsxFile.GetCellValue("Sheet1", "B"+strconv.Itoa(num)) fmt.Println("第", num, "条:", title, ".txt") txtPath = "./txt/" + title + ".txt" txtFile, _ := os.OpenFile(txtPath, os.O_CREATE|os.O_WRONLY|os.O_EXCL, 0666) txtFile.WriteString(content) } }