Exemple #1
0
        public CellRangePosition(string value)
        {
            var match = PATTERN.Match(value);

            SheetName = match.Groups[1].Value;
            Start     = new CellPosition(match.Groups[3].Value, match.Groups[2].Value);

            string endColumn = match.Groups[4].Value;

            if (endColumn.Length == 0)
            {
                End = new CellPosition(Start);
            }
            else
            {
                End = new CellPosition(match.Groups[5].Value, endColumn);
            }
        }
Exemple #2
0
        private void CopyRange(ref CellRangeTemplate sourceRange, SheetData sheetData, Worksheet worksheet, ref CellPosition target, double?rowHeight = null)
        {
            #region
            Sheet      sheetTemplate        = sourceRange.CellRange.SheetTemplate;
            var        workbookPartTemplate = sourceRange.CellRange.WorksheetPart;
            MergeCells mergeCellsTemplate   = sourceRange.CellRange.MergeCells;

            MergeCells mergeCells = worksheet.GetFirstChild <MergeCells>();

            if (false && workbookPartTemplate.DrawingsPart != null && worksheet.WorksheetPart.DrawingsPart == null)
            {
                var drawingsPart = worksheet.WorksheetPart.AddPart <DrawingsPart>(workbookPartTemplate.DrawingsPart);

                drawingsPart = worksheet.WorksheetPart.DrawingsPart;

                if (!worksheet.WorksheetPart.Worksheet.ChildElements.OfType <Drawing>().Any())
                {
                    worksheet.WorksheetPart.Worksheet.Append(new Drawing {
                        Id = worksheet.WorksheetPart.GetIdOfPart(drawingsPart)
                    });
                }
            }

            Dictionary <string, MergeCell> mergeCellTemplateDic = sourceRange.CellRange.MergeCellsDic;
            #endregion

            CellPosition source = sourceRange.CellRange.Start;
            CellPosition offset = target.CalculateOffset(source);

            var cellsToCopy = document.FindCellsByRange(sourceRange.CellRange);
            for (int i = 0; i < cellsToCopy.Count(); i++)
            {
                var rowGroup = cellsToCopy.ElementAt(i);
                Row keyRow   = rowGroup.Key;

                Row targetRow = new Row()
                {
                    RowIndex = (UInt32)(keyRow.RowIndex + offset.Row),
                    Height   = (short)-1,
                };

                if (rowHeight != null)
                {
                    targetRow.Height       = rowHeight;
                    targetRow.CustomHeight = true;
                }

                MoveCurrentRow((int)targetRow.RowIndex.Value);
                sheetData.InsertBefore(targetRow, currentRow);

                foreach (Cell cellToCopy in rowGroup)
                {
                    Cell targetCell = (Cell)cellToCopy.Clone();

                    targetCell.CellReference = CellPosition.OffsetIt(targetCell.CellReference, offset);

                    targetRow.Append(targetCell);

                    MergeCell _findMerge;
                    if (mergeCellTemplateDic != null && mergeCellTemplateDic.TryGetValue(cellToCopy.CellReference.Value.ToUpper(), out _findMerge))
                    {
                        var          positionParent = _findMerge.Reference.Value.Split(':');
                        CellPosition offsetStart    = new CellPosition(positionParent[0]);
                        CellPosition offsetEnd      = new CellPosition(positionParent[1]);

                        var celRefNew = new CellPosition(targetCell.CellReference);


                        if (mergeCells == null)
                        {
                            var a = new MergeCells();
                            worksheet.InsertAfter(a, sheetData);
                            mergeCells = worksheet.GetFirstChild <MergeCells>();
                        }
                        var mergeCell = new MergeCell();
                        mergeCell.Reference = celRefNew.ToString() + ":" + new CellPosition(celRefNew.Row + (offsetEnd.Row - offsetStart.Row), celRefNew.Column + (offsetEnd.Column - offsetStart.Column)).ToString();
                        mergeCells.Append(mergeCell);
                        mergeCells.Count = (mergeCells.Count ?? 0) + 1;
                    }
                }
            }
        }
Exemple #3
0
 public void OffsetIt(CellPosition value)
 {
     row    += value.row;
     column += value.column;
 }
Exemple #4
0
 public CellPosition CalculateOffset(CellPosition value)
 {
     return(new CellPosition(row - value.row, column - value.column));
 }
Exemple #5
0
 public CellPosition(CellPosition right)
 {
     row    = right.row;
     column = right.column;
 }