public virtual void Render(SheetContext sheetContext)
        {
            Repeater repeater = sheetContext.WorksheetContainer.Repeaters[Name];

            if (RendererList.IsNullOrEmpty())
            {
                throw new RenderException($"RepeaterRenderer[{repeater.Name}] is empty");
            }

            if (!DataSource.IsNull())
            {
                foreach (var item in DataSource)
                {
                    sheetContext.CopyRepeaterTemplate(repeater, () =>
                    {
                        foreach (var renderer in RendererList.OrderBy(renderer => renderer.SortNum(sheetContext)))
                        {
                            renderer.Render(sheetContext, item);
                        }
                    });
                }
            }

            sheetContext.RemoveRepeaterTemplate(repeater);
        }
        private void RenderDataTableBody(SheetContext sheetContext, DataTabler dataTabler)
        {
            var dataTableDataLocation = dataTabler.DataStart;

            var columns     = DataSource.Columns;
            var rows        = DataSource.Rows;
            int columnIndex = 0;
            int rowIndex    = 0;

            foreach (DataColumn dataColumn in columns)
            {
                rowIndex = 0;
                foreach (DataRow dataRow in rows)
                {
                    int   rowLocation    = dataTableDataLocation.RowIndex + rowIndex;
                    int   columnLocation = dataTableDataLocation.ColumnIndex + columnIndex;
                    ICell cell           = sheetContext.GetCell(rowLocation, columnLocation, copyBeforeColumnCell: true);
                    if (null == cell)
                    {
                        throw new RenderException($"DataTable [{dataTabler.Name}],cell[{rowLocation},{columnLocation}] is null");
                    }
                    cell.Value = dataRow[dataColumn].CastTo <string>();
                    rowIndex  += 1;
                }
                columnIndex += 1;
            }
        }
        public virtual void Render(SheetContext sheetContext)
        {
            Repeater repeater = sheetContext.WorksheetContainer.Repeaters[Name];

            if (RendererList.IsNullOrEmpty())
            {
                throw new RenderException($"RepeaterRenderer[{repeater.Name}] is empty");
            }

            if (!DataSource.IsNull())
            {
                DataSource.All(item =>
                {
                    sheetContext.CopyRepeaterTemplate(repeater, () =>
                    {
                        RendererList.OrderBy(renderer => renderer.SortNum(sheetContext)).All(renderer =>
                        {
                            renderer.Render(sheetContext, item);
                            return(true);
                        });
                    });
                    return(true);
                });
            }

            sheetContext.RemoveRepeaterTemplate(repeater);
        }
        public int SortNum(SheetContext sheetContext)
        {
            Parameter parameter = sheetContext.WorksheetContainer.Parameters[Name];

            if (parameter.Locations.IsNullOrEmpty())
            {
                throw new TemplateException($"parameter[{parameter.Name}] non-existent.");
            }
            return(parameter.Locations.Min(location => location.RowIndex));
        }
        public int SortNum(SheetContext sheetContext)
        {
            Repeater repeater = sheetContext.WorksheetContainer.Repeaters[Name];

            if (repeater.Start.IsNull())
            {
                throw new TemplateException($"RepeaterRenderer[{repeater.Name}] start non-existent.");
            }
            if (repeater.End.IsNull())
            {
                throw new TemplateException($"RepeaterRenderer[{repeater.Name}] end non-existent.");
            }
            return(repeater.Start.RowIndex);
        }
        public void Render(SheetContext sheetContext)
        {
            DataTabler dataTabler = sheetContext.WorksheetContainer.DataTablers[Name];

            if (DataSource.IsNull())
            {
                throw new RenderException($"The DataSource of DataTableRenderer <[{dataTabler.Name}] is empty");
            }

            sheetContext.FillDataTablerLayout(dataTabler, () =>
            {
                RenderDataTableHender(sheetContext, dataTabler);
                RenderDataTableBody(sheetContext, dataTabler);
            });
        }
