fix : readExcel

This commit is contained in:
chenh1 2021-10-02 03:40:24 +08:00
parent 3767579468
commit f34272df8c
10 changed files with 53 additions and 38 deletions

View File

@ -4,9 +4,10 @@
<list default="true" id="90d49d24-cd7e-4f14-b075-c6e5fe5ae2ce" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/controllers/Administrator.go" beforeDir="false" afterPath="$PROJECT_DIR$/controllers/Administrator.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/controllers/supervisor.go" beforeDir="false" afterPath="$PROJECT_DIR$/controllers/supervisor.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/img/9000010142092---119.png" beforeDir="false" afterPath="$PROJECT_DIR$/img/9000010142092---119.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/lastupdate.tmp" beforeDir="false" afterPath="$PROJECT_DIR$/lastupdate.tmp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/responses/admin.go" beforeDir="false" afterPath="$PROJECT_DIR$/responses/admin.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/test.xlsx" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/test1.xlsm" beforeDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -87,7 +88,7 @@
<property name="go.import.settings.migrated" value="true" />
<property name="go.sdk.automatically.set" value="true" />
<property name="go.tried.to.enable.integration.vgo.integrator" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../openscore" />
<property name="node.js.detected.package.eslint" value="true" />
<property name="node.js.detected.package.tslint" value="true" />
<property name="node.js.selected.package.eslint" value="(autodetect)" />
@ -184,8 +185,8 @@
<breakpoints>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/controllers/score.go</url>
<line>159</line>
<option name="timeStamp" value="8" />
<line>783</line>
<option name="timeStamp" value="15" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>

View File

@ -13,6 +13,7 @@ import (
"image/color"
"image/draw"
"image/png"
"io"
"io/ioutil"
"log"
"openscore/models"
@ -132,7 +133,9 @@ func (c *AdminApiController) ReadExcel(){
defer c.ServeJSON()
var resp Response
var err error
_, header, err := c.GetFile("excel")
file, header, err := c.GetFile("excel")
err = err
if err != nil {
log.Println(err)
@ -140,9 +143,8 @@ func (c *AdminApiController) ReadExcel(){
c.Data["json"] = resp
return
}
//----------------------------------------------------
tempFile, err := os.Create(header.Filename)
io.Copy(tempFile,file)
f, err := excelize.OpenFile(header.Filename)
if err != nil {
log.Println(err)
@ -160,19 +162,19 @@ func (c *AdminApiController) ReadExcel(){
c.Data["json"] = resp
return
}
fmt.Println(rows)
for i:=1;i<len(rows);i++ {
for j:=1;j<len(rows[i]);j++ {
if i>=1&&j>=3 {
//准备数据
testIdStr:=rows[i][0]
testId, _ := strconv.ParseInt(testIdStr, 10, 64)
questionIds := strings.Split(rows[0][j], "-")
questionIdStr:=questionIds[0]
questionId, _ := strconv.ParseInt(questionIdStr, 10, 64)
questionDetailIdStr:=questionIds[3]
testIdStr:=rows[i][0]
testId, _ := strconv.ParseInt(testIdStr, 10, 64)
questionIds := strings.Split(rows[0][j], "-")
questionIdStr:=questionIds[0]
questionId, _ := strconv.ParseInt(questionIdStr, 10, 64)
questionDetailIdStr:=questionIds[3]
questionDetailId, _ := strconv.ParseInt(questionDetailIdStr, 10, 64)
name:=rows[i][2]
//填充数据
@ -183,7 +185,7 @@ func (c *AdminApiController) ReadExcel(){
s:=rows[i][j]
split := strings.Split(s, "\n")
src := UploadPic(rows[i][0]+rows[0][j], split)
testPaperInfo.Pic_src=src
testPaperInfo.Pic_src=src
//查看大题试卷是否已经导入
has,err := testPaper.GetTestPaper(testId)
if err!=nil {
@ -194,7 +196,6 @@ func (c *AdminApiController) ReadExcel(){
if !has {
testPaper.Test_id=testId
testPaper.Question_id=questionId
testPaper.Question_status=1
testPaper.Candidate=name
err = testPaper.Insert()
if err != nil {
@ -224,7 +225,7 @@ func (c *AdminApiController) ReadExcel(){
questionIds := strings.Split(rows[0][k], "-")
questionIdStr:=questionIds[0]
questionId, _ := strconv.ParseInt(questionIdStr, 10, 64)
var topic models.Topic
var topic models.Topic
topic.Question_id=questionId
topic.Import_number=int64(len(rows)-1)
err = topic.Update()
@ -236,14 +237,16 @@ func (c *AdminApiController) ReadExcel(){
}
}
err = tempFile.Close()
if err!=nil {
log.Println(err)
}
err = os.Remove(header.Filename)
if err!=nil {
log.Println(err)
}
if err!=nil {
log.Println(err)
}
err = os.Remove("excelFile")
if err!=nil {
log.Println(err)
}
//------------------------------------------------
data := make(map[string]interface{})
data["data"] =nil
@ -252,6 +255,7 @@ func (c *AdminApiController) ReadExcel(){
}
/**
2.样卷导入
*/
@ -261,7 +265,11 @@ func (c *AdminApiController) ReadExampleExcel(){
defer c.ServeJSON()
var resp Response
var err error
_, header, err := c.GetFile("excel")
//----------------------------------------------------
file, header, err := c.GetFile("excel")
err = err
if err != nil {
log.Println(err)
@ -269,9 +277,8 @@ func (c *AdminApiController) ReadExampleExcel(){
c.Data["json"] = resp
return
}
//----------------------------------------------------
tempFile, err := os.Create(header.Filename)
io.Copy(tempFile,file)
f, err := excelize.OpenFile(header.Filename)
if err != nil {
log.Println(err)
@ -366,13 +373,15 @@ func (c *AdminApiController) ReadExampleExcel(){
}
err = tempFile.Close()
if err!=nil {
log.Println(err)
}
err = os.Remove("excelFile")
err = os.Remove(header.Filename)
if err!=nil {
log.Println(err)
}
//------------------------------------------------
data := make(map[string]interface{})
data["data"] =nil
@ -386,7 +395,11 @@ func (c *AdminApiController) ReadAnswerExcel(){
defer c.ServeJSON()
var resp Response
var err error
_, header, err := c.GetFile("excel")
//----------------------------------------------------
file, header, err := c.GetFile("excel")
err = err
if err != nil {
log.Println(err)
@ -394,9 +407,8 @@ func (c *AdminApiController) ReadAnswerExcel(){
c.Data["json"] = resp
return
}
//----------------------------------------------------
tempFile, err := os.Create(header.Filename)
io.Copy(tempFile,file)
f, err := excelize.OpenFile(header.Filename)
if err != nil {
log.Println(err)
@ -491,13 +503,15 @@ func (c *AdminApiController) ReadAnswerExcel(){
}
err = tempFile.Close()
if err!=nil {
log.Println(err)
}
err = os.Remove("excelFile")
err = os.Remove(header.Filename)
if err!=nil {
log.Println(err)
}
//------------------------------------------------
data := make(map[string]interface{})
data["data"] =nil

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 0 B

BIN
img/9000010243092---118.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
img/9000010243092---119.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

BIN
img/9000010243094---122.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
img/9000010243094---123.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View File

@ -1 +1 @@
{"C:\\Users\\chen\\go\\src\\open-ct\\controllers":1633083779570682400}
{"C:\\Users\\chen\\go\\src\\open-ct\\controllers":1633104387065548000}

BIN
test.xlsx

Binary file not shown.

Binary file not shown.