|
@@ -1,153 +1,142 @@
|
|
|
package services
|
|
|
|
|
|
-import (
|
|
|
- "encoding/json"
|
|
|
- "eta/eta_api/models/data_manage"
|
|
|
- "eta/eta_api/models/data_manage/request"
|
|
|
- "eta/eta_api/utils"
|
|
|
- "fmt"
|
|
|
- "github.com/xuri/excelize/v2"
|
|
|
- "strconv"
|
|
|
- "time"
|
|
|
-)
|
|
|
-
|
|
|
-func MeetingProbabilities() (err error) {
|
|
|
- templatePath := "/Users/xiexiaoyuan/1111.xlsx"
|
|
|
- f, tmpErr := excelize.OpenFile(templatePath)
|
|
|
- if tmpErr != nil {
|
|
|
- fmt.Println("打开文件失败,Err:" + tmpErr.Error())
|
|
|
- err = tmpErr
|
|
|
- return
|
|
|
- }
|
|
|
- defer func() {
|
|
|
- // 关闭工作簿
|
|
|
- if err := f.Close(); err != nil {
|
|
|
- fmt.Println(err)
|
|
|
- }
|
|
|
- }()
|
|
|
- // 获取工作表中指定单元格的值
|
|
|
- cell, err := f.GetCellValue("Sheet1", "B5")
|
|
|
- if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
- return
|
|
|
- }
|
|
|
- fmt.Println(cell)
|
|
|
- // 获取 Sheet1 上所有单元格
|
|
|
- rows, err := f.GetRows("Sheet1")
|
|
|
- if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
- return
|
|
|
- }
|
|
|
- minCowLength := 60
|
|
|
- minRowlength := 84
|
|
|
- realCowLength := minCowLength
|
|
|
- realRowLength := minRowlength
|
|
|
- data := make([][]interface{}, 0)
|
|
|
- var null []struct{}
|
|
|
- cellData := make([]request.ISheetCellData, 0)
|
|
|
- var tmpCt request.ISheetDataCt
|
|
|
- tmpCt.Fa = "General"
|
|
|
- tmpCt.T = "g"
|
|
|
-
|
|
|
- for r, row := range rows {
|
|
|
- lenCow := len(row)
|
|
|
- var dataRow []interface{}
|
|
|
- for c, colCell := range row {
|
|
|
- if colCell == "" {
|
|
|
- dataRow = append(dataRow, null)
|
|
|
- } else {
|
|
|
- var tmp request.ISheetData
|
|
|
- tmp.M = colCell
|
|
|
- tmp.Ct = tmpCt
|
|
|
- tmp.V = colCell
|
|
|
- dataRow = append(dataRow, tmp)
|
|
|
-
|
|
|
- var tmpS request.ISheetCellData
|
|
|
- tmpS.R = r
|
|
|
- tmpS.C = c
|
|
|
- tmpS.V = tmp
|
|
|
- cellData = append(cellData, tmpS)
|
|
|
- }
|
|
|
- fmt.Print(colCell, "\t")
|
|
|
- }
|
|
|
- if lenCow < minCowLength {
|
|
|
- lastCow := minCowLength - lenCow
|
|
|
- for i := 0; i < lastCow; i++ {
|
|
|
- dataRow = append(dataRow, null)
|
|
|
- }
|
|
|
- }
|
|
|
- realCowLength = len(dataRow)
|
|
|
- data = append(data, dataRow)
|
|
|
- }
|
|
|
- lenRow := len(rows)
|
|
|
- //补充剩余的单元格
|
|
|
- if lenRow < minRowlength {
|
|
|
- lastRow := minRowlength - lenRow
|
|
|
- for i := 0; i < lastRow; i++ {
|
|
|
- var dataRow []interface{}
|
|
|
- for j := 0; j < minCowLength; j++ {
|
|
|
- dataRow = append(dataRow, null)
|
|
|
- }
|
|
|
- data = append(data, dataRow)
|
|
|
- }
|
|
|
- }
|
|
|
- realRowLength = len(data)
|
|
|
- //visibleDataRow
|
|
|
- var visibleDataRow []int
|
|
|
- tmpVdr := 0
|
|
|
- for i := 1; i <= realRowLength; i++ {
|
|
|
- tmpVdr = i * 20
|
|
|
- visibleDataRow = append(visibleDataRow, tmpVdr)
|
|
|
- }
|
|
|
- var visibleDataColumn []int
|
|
|
- tmpVdr = 0
|
|
|
- for i := 1; i <= realCowLength; i++ {
|
|
|
- tmpVdr = i * 74
|
|
|
- visibleDataColumn = append(visibleDataColumn, tmpVdr)
|
|
|
- }
|
|
|
- sheet := new(request.ISheet)
|
|
|
- sheet.ScrollTop = 0
|
|
|
- sheet.ScrollLeft = 0
|
|
|
- sheet.Index = "Sheet_pekSifat0Kci_1694244624851"
|
|
|
- sheet.Status = 1
|
|
|
- sheet.JfGirdSelectSave = []struct{}{}
|
|
|
- sheet.LuckySheetSelectSave = []struct{}{}
|
|
|
- sheet.Data = data
|
|
|
- sheet.Config = make(map[string]struct{}, 0)
|
|
|
- sheet.VisibleDataRow = visibleDataRow
|
|
|
- sheet.VisibleDataColumn = visibleDataColumn
|
|
|
- sheet.ChWidth = 4560
|
|
|
- sheet.RhHeight = 1760
|
|
|
- sheet.LuckySheetSelectionRange = make([]int, 0)
|
|
|
- sheet.ZoomRatio = 1
|
|
|
- sheet.CellData = cellData
|
|
|
-
|
|
|
- var content []byte
|
|
|
- content, err = json.Marshal(sheet)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- var req request.AddExcelInfoReq
|
|
|
- req.ExcelClassifyId = 19
|
|
|
- timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
|
|
|
- req.ExcelName = "Meeting" + timestamp
|
|
|
- excelInfo := &data_manage.ExcelInfo{
|
|
|
- //ExcelInfoId: 0,
|
|
|
- ExcelName: req.ExcelName,
|
|
|
- Source: 1,
|
|
|
- ExcelType: req.ExcelType,
|
|
|
- UniqueCode: utils.MD5(utils.EXCEL_DATA_PREFIX + "_" + timestamp),
|
|
|
- ExcelClassifyId: req.ExcelClassifyId,
|
|
|
- SysUserId: 19,
|
|
|
- SysUserRealName: "admin",
|
|
|
- Content: string(content),
|
|
|
- ExcelImage: req.ExcelImage,
|
|
|
- Sort: 0,
|
|
|
- IsDelete: 0,
|
|
|
- ModifyTime: time.Now(),
|
|
|
- CreateTime: time.Now(),
|
|
|
- }
|
|
|
-
|
|
|
- err = data_manage.AddExcelInfo(excelInfo)
|
|
|
- return
|
|
|
-}
|
|
|
+//func MeetingProbabilities() (err error) {
|
|
|
+// templatePath := "/Users/xiexiaoyuan/1111.xlsx"
|
|
|
+// f, tmpErr := excelize.OpenFile(templatePath)
|
|
|
+// if tmpErr != nil {
|
|
|
+// fmt.Println("打开文件失败,Err:" + tmpErr.Error())
|
|
|
+// err = tmpErr
|
|
|
+// return
|
|
|
+// }
|
|
|
+// defer func() {
|
|
|
+// // 关闭工作簿
|
|
|
+// if err := f.Close(); err != nil {
|
|
|
+// fmt.Println(err)
|
|
|
+// }
|
|
|
+// }()
|
|
|
+// // 获取工作表中指定单元格的值
|
|
|
+// cell, err := f.GetCellValue("Sheet1", "B5")
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println(err)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// fmt.Println(cell)
|
|
|
+// // 获取 Sheet1 上所有单元格
|
|
|
+// rows, err := f.GetRows("Sheet1")
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println(err)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// minCowLength := 60
|
|
|
+// minRowlength := 84
|
|
|
+// realCowLength := minCowLength
|
|
|
+// realRowLength := minRowlength
|
|
|
+// data := make([][]interface{}, 0)
|
|
|
+// var null []struct{}
|
|
|
+// cellData := make([]request.ISheetCellData, 0)
|
|
|
+// var tmpCt request.ISheetDataCt
|
|
|
+// tmpCt.Fa = "General"
|
|
|
+// tmpCt.T = "g"
|
|
|
+//
|
|
|
+// for r, row := range rows {
|
|
|
+// lenCow := len(row)
|
|
|
+// var dataRow []interface{}
|
|
|
+// for c, colCell := range row {
|
|
|
+// if colCell == "" {
|
|
|
+// dataRow = append(dataRow, null)
|
|
|
+// } else {
|
|
|
+// var tmp request.ISheetData
|
|
|
+// tmp.M = colCell
|
|
|
+// tmp.Ct = tmpCt
|
|
|
+// tmp.V = colCell
|
|
|
+// dataRow = append(dataRow, tmp)
|
|
|
+//
|
|
|
+// var tmpS request.ISheetCellData
|
|
|
+// tmpS.R = r
|
|
|
+// tmpS.C = c
|
|
|
+// tmpS.V = tmp
|
|
|
+// cellData = append(cellData, tmpS)
|
|
|
+// }
|
|
|
+// fmt.Print(colCell, "\t")
|
|
|
+// }
|
|
|
+// if lenCow < minCowLength {
|
|
|
+// lastCow := minCowLength - lenCow
|
|
|
+// for i := 0; i < lastCow; i++ {
|
|
|
+// dataRow = append(dataRow, null)
|
|
|
+// }
|
|
|
+// }
|
|
|
+// realCowLength = len(dataRow)
|
|
|
+// data = append(data, dataRow)
|
|
|
+// }
|
|
|
+// lenRow := len(rows)
|
|
|
+// //补充剩余的单元格
|
|
|
+// if lenRow < minRowlength {
|
|
|
+// lastRow := minRowlength - lenRow
|
|
|
+// for i := 0; i < lastRow; i++ {
|
|
|
+// var dataRow []interface{}
|
|
|
+// for j := 0; j < minCowLength; j++ {
|
|
|
+// dataRow = append(dataRow, null)
|
|
|
+// }
|
|
|
+// data = append(data, dataRow)
|
|
|
+// }
|
|
|
+// }
|
|
|
+// realRowLength = len(data)
|
|
|
+// //visibleDataRow
|
|
|
+// var visibleDataRow []int
|
|
|
+// tmpVdr := 0
|
|
|
+// for i := 1; i <= realRowLength; i++ {
|
|
|
+// tmpVdr = i * 20
|
|
|
+// visibleDataRow = append(visibleDataRow, tmpVdr)
|
|
|
+// }
|
|
|
+// var visibleDataColumn []int
|
|
|
+// tmpVdr = 0
|
|
|
+// for i := 1; i <= realCowLength; i++ {
|
|
|
+// tmpVdr = i * 74
|
|
|
+// visibleDataColumn = append(visibleDataColumn, tmpVdr)
|
|
|
+// }
|
|
|
+// sheet := new(request.ISheet)
|
|
|
+// sheet.ScrollTop = 0
|
|
|
+// sheet.ScrollLeft = 0
|
|
|
+// sheet.Index = "Sheet_pekSifat0Kci_1694244624851"
|
|
|
+// sheet.Status = 1
|
|
|
+// sheet.JfGirdSelectSave = []struct{}{}
|
|
|
+// sheet.LuckySheetSelectSave = []struct{}{}
|
|
|
+// sheet.Data = data
|
|
|
+// sheet.Config = make(map[string]struct{}, 0)
|
|
|
+// sheet.VisibleDataRow = visibleDataRow
|
|
|
+// sheet.VisibleDataColumn = visibleDataColumn
|
|
|
+// sheet.ChWidth = 4560
|
|
|
+// sheet.RhHeight = 1760
|
|
|
+// sheet.LuckySheetSelectionRange = make([]int, 0)
|
|
|
+// sheet.ZoomRatio = 1
|
|
|
+// sheet.CellData = cellData
|
|
|
+//
|
|
|
+// var content []byte
|
|
|
+// content, err = json.Marshal(sheet)
|
|
|
+// if err != nil {
|
|
|
+// return
|
|
|
+// }
|
|
|
+// var req request.AddExcelInfoReq
|
|
|
+// req.ExcelClassifyId = 19
|
|
|
+// timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
|
|
|
+// req.ExcelName = "Meeting" + timestamp
|
|
|
+// excelInfo := &data_manage.ExcelInfo{
|
|
|
+// //ExcelInfoId: 0,
|
|
|
+// ExcelName: req.ExcelName,
|
|
|
+// Source: 1,
|
|
|
+// ExcelType: req.ExcelType,
|
|
|
+// UniqueCode: utils.MD5(utils.EXCEL_DATA_PREFIX + "_" + timestamp),
|
|
|
+// ExcelClassifyId: req.ExcelClassifyId,
|
|
|
+// SysUserId: 19,
|
|
|
+// SysUserRealName: "admin",
|
|
|
+// Content: string(content),
|
|
|
+// ExcelImage: req.ExcelImage,
|
|
|
+// Sort: 0,
|
|
|
+// IsDelete: 0,
|
|
|
+// ModifyTime: time.Now(),
|
|
|
+// CreateTime: time.Now(),
|
|
|
+// }
|
|
|
+//
|
|
|
+// err = data_manage.AddExcelInfo(excelInfo)
|
|
|
+// return
|
|
|
+//}
|