本文整理汇总了C#中OfficeOpenXml.ExcelPackage.ToMemoryStream方法的典型用法代码示例。如果您正苦于以下问题:C# ExcelPackage.ToMemoryStream方法的具体用法?C# ExcelPackage.ToMemoryStream怎么用?C# ExcelPackage.ToMemoryStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OfficeOpenXml.ExcelPackage
的用法示例。
在下文中一共展示了ExcelPackage.ToMemoryStream方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
/// <summary>
/// Saves an ExcelPackage as a BinaryFile and stores it in the database
/// </summary>
/// <param name="excel">The ExcelPackage object to save</param>
/// <param name="fileName">The filename to save the workbook as</param>
/// <param name="rockContext">The RockContext to use</param>
/// <param name="binaryFileType">Optionally specifies the BinaryFileType to apply to this file for security purposes</param>
/// <returns></returns>
public static BinaryFile Save( ExcelPackage excel, string fileName, RockContext rockContext, BinaryFileType binaryFileType = null )
{
if ( binaryFileType == null )
{
binaryFileType = new BinaryFileTypeService( rockContext ).Get( Rock.SystemGuid.BinaryFiletype.DEFAULT.AsGuid() );
}
var ms = excel.ToMemoryStream();
var binaryFile = new BinaryFile()
{
Guid = Guid.NewGuid(),
IsTemporary = true,
BinaryFileTypeId = binaryFileType.Id,
MimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
FileName = fileName,
ContentStream = ms
};
var binaryFileService = new BinaryFileService( rockContext );
binaryFileService.Add( binaryFile );
rockContext.SaveChanges();
return binaryFile;
}