Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 在asp(mvc)中本地读取XLS_Asp.net Mvc_Excel_Local_Xls - Fatal编程技术网

Asp.net mvc 在asp(mvc)中本地读取XLS

Asp.net mvc 在asp(mvc)中本地读取XLS,asp.net-mvc,excel,local,xls,Asp.net Mvc,Excel,Local,Xls,感谢阅读,我的疑问如下,我试图从xls文件中获取数据,但必须在本地完成,无需上传文件,我已经完成了与txts文件类似的操作,并且工作完美: Function Send(ByVal file As HttpPostedFileBase) As ActionResult Dim line As String Dim textreader As System.IO.StreamReader = New StreamReader(file.InputStream) While N

感谢阅读,我的疑问如下,我试图从xls文件中获取数据,但必须在本地完成,无需上传文件,我已经完成了与txts文件类似的操作,并且工作完美:

Function Send(ByVal file As HttpPostedFileBase) As ActionResult
    Dim line As String
    Dim textreader As System.IO.StreamReader = New StreamReader(file.InputStream)
    While Not textreader.EndOfStream
        line = textreader.ReadLine()
        ViewBag.line = line
    End While
    Return View("Index")
End Function
但是我不能对excel文件做同样的处理,首先,因为我不能使用streamreader,所以当使用此代码时,我不知道如何指定xls文件的目录

    Dim oApp As Excel.Application = New Excel.Application
    Dim oWB As Excel.Workbook
    Dim oSheet As Excel.Worksheet
    oWB = oApp.Workbooks.Open(file.inputstream)  <-- HERE IS WHERE I GET (AN OBVIOUS) ERROR
Dim oApp As Excel.Application=New Excel.Application
将oWB设置为Excel.工作簿
将oSheet设置为Excel.工作表

oWB=oApp.Workbooks.Open(file.inputstream)有几种方法,其中之一是访问“数据库样式”文件

因此,基本上您可以查询类似于表的工作表,如果它们确实是表,那么这段代码可能就是您要查找的

另一方面,如果您仍然需要使用自动化,请尝试以下方法:

...    
object missing = System.Reflection.Missing.Value;
wBook = (Excel._Workbook)xl.Workbooks.Open(filePath, false, false, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); 
...

读取输入流
我尝试过类似的方法,但问题是我不知道文件路径,我也不知道,因为新浏览器不显示完整路径请参见更新的答案:读取InputStream将流复制到文件中。然后你就可以用它了。顺便说一句,由于安全原因,浏览器不会向您显示完整路径,而且因为它是客户端机器路径,因此毫无意义,您无法从服务器端访问它。mm我尝试了filestream的一些功能,但未能成功,我将尝试此功能,很多次:),抱歉,我无法给您答复:(没问题,如果答案是,别忘了检查一下。祝你好运。哦,这(显然是哈哈)是我的错,我可以让它工作,谢谢你的帮助:),只要我可以,我会给你代表
...    
object missing = System.Reflection.Missing.Value;
wBook = (Excel._Workbook)xl.Workbooks.Open(filePath, false, false, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); 
...
using (var fileStream = File.Create(filePath)) {
     file.InputStream.CopyTo(fileStream); 
} 
// Now you got your stream on a file (filePath) so you can work with it.