有没有一种方法可以格式化aspose.cells生成的excel表,而无需拨打workbook.save.save()?
我的客户有一个用例将搜索结果导出到电子表格。我想将格式的电子表格返回给他们,但是我可以通过
workbook.Save(memoryStream, SaveFormat.Xlsx);
调用上述方法调用问题的格式更改的唯一方法是,将电子表格实际上保存到我的本地项目文件夹中,这不是所需的行为。如何在不拨打workbook.save()的情况下返回电子表格?
public byte[] ExportSpreadsheet(List<Result> results)
{
var workbook = MakeWorkbook(results);
var memoryStream = new MemoryStream();
workbook.Save(memoryStream, SaveFormat.Xlsx); // this saves the spreadsheet in the project
memoryStream.Seek(0, SeekOrigin.Begin);
var byteArray = memoryStream.ToArray();
return byteArray;
}
private Workbook MakeWorkbook(List<Result> results)
{
var workbook = new Workbook();
AddDataToWorkbook(workbook);
ApplyFormattingAfterData(workbook);
return workbook;
}
My customer has a use case for exporting search results to a spreadsheet. I would like to return a formatted spreadsheet to them, but the only way I can get the formatting changes to "stick" is by calling
workbook.Save(memoryStream, SaveFormat.Xlsx);
The problem with calling the method above, is that a spreadsheet will actually be saved to my local project folder, which is not desired behavior. How can I return the spreadsheet without calling workbook.Save()?
public byte[] ExportSpreadsheet(List<Result> results)
{
var workbook = MakeWorkbook(results);
var memoryStream = new MemoryStream();
workbook.Save(memoryStream, SaveFormat.Xlsx); // this saves the spreadsheet in the project
memoryStream.Seek(0, SeekOrigin.Begin);
var byteArray = memoryStream.ToArray();
return byteArray;
}
private Workbook MakeWorkbook(List<Result> results)
{
var workbook = new Workbook();
AddDataToWorkbook(workbook);
ApplyFormattingAfterData(workbook);
return workbook;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你做得很好。这条线将保存工作簿以流式传输,而不是在物理文件中。它不会保存到项目的文件夹或路径。
PS。我正在Aspose担任支持开发人员/传播者。
You are doing ok. This line will save the workbook to stream and not on physical filepath. It won't save to your project's folder or path.
PS. I am working as Support developer/ Evangelist at Aspose.