public SheetWriter <TModel> Build(ISheet sheet)
        {
            if (sheet == null)
            {
                return(null);
            }

            var workBook     = sheet.Workbook;
            var headerStyles = new Dictionary <SheetColumnOption <TModel>, ICellStyle>();
            var lineStyles   = new Dictionary <SheetColumnOption <TModel>, ICellStyle>();
            Func <IWorkbook, ICellStyle> createEmptyStyle = (workbook) => null;

            foreach (var option in options)
            {
                var createHeaderStyle = option.CreateHeaderStyle ?? createDefaultHeaderStyle ?? createEmptyStyle;
                var createLineStyle   = option.CreateLineStyle ?? createDefaultLineStyle ?? createEmptyStyle;

                headerStyles.Add(option, createHeaderStyle(workBook));
                lineStyles.Add(option, createLineStyle(workBook));
            }

            var writer = new SheetWriter <TModel>(sheet, options, headerStyles, lineStyles);

            return(writer);
        }
Beispiel #2
0
        /// <summary>
        /// 将数据写入一个指定名称的表格
        /// </summary>
        public WorkbookWriter WriteSheet <TModel>(string sheetName, SheetWriterBuilder <TModel> builder, IEnumerable <TModel> source)
        {
            ISheet sheet = workBook.GetSheet(sheetName) ?? workBook.CreateSheet(sheetName);
            SheetWriter <TModel> writer = builder.Build(sheet);

            writer.Write(source);

            return(this);
        }