Exemple #1
0
        public void MakeReport2()
        {
            List <Product> Products = GetProductData().ToList();
            DataProcessor  dp       = new DataProcessor();

            dp.BeforeGroup = (x, d) =>
            {
                if (1 == d)
                {
                    var          groupColor        = x as IGrouping <string, Product>;
                    TemplateRow  tmp               = new TemplateRow();
                    TemplateCell colorTemplateCell = new TemplateCell()
                    {
                        content = "Color:", cellStyle = "B2"
                    };
                    tmp.RowContent.AddRange(new List <TemplateCell>()
                    {
                        colorTemplateCell, groupColor.Key, groupColor.AsEnumerable().Count()
                    });
                    dp.Result.Add(tmp);
                }
            };
            dp.Process(Products.GroupBy(a => a.Color));
            ReportMaker reportMaker = new ReportMaker();
            Dictionary <string, List <TemplateRow> > dict = new Dictionary <string, List <TemplateRow> >()
            {
                { "Products", dp.Result }
            };
            var image = reportMaker.FillDataInTemplate("Template1.xlsx", dict);

            File.WriteAllBytes("Test2.xlsx", image.ToArray());
        }
Exemple #2
0
        static void Add5and1TemplateLayout(Guid TemplateTypeGuid)
        {
            using (var db = new AllInOneContext())
            {
                List <TemplateCell> tcList = new List <TemplateCell>();
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        TemplateCell tcl = new TemplateCell();
                        if (i == 0 && j == 0)
                        {
                            tcl.TemplateCellId = Guid.NewGuid();
                            tcl.Column         = j;
                            tcl.Row            = i;
                            tcl.RowSpan        = 2;
                            tcl.ColumnSpan     = 2;
                        }
                        else if (i <= 1 && j <= 1)
                        {
                            continue;
                        }
                        else
                        {
                            tcl = new TemplateCell()
                            {
                                TemplateCellId = Guid.NewGuid(),
                                Column         = j,
                                Row            = i,
                                RowSpan        = 1,
                                ColumnSpan     = 1,
                            };
                        }
                        tcList.Add(tcl);
                    }
                }


                TemplateLayout tll = new TemplateLayout()
                {
                    Columns          = 3,
                    Rows             = 3,
                    TemplateLayoutId = Guid.NewGuid(),

                    LayoutType   = db.SystemOption.First(t => t.SystemOptionCode.Equals("11400002")),
                    TemplateType = db.SystemOption.First(t => t.SystemOptionId.Equals(TemplateTypeGuid)),
                    Cells        = tcList
                };
                tll.TemplateLayoutName = "1+5";
                db.TemplateLayout.Add(tll);
                db.SaveChanges();
            }
        }
        public OptionTag[] Parse(string value, IXLRange range, TemplateCell cell, out string newValue)
        {
            List <OptionTag> result = new List <OptionTag>();

            foreach (var expr in GetAllTags(value))
            {
                var optionTag = ParseTag(expr.Substring(2, expr.Length - 4));
                if (optionTag == null)
                {
                    continue;
                }
                optionTag.Cell  = cell;
                optionTag.Range = range;
                result.Add(optionTag);
                value = value.Replace(expr, "");
            }
            newValue = value.Trim();
            return(result.ToArray());
        }
        public OptionTag[] Parse(string value, IXLRange range, TemplateCell cell, out string newValue)
        {
            List <OptionTag> result = new List <OptionTag>();

            foreach (var expr in GetAllTags(value))
            {
                var optionTag = ParseTag(expr.Substring(2, expr.Length - 4));
                if (optionTag == null)
                {
                    continue;
                }
                optionTag.Cell  = cell;
                optionTag.Range = range;
                if (cell.XLCell.Address.RowNumber != cell.Row) // is range tag
                {
                    optionTag.RangeOptionsRow = range.LastRow().RangeAddress;
                }
                result.Add(optionTag);
                value = value.Replace(expr, "");
            }
            newValue = value.Trim();
            return(result.ToArray());
        }
Exemple #5
0
        static void AddStandarTemplateLayout(int row, int column, Guid TemplateTypeGuid)
        {
            using (var db = new AllInOneContext())
            {
                List <TemplateCell> tcList = new List <TemplateCell>();
                for (int i = 0; i < row; i++)
                {
                    for (int j = 0; j < column; j++)
                    {
                        TemplateCell tcl = new TemplateCell()
                        {
                            TemplateCellId = Guid.NewGuid(),
                            Column         = j,
                            Row            = i,
                            RowSpan        = 1,
                            ColumnSpan     = 1,
                        };
                        tcList.Add(tcl);
                    }
                }

                TemplateLayout tll = new TemplateLayout()
                {
                    Columns          = column,
                    Rows             = row,
                    TemplateLayoutId = Guid.NewGuid(),

                    LayoutType   = db.SystemOption.First(t => t.SystemOptionCode.Equals("11400001")),
                    TemplateType = db.SystemOption.First(t => t.SystemOptionId.Equals(TemplateTypeGuid)),
                    Cells        = tcList
                };
                tll.TemplateLayoutName = string.Format("{0}", row * column);
                db.TemplateLayout.Add(tll);
                db.SaveChanges();
            }
        }