如何获取在MVC控制器中上传的excel文件 [英] How to get an excel file uploaded in MVC controller

查看:197
本文介绍了如何获取在MVC控制器中上传的excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试上传excel文件。我正在使用AngularJS + MVC。视图是一个html文件,文件上传是简单的html文件上传。上传文件后,当我单击一个按钮时,我必须能够访问MVC控制器中的excel文件。





我怎样才能实现这个目标?



谢谢

Hi,

I am trying to upload an excel file . I am using AngularJS + MVC. The view is an html file and the file upload is simple html file upload. After uploading the file , when i click a button, i must be able to access the excel file in the MVC controller.


How can i achieve this?

Thanks

推荐答案

我使用过NPOI并且使用起来非常简单:

使用Xlfile作为FileStream =新FileStream(FileName,FileMode.Open,FileAccess。阅读)

使用XLBook作为HSSFWorkbook =新的HSSFWorkbook(Xlfile)

使用XLSheet作为NPOI.SS.UserModel.Sheet = XLBook.GetSheetAt(0)



Dim CurrentRow As NPOI.HSSF.UserModel.HSSFRow

Dim CurrentCell As NPOI.SS.UserModel.Cell

Dim RowEnum As IEnumerator = XLSheet.GetRowEnumerator()



虽然RowEnum.MoveNext

如果(RowEnum.Current IsNot Nothing)那么

CurrentRow = TryCast(RowEnum.Current,NPOI.HSSF.UserModel.HSSFRow)

选择案例CurrentCell.CellType

案例NPOI.SS.UserModel.CellType.STRING

'CurrentCell.StringCellValue

案例NPOI.SS.UserModel.CellType.NUMERIC

'CurrentCell.NumericCellValue.ToString()

结束选择

结束时

结束使用

结束使用

Xlfile.Close()

结束使用
I've used NPOI and it's quite simple to use:
Using Xlfile As FileStream = New FileStream(FileName, FileMode.Open, FileAccess.Read)
Using XLBook As HSSFWorkbook = New HSSFWorkbook(Xlfile)
Using XLSheet As NPOI.SS.UserModel.Sheet = XLBook.GetSheetAt(0)

Dim CurrentRow As NPOI.HSSF.UserModel.HSSFRow
Dim CurrentCell As NPOI.SS.UserModel.Cell
Dim RowEnum As IEnumerator = XLSheet.GetRowEnumerator()

While RowEnum.MoveNext
If (RowEnum.Current IsNot Nothing) Then
CurrentRow = TryCast(RowEnum.Current, NPOI.HSSF.UserModel.HSSFRow)
Select Case CurrentCell.CellType
Case NPOI.SS.UserModel.CellType.STRING
' CurrentCell.StringCellValue
Case NPOI.SS.UserModel.CellType.NUMERIC
' CurrentCell.NumericCellValue.ToString()
End Select
End While
End Using
End Using
Xlfile.Close()
End Using


这篇关于如何获取在MVC控制器中上传的excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