Beispiel #7
0
        public void PushSheet(string name)
        {
            foreach (var parentCtx in this.groupCtxStack)
            {
                if (parentCtx.Sheet.Name == name)
                {
                    throw new BinariexException("reading schema", "Cannot put sheet recursively.");
                }
            }

            var sheet = OpenSheet(name);

            if (!this.sheetCtxMap.TryGetValue(name, out var sheetCtx))
            {
                var cursorRowIndex = 1;
                if (sheet.Dimension != null)
                {
                    while (sheet.Cells[cursorRowIndex, sheet.Dimension.Columns].Text == ExcelWriter.HEADER_MARKER)
                    {
                        cursorRowIndex++;
                    }
                }

                sheetCtx = new SheetContext
                {
                    Sheet          = sheet,
                    HeaderRowCount = cursorRowIndex - 1,
                    CursorRowIndex = 1
                };
                this.sheetCtxMap[name] = sheetCtx;
            }

            var groupCtx = new GroupContext
            {
                Sheet             = sheet,
                SheetContext      = sheetCtx,
                HeaderRowIndex    = 0,
                TopRowIndex       = sheetCtx.CursorRowIndex,
                LeftColumnIndex   = 1,
                CursorRowIndex    = sheetCtx.CursorRowIndex,
                CursorColumnIndex = 1,
            };

            this.groupCtxStack.Push(groupCtx);
        }
        public int SortNum(SheetContext sheetContext)
        {
            DataTabler EDataTableRender = sheetContext.WorksheetContainer.DataTablers[Name];

            if (EDataTableRender.HeaderStart.IsNull())
            {
                throw new TemplateException($"DataTableRenderer <[{EDataTableRender.Name}] header non-existent.");
            }
            if (EDataTableRender.DataStart.IsNull())
            {
                throw new TemplateException($"DataTableRenderer <[{EDataTableRender.Name}] data non-existent.");
            }

            EDataTableRender.HenderEnd = new Location(EDataTableRender.HeaderStart.RowIndex, EDataTableRender.HeaderStart.ColumnIndex + DataSource.Columns.Count - 1);
            EDataTableRender.DataEnd   = new Location(EDataTableRender.DataStart.RowIndex + DataSource.Rows.Count - 1, EDataTableRender.DataStart.ColumnIndex + DataSource.Columns.Count - 1);

            return(EDataTableRender.HeaderStart.RowIndex);
        }
Beispiel #9
0
        public void Render(SheetContext sheetContext)
        {
            Parameter parameter = sheetContext.WorksheetContainer.Parameters[Name];

            foreach (var location in parameter.Locations)
            {
                ICell cell = sheetContext.GetCell(location);
                if (null == cell)
                {
                    throw new RenderException($"parameter[{parameter.Name}],cell[{location.RowIndex},{location.ColumnIndex}] is null");
                }
                var parameterName = $"$[{parameter.Name}]";
                if (parameterName.Equals(cell.GetStringValue().Trim()))
                {
                    cell.Value = Value;
                }
                else
                {
                    cell.Value = (cell.GetStringValue().Replace(parameterName, Value.CastTo <string>()));
                }
            }
        }
        private void RenderDataTableHender(SheetContext sheetContext, DataTabler dataTabler)
        {
            var dataTableHeaderLocation = dataTabler.HeaderStart;

            var columns              = DataSource.Columns;
            int columnCount          = columns.Count;
            int rowHeaderLocation    = dataTableHeaderLocation.RowIndex;
            int columnHeaderLocation = dataTableHeaderLocation.ColumnIndex + columns.Count - 1;

            for (int startH = dataTableHeaderLocation.ColumnIndex; startH < columnHeaderLocation; startH++)
            {
                ICell cell = sheetContext.GetCell(rowHeaderLocation, startH, copyBeforeColumnCell: true);
                if (null == cell)
                {
                    throw new RenderException($"DataTable[{dataTabler.Name}],cell[{rowHeaderLocation},{startH}] is null");
                }
            }
            sheetContext.MergeCells(rowHeaderLocation, rowHeaderLocation, dataTableHeaderLocation.ColumnIndex, columnHeaderLocation);

            ICell merageCell = sheetContext.GetCell(dataTableHeaderLocation);

            merageCell.Value = DataSource.TableName.CastTo <string>();
        }
        public int SortNum(SheetContext sheetContext)
        {
            Repeater repeater = sheetContext.WorksheetContainer.Repeaters[Name];

            return(repeater.Start.RowIndex);
        }
        public int SortNum(SheetContext sheetContext)
        {
            Parameter parameter = sheetContext.WorksheetContainer.Parameters[Name];

            return(parameter.Locations.Min(location => location.RowIndex));
        }
Beispiel #13
0
 public Sheet1Controller(SheetContext context)
 {
     _context = context;
 }
 public UploadFileController(SheetContext context)
 {
     _context = context;
 }