0
그래서 Excel에서 변환 한 CSV 파일을 가져 오려고하는데 두 열에 질문과 대답이 있습니다. 난 그냥 파일을 구문 분석하고 지금은 콘솔에 출력하고 싶습니다. 내 파일 sample.csv를 선택하면 끝내기 1을 수행하고 파일을 찾을 수 없다고 말합니다. 어떤 도움이라도 큰 도움이 될 것입니다.양식에서 CSV 파일 가져 오기 및 GO 결과를 구문 분석
HTML
<form class="form-horizontal" method="post" action="/deck/{{ .deck.Id }}/bulkimport" >
<div class="form-group">
<div class="col-lg-10">
<div class="alert alert-info">
<input type="file" name="file" style="visibility: hidden;" id="pdffile"/>
<label>Choose A File</label>
<div class="input-append">
<input type="text" id="subfile" class="input-xlarge"/>
<a class="btn" onclick="$('#pdffile').click();">Browse</a>
</div>
<br/>
<!-- <button id="showHidden" class="btn btn-warning">Show/Hide Input Field</button> -->
<input name="deck" value="{{.deck.Id}}" hidden>
<button class="btn btn-primary" type="submit" name="submit">Upload</button>
</div>
</div>
</div>
</form>
GO 기능
func BulkImortFlashCardsFormPage (req *http.Request, params martini.Params, c Flashcard,errors binding.Errors, r render.Render,session sessions.Session, db *DB) {
id := params["id"]
f, _, err := req.FormFile("file")
if err != nil {
// log.Fatal("Can't Find File ")
session.AddFlash(FlashError {"global", "File not found", "", "error"})
r.Redirect("/deck/" + id + "/cardlist")
return
}
defer f.Close()
reader := csv.NewReader(f)
record, err := reader.ReadAll()
if err != nil {
fmt.Println("Error:", err)
return
}
for _, line := range record {
fmt.Println(line[1])
}
session.AddFlash(FlashError {"global", "Cards created succesfully", "", "success"})
r.Redirect("/deck/" + id + "/cardlist")
return
}