[英]How to write an Excel worksheet to a 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創建文件?
您可以使用以下命令輕松獲取文件的字節數組
var buffer = File.ReadAllBytes(pathToSave)
然后使用字節數組創建內存流:
var stream = new MemoryStream(buffer);
你是這個意思嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.