Ejemplo n.º 1
0
        /// <summary>
        ///     导出格式化处理后的文件到二进制文件流
        /// </summary>
        /// <param name="templateFile"></param>
        /// <param name="sheetFormatters"></param>
        /// <returns></returns>
        public static byte[] ExportToBuffer(string templateFile, params SheetFormatter[] sheetFormatters)
        {
            IWorkbook workbook = NPOIHelper.LoadWorkbook(templateFile);

            foreach (SheetFormatter sheetFormatter in sheetFormatters)
            {
                sheetFormatter.Format(workbook);
            }
            return(workbook.SaveToBuffer());
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     导出格式化处理后的文件到内存流
        /// </summary>
        /// <param name="templateFile"></param>
        /// <param name="sheetFormatters"></param>
        /// <returns></returns>
        public static Stream ExportToStream(string templateFile, params SheetFormatter[] sheetFormatters)
        {
            IWorkbook workbook = NPOIHelper.LoadWorkbook(templateFile);

            foreach (SheetFormatter sheetFormatter in sheetFormatters)
            {
                sheetFormatter.Format(workbook);
            }
            var ms = new MemoryStream();

            workbook.Write(ms);
            return(ms);
        }
Ejemplo n.º 3
0
        /// 导出到Web
        /// <param name="templateFile"></param>
        /// <param name="targetFile"></param>
        /// <param name="containers"></param>
        public static void ExportToWeb(string templateFile, string targetFile, params SheetFormatterContainer[] containers)
        {
            #region 参数验证

            if (string.IsNullOrEmpty(templateFile))
            {
                throw new ArgumentNullException("templateFile");
            }
            if (!File.Exists(templateFile))
            {
                throw new FileNotFoundException(templateFile + " 文件不存在!");
            }

            #endregion 参数验证

            IWorkbook workbook = NPOIHelper.LoadWorkbook(templateFile);
            ExportToWeb(workbook, targetFile, containers);
        }
Ejemplo n.º 4
0
        /// 导出格式化处理后的文件到二进制文件流
        /// <param name="templateFile"></param>
        /// <param name="containers"></param>
        /// <returns></returns>
        public static byte[] ExportToBuffer(string templateFile, params SheetFormatterContainer[] containers)
        {
            var workbook = NPOIHelper.LoadWorkbook(templateFile);

            return(ExportToBuffer(workbook, containers));
        }