Ejemplo n.º 1
0
        /// 格式化操作
        /// <param name="context"></param>
        public override void Format(SheetFormatterContext context)
        {
            context.ClearRowContent(_startTagCell.X);
            context.ClearRowContent(_endTagCell.X);
            if (null == _cellInfoList || _cellInfoList.Count <= 0 || null == _dataSource)
            {
                return;
            }
            var itemCount = 0;

            foreach (TSource itemSource in _dataSource)
            {
                if (itemCount++ > 0)
                {
                    context.CopyRows(_startTagCell.X, _endTagCell.X);  //追加空行
                }
                foreach (RepeaterCellInfo <TSource> cellInfo in _cellInfoList)
                {
                    var rowIndex = context.GetCurrentRowIndex(cellInfo.CellPoint.X);
                    var row      = context.Sheet.GetRow(rowIndex) ?? context.Sheet.CreateRow(rowIndex);
                    var cell     = row.GetCell(cellInfo.CellPoint.Y) ?? row.CreateCell(cellInfo.CellPoint.Y);
                    SetCellValue(cell, cellInfo.DgSetValue(itemSource));
                }
            }
        }
Ejemplo n.º 2
0
 public static byte[] ExportToBuffer(IWorkbook workbook, params SheetFormatterContainer[] containers)
 {
     foreach (var container in containers)
     {
         var sheet   = workbook.GetSheet(container.SheetName);
         var context = new SheetFormatterContext(sheet, container.Formatters);
         context.Format();
     }
     return(workbook.SaveToBuffer());
 }
Ejemplo n.º 3
0
        public static byte[] ExportToBuffer(string templateFile, params SheetFormatterContainer[] containers)
        {
            var workbook = LoadTemplateWorkbook(templateFile);

            foreach (var container in containers)
            {
                var sheet   = workbook.GetSheet(container.SheetName);  //加载第一个sheet
                var context = new SheetFormatterContext(sheet, container.Formatters);
                context.Format();
            }
            return(workbook.SaveToBuffer());
        }
Ejemplo n.º 4
0
        /// 格式化操作
        /// <param name="context"></param>
        public override void Format(SheetFormatterContext context)
        {
            var rowIndex = context.GetCurrentRowIndex(_cellPoint.X);
            var row      = context.Sheet.GetRow(rowIndex);

            if (null == row)
            {
                row = context.Sheet.CreateRow(rowIndex);
            }
            var cell = row.GetCell(_cellPoint.Y);

            if (null == cell)
            {
                cell = row.CreateCell(_cellPoint.Y);
            }
            SetCellValue(cell, _value);
        }
Ejemplo n.º 5
0
 public override void Format(SheetFormatterContext context)
 {
     context.ClearRowContent(_templateRowIndex); //清除模板行单元格内容
     if (null == _columnInfoList || _columnInfoList.Count <= 0 || null == _dataSource)
     {
         return;
     }
     foreach (TSource rowSource in _dataSource)
     {
         var row = context.Sheet.GetRow(context.GetCurrentRowIndex(_templateRowIndex));
         foreach (TableColumnInfo <TSource> colInfo in _columnInfoList)
         {
             var cell = row.GetCell(colInfo.ColumnIndex);
             SetCellValue(cell, colInfo.DgSetValue(rowSource));
         }
         context.InsertEmptyRow(_templateRowIndex); //追加空行
     }
     context.RemoveRow(_templateRowIndex);          //删除空行
 }
Ejemplo n.º 6
0
        public override void Format(SheetFormatterContext context)
        {
            var rowIndex = context.GetCurrentRowIndex(_cellPoint.X);
            var row      = context.Sheet.GetRow(rowIndex);

            if (null == row)
            {
                row = context.Sheet.CreateRow(rowIndex);
            }
            var cell = row.GetCell(_cellPoint.Y);

            if (null == cell)
            {
                cell = row.CreateCell(_cellPoint.Y);
            }
            if (cell.CellType.Equals(CellType.String))
            {
                SetCellValue(cell, cell.StringCellValue.Replace(string.Format("$[{0}]", _parameterName), _value));
            }
        }
Ejemplo n.º 7
0
        /// 格式化操作
        /// <param name="context"></param>
        public override void Format(SheetFormatterContext context)
        {
            context.ClearRowContent(TemplateRowIndex); //清除模板行单元格内容
            if (null == ColumnInfoList || ColumnInfoList.Count <= 0 || null == DataSource)
            {
                return;
            }
            var itemCount = 0;

            foreach (TSource rowSource in DataSource)
            {
                if (itemCount++ > 0)
                {
                    context.InsertEmptyRow(TemplateRowIndex);  //追加空行
                }
                var row = context.Sheet.GetRow(context.GetCurrentRowIndex(TemplateRowIndex));
                foreach (TableColumnInfo <TSource> colInfo in ColumnInfoList)
                {
                    var cell = row.GetCell(colInfo.ColumnIndex);
                    SetCellValue(cell, colInfo.DgSetValue(rowSource));
                }
            }
        }
Ejemplo n.º 8
0
        /// 格式化操作
        public override void Format(SheetFormatterContext context)
        {
            context.ClearRowContent(TemplateRowIndex); //清除模板行单元格内容
            if (null == ColumnInfoList || ColumnInfoList.Count <= 0 || null == DataSource)
            {
                return;
            }
            var itemCount = 0;
            var sheet     = context.Sheet;
            int rowIndex  = 0;
            Stack <LevelInfo> levelStack = new Stack <LevelInfo>();


            foreach (TSource rowSource in DataSource)
            {
                if (itemCount++ > 0)
                {
                    //如果不是第一行时执行的操作
                    context.InsertEmptyRow(TemplateRowIndex);  //追加空行
                }

                //当前行索引
                rowIndex = context.GetCurrentRowIndex(TemplateRowIndex);
                //当前行的层级
                int level = GetLevel(rowSource);
                //当前行
                var row = sheet.GetRow(rowIndex);

                if (levelStack.Count > 0)
                {
                    LevelInfo top = levelStack.Peek();
                    while (level < top.Level)
                    {
                        sheet.GroupRow(top.RowIndex, rowIndex - 1);
                        levelStack.Pop();
                        top = levelStack.Peek();
                    }
                    if (level > top.Level)
                    {
                        levelStack.Push(new LevelInfo(rowIndex, level));
                    }
                }
                else
                {
                    levelStack.Push(new LevelInfo(rowIndex, level));
                }

                foreach (TableColumnInfo <TSource> colInfo in ColumnInfoList)
                {
                    var    cell  = row.GetCell(colInfo.ColumnIndex);
                    object value = colInfo.DgSetValue(rowSource);
                    if (colInfo.ColumnIndex == _levelColumnIndex)
                    {
                        //处理层级列,如果是层级列,则增加缩进
                        value = new string(' ', level * 2) + value;
                    }
                    SetCellValue(cell, value);
                }
            }

            while (levelStack.Count > 0)
            {
                LevelInfo top = levelStack.Pop();
                if (0 < top.Level)
                {
                    sheet.GroupRow(top.RowIndex, rowIndex);
                }
            }
        }
Ejemplo n.º 9
0
 public abstract void Format(SheetFormatterContext context);