读取excel文件
This commit is contained in:
@@ -107,6 +107,7 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i
|
|||||||
if len(files) == 0 {
|
if len(files) == 0 {
|
||||||
return "", errors.New("没有文件上传!")
|
return "", errors.New("没有文件上传!")
|
||||||
}
|
}
|
||||||
|
|
||||||
//读取excel文件
|
//读取excel文件
|
||||||
xlsx, err := excelize.OpenFile(files[0].Filename)
|
xlsx, err := excelize.OpenFile(files[0].Filename)
|
||||||
// xlsx, err := excelize.OpenFile("111.xlsx")
|
// xlsx, err := excelize.OpenFile("111.xlsx")
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/business/jxstore/yonghui"
|
"git.rosy.net.cn/jx-callback/business/jxstore/yonghui"
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
)
|
)
|
||||||
@@ -12,16 +15,32 @@ type YongHuiController struct {
|
|||||||
|
|
||||||
// @Title 读取永辉excel文件
|
// @Title 读取永辉excel文件
|
||||||
// @Description 读取永辉excel文件
|
// @Description 读取永辉excel文件
|
||||||
// @Param token header string true "认证token"
|
// @Param token header string false "认证token"
|
||||||
// @Param isAsync query bool false "是否异步,缺省是同步"
|
// @Param isAsync query bool false "是否异步,缺省是同步"
|
||||||
// @Success 200 {object} controllers.CallResult
|
// @Success 200 {object} controllers.CallResult
|
||||||
// @Failure 200 {object} controllers.CallResult
|
// @Failure 200 {object} controllers.CallResult
|
||||||
// @router /LoadExcelByYongHui [post]
|
// @router /LoadExcelByYongHui [post,get]
|
||||||
func (c *YongHuiController) LoadExcelByYongHui() {
|
func (c *YongHuiController) LoadExcelByYongHui() {
|
||||||
c.callLoadExcelByYongHui(func(params *tYonghuiLoadExcelByYongHuiParams) (retVal interface{}, errCode string, err error) {
|
if c.Ctx.Input.IsGet() {
|
||||||
r := c.Ctx.Request
|
w := c.Ctx.ResponseWriter
|
||||||
files := r.MultipartForm.File["userfiles"]
|
// 上传页面
|
||||||
retVal, err = yonghui.LoadExcelByYongHui(params.Ctx, files, params.IsAsync)
|
w.Header().Add("Content-Type", "text/html")
|
||||||
return retVal, "", err
|
w.WriteHeader(200)
|
||||||
})
|
html := `
|
||||||
|
<form enctype="multipart/form-data" action="/v2/yonghui/LoadExcelByYongHui" method="POST">
|
||||||
|
Send this file: <input name="userfiles" multiple accept="*" type="file" />
|
||||||
|
<input type="submit" value="Send File" />
|
||||||
|
</form>
|
||||||
|
`
|
||||||
|
io.WriteString(w, html)
|
||||||
|
} else if c.Ctx.Input.IsPost() {
|
||||||
|
c.callLoadExcelByYongHui(func(params *tYonghuiLoadExcelByYongHuiParams) (retVal interface{}, errCode string, err error) {
|
||||||
|
r := c.Ctx.Request
|
||||||
|
files := r.MultipartForm.File["userfiles"]
|
||||||
|
fmt.Println(r)
|
||||||
|
fmt.Println(r.MultipartForm)
|
||||||
|
retVal, err = yonghui.LoadExcelByYongHui(params.Ctx, files, params.IsAsync)
|
||||||
|
return retVal, "", err
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2002,7 +2002,7 @@ func init() {
|
|||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "LoadExcelByYongHui",
|
Method: "LoadExcelByYongHui",
|
||||||
Router: `/LoadExcelByYongHui`,
|
Router: `/LoadExcelByYongHui`,
|
||||||
AllowHTTPMethods: []string{"post"},
|
AllowHTTPMethods: []string{"post","get"},
|
||||||
MethodParams: param.Make(),
|
MethodParams: param.Make(),
|
||||||
Filters: nil,
|
Filters: nil,
|
||||||
Params: nil})
|
Params: nil})
|
||||||
|
|||||||
Reference in New Issue
Block a user