public void CellIndexAdditionTest()
        {
            var a = new ExcelCellIndex("A1");
            var b = new ExcelCellIndex("A1");

            a.Add(b).CellReference.Should().Be("A1");
        }
        public void MergeCells(ExcelCellIndex upperLeft, ExcelCellIndex lowerRight)
        {
            var mergeCells = worksheet.GetFirstChild <MergeCells>() ?? InsertWorksheetChild(worksheet, new MergeCells());

            mergeCells.AppendChild(new MergeCell {
                Reference = $"{upperLeft.CellReference}:{lowerRight.CellReference}"
            });
        }
示例#3
0
        public void EqualsReturnsFalseForNonIndex()
        {
            var index = new ExcelCellIndex(1, 2);

            var result = index.Equals("asdas");

            result.Should().Be(false);
        }
示例#4
0
        public void EqualsWorksForOtherCellIndexes(int row1, int column1, int row2, int column2, bool equals)
        {
            var index1 = new ExcelCellIndex(row1, column1);
            var index2 = new ExcelCellIndex(row2, column2);

            var result = index1.Equals(index2);

            result.Should().Be(equals);
        }
        public void CellIndexSubtractionTest()
        {
            var a = new ExcelCellIndex("A1");
            var b = new ExcelCellIndex("A1");

            "A1".Should().Be(a.Subtract(b).CellReference);

            b = new ExcelCellIndex("ABC345");
            "ABC345".Should().Be(b.Subtract(a).CellReference);
        }
示例#6
0
        public void GetCellTest()
        {
            var document  = ExcelDocumentFactory.CreateFromTemplate(File.ReadAllBytes(GetFilePath("template.xlsx")), logger);
            var worksheet = document.GetWorksheet(0);

            var position = new ExcelCellIndex("B9");
            var cell     = worksheet.GetCell(position);

            cell.GetStringValue().Should().Be("Model:Document:B10:C11");

            document.Dispose();
        }
示例#7
0
        public void CellsInRangeTest()
        {
            var document  = ExcelDocumentFactory.CreateFromTemplate(File.ReadAllBytes(GetFilePath("template.xlsx")), logger);
            var worksheet = document.GetWorksheet(0);

            var upperLeft  = new ExcelCellIndex("A22");
            var lowerRight = new ExcelCellIndex("A24");
            var cells      = worksheet.GetSortedCellsInRange(upperLeft, lowerRight).ToArray();

            cells.Length.Should().Be(3);
            cells[1].GetStringValue().Should().Be("Value:String:Name");
            cells[2].GetStringValue().Should().Be("Value:String:Address");

            document.Dispose();
        }
        public void CellIndexConstructorsTest()
        {
            var a = new ExcelCellIndex("A1");

            a.RowIndex.Should().Be(1);
            a.ColumnIndex.Should().Be(1);

            var b = new ExcelCellIndex(1, 1);

            b.CellReference.Should().Be("A1");

            var c = new ExcelCellIndex("AAA23");

            c.RowIndex.Should().Be(23);
            c.ColumnIndex.Should().Be(703);
        }
 public IEnumerable <IExcelCell> GetSortedCellsInRange(ExcelCellIndex upperLeft, ExcelCellIndex lowerRight)
 {
     return(rowsCache.RangeFromTo((uint)upperLeft.RowIndex, (uint)lowerRight.RowIndex + 1)
            .Select(x => x.Value)
            .SelectMany(row => row.Elements <Cell>()
                        .Where(cell =>
     {
         var columnIndex = new ExcelCellIndex(cell.CellReference).ColumnIndex;
         return columnIndex >= upperLeft.ColumnIndex && columnIndex <= lowerRight.ColumnIndex;
     }))
            .OrderBy(cell =>
     {
         var cellIndex = new ExcelCellIndex(cell.CellReference);
         return (cellIndex.RowIndex - upperLeft.RowIndex) * (lowerRight.ColumnIndex - upperLeft.ColumnIndex) + cellIndex.ColumnIndex;
     })
            .Select(cell => new ExcelCell(cell, documentStyle, excelSharedStrings)));
 }
示例#10
0
        public IExcelCell CreateCell(int index)
        {
            var cellReference = new ExcelCellIndex((int)row.RowIndex.Value, index).CellReference;

            if (row.Elements <Cell>().Any(c => c.CellReference.Value == cellReference))
            {
                return(new ExcelCell(row.Elements <Cell>().First(c => c.CellReference.Value == cellReference), documentStyle, excelSharedStrings));
            }

            var refCell = row.Elements <Cell>().FirstOrDefault(cell => IsCellReferenceGreaterThan(cell.CellReference.Value, cellReference));
            var newCell = new Cell
            {
                CellReference = new ExcelCellIndex((int)row.RowIndex.Value, index).CellReference
            };

            row.InsertBefore(newCell, refCell);

            return(new ExcelCell(newCell, documentStyle, excelSharedStrings));
        }
 public IExcelCell GetCell(ExcelCellIndex position)
 {
     return(GetSortedCellsInRange(position, position).FirstOrDefault());
 }
 public CellPosition(int rowIndex, int columnIndex)
 {
     internalCellIndex = new ExcelCellIndex(rowIndex, columnIndex);
 }
 public CellPosition(ExcelCellIndex excelCellIndex)
 {
     internalCellIndex = excelCellIndex;
 }
 public CellPosition(string cellReference)
 {
     internalCellIndex = new ExcelCellIndex(cellReference);
 }