Esempio n. 1
0
        public void Should_delete_columns_by_given_header_text()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            ExcelWorksheet worksheet  = excelPackage1.GetWorksheet("TEST6");
            const string   columnName = "Quantity";

            ExcelAddressBase valuedDimension = worksheet.GetValuedDimension();

            worksheet.ChangeCellValue(2, valuedDimension.End.Column + 1, columnName);
            worksheet.ChangeCellValue(2, valuedDimension.End.Column + 2, columnName);
            worksheet.ChangeCellValue(2, valuedDimension.End.Column + 3, columnName);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            worksheet.DeleteColumns(columnName);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            worksheet.GetColumns(2).Any(x => x.Value == columnName).Should().BeFalse();
            worksheet.GetValuedDimension().End.Column.Should().Be(2);
            worksheet.Cells[2, 2, 2, 2].Text.Should().Be("UpdatedDate");
        }
Esempio n. 2
0
        /// <summary>
        ///     Adds a line to the worksheet
        /// </summary>
        /// <param name="worksheet"></param>
        /// <param name="rowIndex"></param>
        /// <param name="startColumnIndex"></param>
        /// <param name="configureCells"></param>
        /// <param name="values"></param>
        /// <returns></returns>
        public static ExcelWorksheet AddLine(this ExcelWorksheet worksheet, int rowIndex, int startColumnIndex, Action <ExcelRange> configureCells = null, params object[] values)
        {
            for (var i = 0; i < values.Length; i++)
            {
                worksheet.ChangeCellValue(rowIndex, i + startColumnIndex, values[i], configureCells);
            }

            return(worksheet);
        }
        public void Should_delete_columns_by_given_header_text()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets["TEST6"];

            ExcelAddressBase valuedDimension = worksheet.GetValuedDimension();

            worksheet.ChangeCellValue(1, valuedDimension.End.Column + 1, "Quantity");
            worksheet.ChangeCellValue(1, valuedDimension.End.Column + 2, "Quantity");
            worksheet.ChangeCellValue(1, valuedDimension.End.Column + 3, "Quantity");

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            worksheet.DeleteColumns("Quantity");

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            worksheet.GetValuedDimension().End.Column.Should().Be(2);
            worksheet.Cells[1, 2, 1, 2].Text.Should().Be("UpdatedDate");
        }