从Stream中读取excel文件的内容

时间:2013-01-29 09:26:29

标签: c# sharepoint-2010

我有一个从excel文件创建的文件流。我需要阅读此流的内容并从中获取excel表。任何想法我怎么能这样做?

注意:我必须在不使用任何第三方库的情况下执行此操作

WebRequest request = WebRequest.Create(new Uri("http://servername:1056/ExcelFiles/Myfile.xlsx", UriKind.Absolute));
request.UseDefaultCredentials = true;
WebResponse response = request.GetResponse();
Stream fs = response.GetResponseStream() as Stream;

这里我需要读取fs的内容而不必将文件保存到本地系统/磁盘

2 个答案:

答案 0 :(得分:0)

尝试这样的事情

WebClient webClient= new WebClient();
Stream stream = webClient.OpenRead("http://servername:1056/ExcelFiles/Myfile.xlsx");
  //StreamReader streamReader = new StreamReader(stream);
  //String content = streamReader.ReadToEnd();
// Read the Document using SpreadSheetDocument Method 
var ssDoc = SpreadSheetDocument.Open(stream, false);

SpreadsheetDocument.Open method (Stream, Boolean)

答案 1 :(得分:0)

您可以使用SpreadSheetDocument从具有静态方法的流中读取数据

var doc = SpreadSheetDocument.Open(docName, true);

有关此链接的更多信息http://msdn.microsoft.com/en-us/library/ff478410

读为memmorystream

WebClient wc = new WebClient();

byte[] fileArray = wc.DownloadData("url is inserted here");

MemoryStream ms = new MemoryStream(fileArray);