1
我有这样的代码,但它保存到文件如何将Excel工作表写入MemoryStream?
Excel.Application app = new Excel.Application();
app.Workbooks.Add();
Excel._Worksheet sheet = app.ActiveSheet;
sheet.Cells[1, "A"] = "login";
sheet.Cells[1, "B"] = "e-mail";
int row = 1;
foreach (ProviderUser u in users)
{
row++;
sheet.Cells[row, "A"] = u.UserName;
sheet.Cells[row, "A"] = u.Email;
}
string pathToSave = Path.Combine(Environment.CurrentDirectory, "users.xlsx");
sheet.SaveAs(pathToSave);
app.Quit();
这是不可能达成任何结果,Excel是进程外的一个COM服务器。它的数据不能直接访问,你必须通过命名空间方法。你只能要求它保存到一个文件。 –
可能重复[如何写一个Excel工作簿到.NET中的MemoryStream?](http://stackoverflow.com/questions/156500/how-to-write-an-excel-workbook-to-a-memorystream-中网) –