public void DeleteColumns(string columnName, int qty)
 {
     DeleteColumns(ExcelAddress.ColumnNameToIndex(columnName), qty);
 }
        public void Load()
        {
            WorksheetPart wp = _wsheet.GetOWorksheetPart();

            if (wp == null)
            {
                return;
            }

            Action <Cell> readCell = (cell) =>
            {
                RowColumn rc        = ExcelAddress.ToRowColumn(cell.CellReference);
                CellProxy cellProxy = this.EnsureCell(rc.Row, rc.Column);
                if (cell.DataType != null)
                {
                    cellProxy.DataType = cell.DataType.Value;
                    if (cell.DataType.Value == CellValues.InlineString)
                    {
                        cellProxy.Value = cell.InlineString.Text.Text;
                    }
                    else
                    {
                        if (cell.CellValue != null)
                        {
                            cellProxy.Value = cell.CellValue.Text;
                        }
                        else
                        {
                            cellProxy.Value = string.Empty;
                        }
                    }
                }
                else
                {
                    if (cell.CellValue != null)
                    {
                        cellProxy.Value = cell.CellValue.Text;
                    }
                }
                if (cell.StyleIndex != null)
                {
                    cellProxy.StyleIndex = cell.StyleIndex;
                }
                if (cell.ShowPhonetic != null)
                {
                    cellProxy.ShowPhonetic = cell.ShowPhonetic;
                }
                if (cell.ValueMetaIndex != null)
                {
                    cellProxy.ValueMetaIndex = cell.ValueMetaIndex;
                }
                if (cell.CellFormula != null)
                {
                    cellProxy.CreateFormula();
                    cellProxy.Formula.Text      = cell.CellFormula.Text;
                    cellProxy.Formula.R1        = cell.CellFormula.R1;
                    cellProxy.Formula.R2        = cell.CellFormula.R2;
                    cellProxy.Formula.Reference = cell.CellFormula.Reference;
                    if (cell.CellFormula.AlwaysCalculateArray != null)
                    {
                        cellProxy.Formula.AlwaysCalculateArray = cell.CellFormula.AlwaysCalculateArray;
                    }
                    if (cell.CellFormula.Bx != null)
                    {
                        cellProxy.Formula.Bx = cell.CellFormula.Bx;
                    }
                    if (cell.CellFormula.CalculateCell != null)
                    {
                        cellProxy.Formula.CalculateCell = cell.CellFormula.CalculateCell;
                    }
                    if (cell.CellFormula.DataTable2D != null)
                    {
                        cellProxy.Formula.DataTable2D = cell.CellFormula.DataTable2D;
                    }
                    if (cell.CellFormula.DataTableRow != null)
                    {
                        cellProxy.Formula.DataTableRow = cell.CellFormula.DataTableRow;
                    }
                    if (cell.CellFormula.FormulaType != null)
                    {
                        cellProxy.Formula.FormulaType = cell.CellFormula.FormulaType;
                    }
                    if (cell.CellFormula.Input1Deleted != null)
                    {
                        cellProxy.Formula.Input1Deleted = cell.CellFormula.Input1Deleted;
                    }
                    if (cell.CellFormula.Input2Deleted != null)
                    {
                        cellProxy.Formula.Input2Deleted = cell.CellFormula.Input2Deleted;
                    }
                    if (cell.CellFormula.SharedIndex != null)
                    {
                        cellProxy.Formula.SharedIndex = cell.CellFormula.SharedIndex;
                    }

                    cellProxy.Value = null; // Don't cache/store values for formulas
                }
            };

            OpenXmlReader reader      = OpenXmlReader.Create(_wsheet.GetOWorksheetPart());
            bool          inWorksheet = false;
            bool          inSheetData = false;

            while (reader.Read())
            {
                if (inWorksheet && reader.IsStartElement)
                {
                    if (reader.ElementType == typeof(Row) && reader.IsStartElement)
                    {
                        // ----------------------------------------
                        // Scan row if anything other than RowIndex and Spans has been set,
                        // if so then cache
                        Row r = (Row)reader.LoadCurrentElement();
                        var needToCacheRow = (from a in r.GetAttributes()
                                              let ln = a.LocalName
                                                       where ln != "r" && ln != "spans"
                                                       select a).Any();

                        if (needToCacheRow)
                        {
                            _cachedRows.Add(r.RowIndex, (Row)r.CloneNode(false));
                        }
                        foreach (Cell cell in r.Elements <Cell>())
                        {
                            readCell(cell);
                        }
                        // ----------------------------------------
                    }
                    else if (reader.ElementType == typeof(SheetData))
                    {
                        inSheetData = reader.IsStartElement;
                    }
                    else if (reader.IsStartElement)
                    {
                        var e = reader.LoadCurrentElement();
                        _cachedElements.Add(e);
                    }
                }
                else if (reader.ElementType == typeof(Worksheet))
                {
                    inWorksheet = reader.IsStartElement;
                }
            }

            // Reset modified to false (loading sets it to true due to CellProxy loading)
            this.Modified = false;
        }
 public void DeleteColumn(string columnName)
 {
     DeleteColumns(ExcelAddress.ColumnNameToIndex(columnName), 1);
 }
 public void PushColumns(string columnName, int qty)
 {
     PushColumns(ExcelAddress.ColumnNameToIndex(columnName), qty);
 }
 public void PushColumn(string columnName)
 {
     PushColumns(ExcelAddress.ColumnNameToIndex(columnName), 1);
 }
 public void InsertColumns(string columnName, int qty)
 {
     InsertColumns(ExcelAddress.ColumnNameToIndex(columnName), qty);
 }
 public void InsertColumn(string columnName)
 {
     InsertColumns(ExcelAddress.ColumnNameToIndex(columnName), 1);
 }