如何使用内存流读取excel文件数据?

时间:2016-05-27 05:22:11

标签: c# excel

我想从我从ARC发送的JSON数据中读取Excel文件,有人可以帮我解决一下吗?

public bool ControlAttachment(AttachmentFile file)
{
    try
    {
        if (file != null && file.File != null)
        {
            string xlsfile = file.File;
            string [] xls = {"application/excel","application/vnd.msexcel","xls","xlsx","application/vnd.ms-excel",};

            if (xls.ToList().Contains(file.FileType.Trim()))
            {
                file.FileType = ".xls";
                byte[] contents = Convert.FromBase64String(xlsfile);
                string LogFilePaths = ConfigurationManager.AppSettings["ExcelMapperPath"];
                string fileName = file.FileName.Split('.')[0] + file.FileType;
                string LogFile = HttpContext.Current.Server.MapPath(LogFilePaths + file.FileName.Split('.')[0] + file.FileType);

                System.IO.File.WriteAllBytes(LogFile, contents);

                if (!File.Exists(LogFile))
                { 
                    File.Create(LogFile).Dispose();
                }
                MemoryStream ms = new MemoryStream();
                using (var fs = new FileStream(LogFile, FileMode.Open, FileAccess.Write))
                { 
                        ms.CopyTo(fs);
                        ms.Dispose();
                }
            }
        }
        return true;
    }
    catch 
    {
        return false;
    }
}

0 个答案:

没有答案
相关问题