예제 #1
0
        public override void AddMergedRegion(
            ExcelColumnIndex firstColumnIndex,
            int firstRowIndex,
            ExcelColumnIndex lastColumnIndex,
            int lastRowIndex)
        {
            int firstColumIndexInt = firstColumnIndex.AsInt32();

            firstColumIndexInt.ThrowIfValueIsOutOfRange(nameof(firstColumnIndex), 0, int.MaxValue);
            firstRowIndex.ThrowIfValueIsOutOfRange(nameof(firstRowIndex), 1, int.MaxValue);

            int lastColumIndexInt = lastColumnIndex.AsInt32();

            lastColumIndexInt.ThrowIfValueIsOutOfRange(nameof(lastColumnIndex), 0, int.MaxValue);
            lastRowIndex.ThrowIfValueIsOutOfRange(nameof(lastRowIndex), 1, int.MaxValue);

            var cra = new CellRangeAddress(
                firstRow: firstRowIndex - 1, // Because of using one-based indexing.
                lastRow: lastRowIndex - 1,   // Because of using one-based indexing.
                firstCol: firstColumIndexInt,
                lastCol: lastColumIndexInt
                );

            _sheet.AddMergedRegion(cra);
        }
예제 #2
0
        public override void AutoSizeColumn(ExcelColumnIndex columnIndex, bool useMergedCells)
        {
            int columnIndexInt = columnIndex.AsInt32();

            columnIndexInt.ThrowIfValueIsOutOfRange(nameof(columnIndex), 1, int.MaxValue);

            _sheet.AutoSizeColumn(columnIndexInt, useMergedCells);
        }
        public override void AutoSizeColumn(ExcelColumnIndex columnIndex)
        {
            int columnIndexInt = columnIndex.AsInt32().UseOneBasedIndexing();

            columnIndexInt.ThrowIfValueIsOutOfRange(nameof(columnIndex), 1, int.MaxValue);

            _sheet.Column(columnIndexInt).AutoFit();
        }
        public override void AutoSizeColumn(ExcelColumnIndex columnIndex, bool useMergedCells)
        {
            int columnIndexInt = columnIndex.AsInt32().UseOneBasedIndexing();

            columnIndexInt.ThrowIfValueIsOutOfRange(nameof(columnIndex), 1, int.MaxValue);

            // TODO: find a way to enable auto size for merged cells.
            _sheet.Column(columnIndexInt).AutoFit();
        }
        public override IExcelCellHolder GetOrCreateCell(ExcelColumnIndex columnIndex, int rowIndex,
                                                         bool centrized)
        {
            int columnIndexInt = columnIndex.AsInt32().UseOneBasedIndexing();

            columnIndexInt.ThrowIfValueIsOutOfRange(nameof(columnIndex), 1, int.MaxValue);
            rowIndex.ThrowIfValueIsOutOfRange(nameof(rowIndex), 1, int.MaxValue);

            ExcelRange excelRange = _sheet.Cells[rowIndex, columnIndexInt];

            excelRange = centrized
                ? excelRange.Center()
                : excelRange;

            return(new EpplusExcelCellHolder(excelRange));
        }
        public void ApplyAnalysisToSingleLaunch(IExcelSheet sheet, ExcelColumnIndex currentColumn,
                                                int currentRow, int operationNumber)
        {
            string dataAddress = sheet[currentColumn, currentRow].Address;

            int    theoreticalDataRow    = currentColumn.AsInt32().UseOneBasedIndexing().SkipHeader();
            string theoreticalMinAddress = sheet[_theoreticalMinColumn, theoreticalDataRow].Address;
            string theoreticalMaxAddress = sheet[_theoreticalMaxColumn, theoreticalDataRow].Address;

            string normalizedFormula = ManualFormulaProvider.Normalize(
                dataAddress, theoreticalMinAddress, theoreticalMaxAddress
                );

            int normalizedDataRowIndex = ExcelWrapperForPhaseTwo.GetNormalizedDataRowIndex(
                _args, currentRow
                );

            sheet[currentColumn, normalizedDataRowIndex].SetFormula(normalizedFormula);
        }
        public override void AddMergedRegion(
            ExcelColumnIndex firstColumnIndex,
            int firstRowIndex,
            ExcelColumnIndex lastColumnIndex,
            int lastRowIndex)
        {
            int firstColumnIndexInt = firstColumnIndex.AsInt32().UseOneBasedIndexing();

            firstColumnIndexInt.ThrowIfValueIsOutOfRange(nameof(firstRowIndex), 1, int.MaxValue);
            firstRowIndex.ThrowIfValueIsOutOfRange(nameof(firstRowIndex), 1, int.MaxValue);

            int lastColumnIndexInt = lastColumnIndex.AsInt32().UseOneBasedIndexing();

            lastColumnIndexInt.ThrowIfValueIsOutOfRange(nameof(lastRowIndex), 1, int.MaxValue);
            lastRowIndex.ThrowIfValueIsOutOfRange(nameof(lastRowIndex), 1, int.MaxValue);

            _sheet.Cells[
                firstRowIndex, firstColumnIndexInt,
                lastRowIndex, lastColumnIndexInt
            ].Merge = true;
        }
예제 #8
0
        public override IExcelCellHolder GetOrCreateCell(ExcelColumnIndex columnIndex, int rowIndex,
                                                         bool centrized)
        {
            rowIndex.ThrowIfValueIsOutOfRange(nameof(rowIndex), 1, int.MaxValue);
            int columIndexInt = columnIndex.AsInt32();

            columIndexInt.ThrowIfValueIsOutOfRange(nameof(columnIndex), 0, int.MaxValue);

            // Because of using one-based indexing.
            int  fixedRowIndex = rowIndex - 1;
            IRow row           = GetOrCreateRow(fixedRowIndex, centrized);

            ICell cell = row.GetCell(columIndexInt);

            ICell result = cell is null
                ? row.CreateCell(columIndexInt)
                : cell;

            result = centrized
                ? result.Center()
                : result;

            return(new NpoiExcelCellHolder(result));
        }
        public override void SetArrayFormula(
            string arrayFormula,
            ExcelColumnIndex firstColumnIndex,
            int firstRowIndex,
            ExcelColumnIndex lastColumnIndex,
            int lastRowIndex)
        {
            arrayFormula.ThrowIfNullOrWhiteSpace(nameof(arrayFormula));

            int firstColumnIndexInt = firstColumnIndex.AsInt32().UseOneBasedIndexing();

            firstColumnIndexInt.ThrowIfValueIsOutOfRange(nameof(firstRowIndex), 1, int.MaxValue);
            firstRowIndex.ThrowIfValueIsOutOfRange(nameof(firstRowIndex), 1, int.MaxValue);

            int lastColumnIndexInt = lastColumnIndex.AsInt32().UseOneBasedIndexing();

            lastColumnIndexInt.ThrowIfValueIsOutOfRange(nameof(lastRowIndex), 1, int.MaxValue);
            lastRowIndex.ThrowIfValueIsOutOfRange(nameof(lastRowIndex), 1, int.MaxValue);

            _sheet.Cells[
                firstRowIndex, firstColumnIndexInt,
                lastRowIndex, lastColumnIndexInt
            ].CreateArrayFormula(arrayFormula);
        }