Example #1
0
        protected override List <Cell> GetCells(int rowIndex, int maxColEnd)
        {
            List <Cell> result = new List <Cell>();

            Aspose.Cells.Row  row       = worksheet.Cells.Rows[rowIndex];
            Aspose.Cells.Cell firstCell = row.FirstCell;
            Aspose.Cells.Cell lastCell  = row.LastCell;
            if (lastCell == null)
            {
                return(result);
            }

            for (int i = 0; i <= lastCell.Column; i++)
            {
                if (i >= maxColEnd)
                {
                    break;
                }
                Aspose.Cells.Cell cell = row.GetCellOrNull(i);
                result.Add(new AsposeExcelCell(cell, worksheet));
                if (cell != null && cell.IsMerged && cell.GetMergedRange().ColumnCount > 1)
                {
                    i += cell.GetMergedRange().ColumnCount - 1;
                }
            }
            return(result);
        }
        public override List <Cell> GetCells(int rowIndex, int maxColEnd = IAdapter.MaxColumnsCount)
        {
            List <Cell> result = new List <Cell>();

            Aspose.Cells.Row  row       = worksheet.Cells.Rows[rowIndex];
            Aspose.Cells.Cell firstCell = row.FirstCell;
            Aspose.Cells.Cell lastCell  = row.LastCell;
            if (lastCell == null)
            {
                return(result);
            }

            for (int i = 0; i <= lastCell.Column; i++)
            {
                if (i >= maxColEnd)
                {
                    break;
                }
                Aspose.Cells.Cell cell = row.GetCellOrNull(i);
                result.Add(new AsposeExcelCell(cell, worksheet));
                if (cell != null && cell.IsMerged && cell.GetMergedRange().ColumnCount > 1)
                {
                    i += cell.GetMergedRange().ColumnCount - 1;
                }
            }

            /*
             * IEnumerator enumerator = worksheet.Cells.Rows[rowIndex].GetEnumerator();
             * int range_end = -1;
             * while (enumerator.MoveNext())
             * {
             *  Aspose.Cells.Cell cell = (Aspose.Cells.Cell)enumerator.Current;
             *  if (cell.Column < range_end)
             *  {
             *      index++;
             *      continue;
             *  }
             *
             *  result.Add(new AsposeExcelCell(cell));
             *
             *  if (cell.IsMerged)
             *  {
             *      int first = cell.GetMergedRange().FirstColumn;
             *      int count = cell.GetMergedRange().ColumnCount;
             *      range_end = first + count;
             *  }
             *  index++;
             * }
             */
            return(result);
        }
Example #3
0
        public bool IsMatch(Aspose.Cells.Row row, int referenceYear)
        {
            if (this.Value.Equals("reference"))
            {
                this.Value = referenceYear;
            }

            object value = this.Column.GetCleanCell(row);

            if (this.UseFunction)
            {
                value = this.TransformeValue(value.ToString(), referenceYear);
            }

            return(this.CheckValue(value));
        }
        public bool IsInclud(Aspose.Cells.Row row, int referenceYear)
        {
            var first  = this.MatchConditions.First();
            var result = first.IsMatch(row, referenceYear);

            foreach (var item in this.MatchConditions.Skip(1))
            {
                var nextResult = item.IsMatch(row, referenceYear);
                if (first.LogicalOperatorToNextCondition == LogicalOperator.And)
                {
                    result = result && nextResult;
                }
                else
                {
                    result = result || nextResult;
                }

                first = item;
            }

            return(result);
        }
Example #5
0
        public MemoryStream ToExcel <T>(IPaginatedList <T> list)
        {
            try
            {
                //Create excel workbook
                Aspose.Cells.Workbook  book  = new Aspose.Cells.Workbook();
                Aspose.Cells.Worksheet sheet = book.Worksheets[0];

                List <string>  objHeaders = new List <string>();
                PropertyInfo[] headerInfo = typeof(T).GetProperties();
                foreach (var property in headerInfo)
                {
                    var attribute = property.GetCustomAttributes(typeof(DisplayNameAttribute), false)
                                    .Cast <DisplayNameAttribute>().FirstOrDefault();

                    //Avoid columns from Base Business Entity
                    if (property.Name == "ChangedFields")
                    {
                        break;
                    }
                    objHeaders.Add(property.Name);
                }

                sheet.Cells.ImportCustomObjects(list.Items.ToList(), objHeaders.ToArray(), true, 1, 0, list.TotalRecordCount, true, string.Empty, false);

                #region Header style

                Aspose.Cells.Style style = book.CreateStyle();
                style.Font.IsBold = true;
                // Define a style flag struct.
                Aspose.Cells.StyleFlag flag = new Aspose.Cells.StyleFlag();
                flag.FontBold = true;
                // Get the first row in the first worksheet.
                Aspose.Cells.Row row = book.Worksheets[0].Cells.Rows[1];
                // Apply the style to it.
                row.ApplyStyle(style, flag);

                #endregion

                // Auto-fit all the columns
                book.Worksheets[0].AutoFitColumns();

                using (MemoryStream outputStream = new MemoryStream())
                {
                    //Save workbook as stream instead of saving it to the Disk
                    book.Save(outputStream, Aspose.Cells.SaveFormat.Xlsx);

                    //Call dispose methods
                    sheet.Dispose();
                    book.Dispose();

                    outputStream.Position = 0;
                    return(outputStream);
                }
            }
            catch (Exception)
            {
                // TODO : Handle out of memory exception
                throw;
            }
        }