1

我有这个代码,但它保存到文件中

            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();
4

1 回答 1

1

您知道文件的位置还是需要先使用 Excel 创建它?

您可以使用轻松获取文件的字节数组

var buffer = File.ReadAllBytes(pathToSave)

然后用字节数组创建你的内存流:

var stream = new MemoryStream(buffer);

你是这个意思吗?

于 2012-09-05T13:38:31.957 回答