本文整理匯總了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;
}