diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell.cs index 48276ca..8453406 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell.cs @@ -1580,6 +1580,13 @@ FormulaR1C1 = source.FormulaR1C1; _richText = source._richText == null ? null : new XLRichText(source._richText, source.Style.Font); _comment = source._comment == null ? null : new XLComment(this, source._comment, source.Style.Font); + + if (source._hyperlink != null) + { + SettingHyperlink = true; + Hyperlink = new XLHyperlink(source.Hyperlink); + SettingHyperlink = false; + } } private IXLCell GetTargetCell(String target, XLWorksheet defaultWorksheet) @@ -1618,37 +1625,29 @@ public IXLCell CopyFrom(XLCell otherCell, Boolean copyDataValidations) { var source = otherCell; - _cellValue = source._cellValue; - _richText = source._richText == null ? null : new XLRichText(source._richText, source.Style.Font); - _comment = source._comment == null ? null : new XLComment(this, source._comment, source.Style.Font); + CopyValues(otherCell); - _dataType = source._dataType; - FormulaR1C1 = source.FormulaR1C1; SetStyle(source._style ?? source.Worksheet.Workbook.GetStyleById(source._styleCacheId)); - if (source._hyperlink != null) - { - SettingHyperlink = true; - Hyperlink = new XLHyperlink(source.Hyperlink); - SettingHyperlink = false; - } + if (copyDataValidations) { - using (var asRange = otherCell.AsRange()) - { - var thisDv = DataValidation; - var otherDv = asRange.DataValidation; - thisDv.CopyFrom(otherDv); - thisDv.Value = GetFormulaA1(otherCell.GetFormulaR1C1(otherDv.Value)); - thisDv.MinValue = GetFormulaA1(otherCell.GetFormulaR1C1(otherDv.MinValue)); - thisDv.MaxValue = GetFormulaA1(otherCell.GetFormulaR1C1(otherDv.MaxValue)); - } + CopyDataValidation(otherCell, otherCell.DataValidation); } return this; } + internal void CopyDataValidation(XLCell otherCell, XLDataValidation otherDv) + { + var thisDv = DataValidation; + thisDv.CopyFrom(otherDv); + thisDv.Value = GetFormulaA1(otherCell.GetFormulaR1C1(otherDv.Value)); + thisDv.MinValue = GetFormulaA1(otherCell.GetFormulaR1C1(otherDv.MinValue)); + thisDv.MaxValue = GetFormulaA1(otherCell.GetFormulaR1C1(otherDv.MaxValue)); + } + internal void ShiftFormulaRows(XLRange shiftedRange, int rowsShifted) { _formulaA1 = ShiftFormulaRows(FormulaA1, Worksheet, shiftedRange, rowsShifted); diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/DataValidation/XLDataValidation.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/DataValidation/XLDataValidation.cs index c01dbf0..7923cb6 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/DataValidation/XLDataValidation.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/DataValidation/XLDataValidation.cs @@ -6,7 +6,15 @@ { public XLDataValidation(IXLRanges ranges) { - Ranges = ranges; + + Ranges = new XLRanges(); + ranges.ForEach(r=> + { + var newR = + new XLRange(new XLRangeParameters(r.RangeAddress as XLRangeAddress, + r.Worksheet.Style) {IgnoreEvents = true}); + (Ranges as XLRanges).Add(newR); + } ); Initialize(); } @@ -23,7 +31,9 @@ ErrorMessage = String.Empty; ErrorStyle = XLErrorStyle.Stop; Operator = XLOperator.Between; - + Value = String.Empty; + MinValue = String.Empty; + MaxValue = String.Empty; } public Boolean IsDirty() @@ -56,7 +66,13 @@ public String ErrorTitle { get; set; } public String ErrorMessage { get; set; } public XLErrorStyle ErrorStyle { get; set; } - public XLAllowedValues AllowedValues { get; set; } + private XLAllowedValues _allowedValues; + public XLAllowedValues AllowedValues + { + get { return _allowedValues; } + set { _allowedValues = value; } + } + public XLOperator Operator { get; set; } public String Value @@ -134,7 +150,7 @@ { AllowedValues = XLAllowedValues.List; InCellDropdown = inCellDropdown; - Value = String.Format("'{0}'!{1}", ((XLRange)range).Worksheet.Name, range.RangeAddress.ToStringFixed()); + Value = range.RangeAddress.ToStringFixed(); } public void Custom(String customValidation) @@ -149,11 +165,6 @@ { if (dataValidation == this) return; - //if (Ranges != null) - // Ranges.Dispose(); - - //Ranges = new XLRanges(); - if (Ranges == null && dataValidation.Ranges != null) { Ranges = new XLRanges(); diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/DataValidation/XLValidationCriteria.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/DataValidation/XLValidationCriteria.cs index b4e9eb2..449e688 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/DataValidation/XLValidationCriteria.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/DataValidation/XLValidationCriteria.cs @@ -66,105 +66,101 @@ public void EqualTo(IXLRange range) { - dataValidation.Value = String.Format("'{0}'!{1}", ((XLRange)range).Worksheet.Name, range.RangeAddress); + dataValidation.Value = range.RangeAddress.ToStringFixed(); dataValidation.Operator = XLOperator.EqualTo; } public void NotEqualTo(IXLRange range) { - dataValidation.Value = String.Format("'{0}'!{1}", ((XLRange)range).Worksheet.Name, range.RangeAddress); + dataValidation.Value = range.RangeAddress.ToStringFixed(); dataValidation.Operator = XLOperator.NotEqualTo; } public void GreaterThan(IXLRange range) { - dataValidation.Value = String.Format("'{0}'!{1}", ((XLRange)range).Worksheet.Name, range.RangeAddress); + dataValidation.Value = range.RangeAddress.ToStringFixed(); dataValidation.Operator = XLOperator.GreaterThan; } public void LessThan(IXLRange range) { - dataValidation.Value = String.Format("'{0}'!{1}", ((XLRange)range).Worksheet.Name, range.RangeAddress); + dataValidation.Value = range.RangeAddress.ToStringFixed(); dataValidation.Operator = XLOperator.LessThan; } public void EqualOrGreaterThan(IXLRange range) { - dataValidation.Value = String.Format("'{0}'!{1}", ((XLRange)range).Worksheet.Name, range.RangeAddress); + dataValidation.Value = range.RangeAddress.ToStringFixed(); dataValidation.Operator = XLOperator.EqualOrGreaterThan; } public void EqualOrLessThan(IXLRange range) { - dataValidation.Value = String.Format("'{0}'!{1}", ((XLRange)range).Worksheet.Name, range.RangeAddress); + dataValidation.Value = range.RangeAddress.ToStringFixed(); dataValidation.Operator = XLOperator.EqualOrLessThan; } public void Between(IXLRange minValue, IXLRange maxValue) { - dataValidation.MinValue = String.Format("'{0}'!{1}", ((XLRange)minValue).Worksheet.Name, - minValue.RangeAddress); - dataValidation.MaxValue = String.Format("'{0}'!{1}", ((XLRange)maxValue).Worksheet.Name, - maxValue.RangeAddress); + dataValidation.MinValue = minValue.RangeAddress.ToStringFixed(); + dataValidation.MaxValue = maxValue.RangeAddress.ToStringFixed(); dataValidation.Operator = XLOperator.Between; } public void NotBetween(IXLRange minValue, IXLRange maxValue) { - dataValidation.MinValue = String.Format("'{0}'!{1}", ((XLRange)minValue).Worksheet.Name, - minValue.RangeAddress); - dataValidation.MaxValue = String.Format("'{0}'!{1}", ((XLRange)maxValue).Worksheet.Name, - maxValue.RangeAddress); + dataValidation.MinValue = minValue.RangeAddress.ToStringFixed(); + dataValidation.MaxValue = maxValue.RangeAddress.ToStringFixed(); dataValidation.Operator = XLOperator.NotBetween; } public void EqualTo(IXLCell cell) { - dataValidation.Value = String.Format("'{0}'!{1}", cell.Worksheet.Name, cell.Address); + dataValidation.Value = cell.Address.ToStringFixed(); dataValidation.Operator = XLOperator.EqualTo; } public void NotEqualTo(IXLCell cell) { - dataValidation.Value = String.Format("'{0}'!{1}", cell.Worksheet.Name, cell.Address); + dataValidation.Value = cell.Address.ToStringFixed(); dataValidation.Operator = XLOperator.NotEqualTo; } public void GreaterThan(IXLCell cell) { - dataValidation.Value = String.Format("'{0}'!{1}", cell.Worksheet.Name, cell.Address); + dataValidation.Value = cell.Address.ToStringFixed(); dataValidation.Operator = XLOperator.GreaterThan; } public void LessThan(IXLCell cell) { - dataValidation.Value = String.Format("'{0}'!{1}", cell.Worksheet.Name, cell.Address); + dataValidation.Value = cell.Address.ToStringFixed(); dataValidation.Operator = XLOperator.LessThan; } public void EqualOrGreaterThan(IXLCell cell) { - dataValidation.Value = String.Format("'{0}'!{1}", cell.Worksheet.Name, cell.Address); + dataValidation.Value = cell.Address.ToStringFixed(); dataValidation.Operator = XLOperator.EqualOrGreaterThan; } public void EqualOrLessThan(IXLCell cell) { - dataValidation.Value = String.Format("'{0}'!{1}", cell.Worksheet.Name, cell.Address); + dataValidation.Value = cell.Address.ToStringFixed(); dataValidation.Operator = XLOperator.EqualOrLessThan; } public void Between(IXLCell minValue, IXLCell maxValue) { - dataValidation.MinValue = String.Format("'{0}'!{1}", minValue.Worksheet.Name, minValue.Address); - dataValidation.MaxValue = String.Format("'{0}'!{1}", maxValue.Worksheet.Name, maxValue.Address); + dataValidation.MinValue = minValue.Address.ToStringFixed(); + dataValidation.MaxValue = maxValue.Address.ToStringFixed(); dataValidation.Operator = XLOperator.Between; } public void NotBetween(IXLCell minValue, IXLCell maxValue) { - dataValidation.MinValue = String.Format("'{0}'!{1}", minValue.Worksheet.Name, minValue.Address); - dataValidation.MaxValue = String.Format("'{0}'!{1}", maxValue.Worksheet.Name, maxValue.Address); + dataValidation.MinValue = minValue.Address.ToStringFixed(); + dataValidation.MaxValue = maxValue.Address.ToStringFixed(); dataValidation.Operator = XLOperator.NotBetween; } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeBase.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeBase.cs index 63cf3ec..583d321 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeBase.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeBase.cs @@ -43,8 +43,14 @@ #region Constructor + static Int32 IdCounter = 0; + readonly Int32 Id; + protected XLRangeBase(XLRangeAddress rangeAddress) { + + Id = ++IdCounter; + RangeAddress = new XLRangeAddress(rangeAddress); } @@ -111,8 +117,12 @@ if (thisStart > dvStart && thisEnd < dvEnd) { - dv.Ranges.Add(Worksheet.Column(column.ColumnNumber()).Column(dvStart, thisStart - 1)); - dv.Ranges.Add(Worksheet.Column(column.ColumnNumber()).Column(thisEnd + 1, dvEnd)); + var r1 = Worksheet.Column(column.ColumnNumber()).Column(dvStart, thisStart - 1); + r1.Dispose(); + dv.Ranges.Add(r1); + var r2 = Worksheet.Column(column.ColumnNumber()).Column(thisEnd + 1, dvEnd); + r2.Dispose(); + dv.Ranges.Add(r2); } else { @@ -131,12 +141,17 @@ coEnd = thisStart - 1; if (coEnd >= dvStart) - dv.Ranges.Add(Worksheet.Column(column.ColumnNumber()).Column(coStart, coEnd)); + { + var r = Worksheet.Column(column.ColumnNumber()).Column(coStart, coEnd); + r.Dispose(); + dv.Ranges.Add(r); + } } } } else { + column.Dispose(); dv.Ranges.Add(column); } } @@ -964,9 +979,10 @@ cell.ShiftFormulaColumns(asRange, numberOfColumns); } + + var cellsDataValidations = new Dictionary(); var cellsToInsert = new Dictionary(); var cellsToDelete = new List(); - //var cellsToBlank = new List(); int firstColumn = RangeAddress.FirstAddress.ColumnNumber; int firstRow = RangeAddress.FirstAddress.RowNumber; int lastRow = RangeAddress.FirstAddress.RowNumber + RowCount() - 1; @@ -991,8 +1007,6 @@ newCell.FormulaA1 = oldCell.FormulaA1; cellsToInsert.Add(newKey, newCell); cellsToDelete.Add(oldKey); - //if (oldKey.ColumnNumber < firstColumn + numberOfColumns) - // cellsToBlank.Add(oldKey); } } } @@ -1008,16 +1022,28 @@ var newKey = new XLAddress(Worksheet, c.Address.RowNumber, newColumn, false, false); var newCell = new XLCell(Worksheet, newKey, c.GetStyleId()); newCell.CopyValues(c); + cellsDataValidations.Add(newCell.Address, + new DataValidationToCopy { DataValidation = c.DataValidation, SourceAddress = c.Address }); newCell.FormulaA1 = c.FormulaA1; cellsToInsert.Add(newKey, newCell); cellsToDelete.Add(c.Address); - //if (c.Address.ColumnNumber < firstColumn + numberOfColumns) - // cellsToBlank.Add(c.Address); + c.DataValidation.Clear(); } } + + cellsDataValidations.ForEach(kp => + { + XLCell targetCell; + if (!cellsToInsert.TryGetValue(kp.Key, out targetCell)) + targetCell = Worksheet.Cell(kp.Key); + + targetCell.CopyDataValidation(Worksheet.Cell(kp.Value.SourceAddress), kp.Value.DataValidation); + }); + cellsToDelete.ForEach(c => Worksheet.Internals.CellsCollection.Remove(c.RowNumber, c.ColumnNumber)); cellsToInsert.ForEach( c => Worksheet.Internals.CellsCollection.Add(c.Key.RowNumber, c.Key.ColumnNumber, c.Value)); + //cellsDataValidations.ForEach(kp => Worksheet.Cell(kp.Key).CopyDataValidation(Worksheet.Cell(kp.Value.SourceAddress), kp.Value.DataValidation)); Int32 firstRowReturn = RangeAddress.FirstAddress.RowNumber; Int32 lastRowReturn = RangeAddress.LastAddress.RowNumber ; @@ -1143,6 +1169,11 @@ return retVal; } + struct DataValidationToCopy + { + public XLAddress SourceAddress; + public XLDataValidation DataValidation; + } public IXLRangeRows InsertRowsAbove(Boolean onlyUsedCells, Int32 numberOfRows, Boolean formatFromAbove = true) { foreach (XLWorksheet ws in Worksheet.Workbook.WorksheetsInternal) @@ -1154,7 +1185,7 @@ var cellsToInsert = new Dictionary(); var cellsToDelete = new List(); - //var cellsToBlank = new List(); + var cellsDataValidations = new Dictionary(); int firstRow = RangeAddress.FirstAddress.RowNumber; int firstColumn = RangeAddress.FirstAddress.ColumnNumber; int lastColumn = RangeAddress.FirstAddress.ColumnNumber + ColumnCount() - 1; @@ -1175,7 +1206,7 @@ Worksheet.Cell(oldKey); var newCell = new XLCell(Worksheet, newKey, oldCell.GetStyleId()); - newCell.CopyFrom(oldCell, true); + newCell.CopyValues(oldCell); newCell.FormulaA1 = oldCell.FormulaA1; cellsToInsert.Add(newKey, newCell); cellsToDelete.Add(oldKey); @@ -1194,15 +1225,30 @@ int newRow = c.Address.RowNumber + numberOfRows; var newKey = new XLAddress(Worksheet, newRow, c.Address.ColumnNumber, false, false); var newCell = new XLCell(Worksheet, newKey, c.GetStyleId()); - newCell.CopyFrom(c, true); + newCell.CopyValues(c); + cellsDataValidations.Add(newCell.Address, + new DataValidationToCopy {DataValidation = c.DataValidation, SourceAddress = c.Address}); newCell.FormulaA1 = c.FormulaA1; cellsToInsert.Add(newKey, newCell); cellsToDelete.Add(c.Address); + c.DataValidation.Clear(); } } + + cellsDataValidations.ForEach(kp => + { + XLCell targetCell; + if(!cellsToInsert.TryGetValue(kp.Key, out targetCell)) + targetCell = Worksheet.Cell(kp.Key); + + targetCell.CopyDataValidation( + Worksheet.Cell(kp.Value.SourceAddress), kp.Value.DataValidation); + }); + cellsToDelete.ForEach(c => Worksheet.Internals.CellsCollection.Remove(c.RowNumber, c.ColumnNumber)); cellsToInsert.ForEach( c => Worksheet.Internals.CellsCollection.Add(c.Key.RowNumber, c.Key.ColumnNumber, c.Value)); + Int32 firstRowReturn = RangeAddress.FirstAddress.RowNumber; Int32 lastRowReturn = RangeAddress.FirstAddress.RowNumber + numberOfRows - 1; @@ -1299,6 +1345,7 @@ // Range to shift... var cellsToInsert = new Dictionary(); + //var cellsDataValidations = new Dictionary(); var cellsToDelete = new List(); var shiftLeftQuery = Worksheet.Internals.CellsCollection.GetCells( RangeAddress.FirstAddress.RowNumber, @@ -1323,6 +1370,7 @@ false, false); var newCell = new XLCell(Worksheet, newKey, c.GetStyleId()); newCell.CopyValues(c); + //cellsDataValidations.Add(newCell.Address,new DataValidationToCopy { DataValidation = c.DataValidation, SourceAddress = c.Address }); newCell.FormulaA1 = c.FormulaA1; cellsToDelete.Add(c.Address); @@ -1333,6 +1381,15 @@ if (canInsert) cellsToInsert.Add(newKey, newCell); } + //cellsDataValidations.ForEach(kp => + //{ + // XLCell targetCell; + // if (!cellsToInsert.TryGetValue(kp.Key, out targetCell)) + // targetCell = Worksheet.Cell(kp.Key); + // + // targetCell.CopyDataValidation(Worksheet.Cell(kp.Value.SourceAddress), kp.Value.DataValidation); + //}); + cellsToDelete.ForEach(c => Worksheet.Internals.CellsCollection.Remove(c.RowNumber, c.ColumnNumber)); cellsToInsert.ForEach( c => Worksheet.Internals.CellsCollection.Add(c.Key.RowNumber, c.Key.ColumnNumber, c.Value)); diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRanges.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRanges.cs index 9d61fd0..266d999 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRanges.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRanges.cs @@ -24,6 +24,12 @@ return this; } + public void Add(XLRange range) + { + Count++; + _ranges.Add(range); + } + public void Add(IXLRangeBase range) { Count++; @@ -83,7 +89,11 @@ { dv.Ranges.Remove(dvRange); foreach (IXLCell c in dvRange.Cells().Where(c => !range.Contains(c.Address.ToString()))) - dv.Ranges.Add(c.AsRange()); + { + var r = c.AsRange(); + r.Dispose(); + dv.Ranges.Add(r); + } } } } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorksheet.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorksheet.cs index 7155e2d..79b9de8 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorksheet.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorksheet.cs @@ -552,14 +552,7 @@ var targetSheet = (XLWorksheet)workbook.WorksheetsInternal.Add(newSheetName, position); Internals.CellsCollection.GetCells().ForEach(c => targetSheet.Cell(c.Address).CopyFrom(c, false)); - DataValidations.ForEach(dv => - { - var newDv = new XLDataValidation(dv); - newDv.Value = ReplaceRelativeSheet(newSheetName, dv.Value); - newDv.MinValue = ReplaceRelativeSheet(newSheetName, dv.MinValue); - newDv.MaxValue = ReplaceRelativeSheet(newSheetName, dv.MaxValue); - targetSheet.DataValidations.Add(newDv); - }); + DataValidations.ForEach(dv => targetSheet.DataValidations.Add(new XLDataValidation(dv))); Internals.ColumnsCollection.ForEach( kp => targetSheet.Internals.ColumnsCollection.Add(kp.Key, new XLColumn(kp.Value))); Internals.RowsCollection.ForEach(kp => targetSheet.Internals.RowsCollection.Add(kp.Key, new XLRow(kp.Value))); diff --git a/ClosedXML/ClosedXML/ClosedXML_Tests/Excel/Columns/ColumnsTests.cs b/ClosedXML/ClosedXML/ClosedXML_Tests/Excel/Columns/ColumnsTests.cs index 999af25..a245c2c 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Tests/Excel/Columns/ColumnsTests.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Tests/Excel/Columns/ColumnsTests.cs @@ -113,6 +113,7 @@ var column3 = ws.Column(3); var columnIns = ws.Column(2).InsertColumnsBefore(1).First(); + wb.SaveAs(@"D:\Excel Files\ForTesting\Sandbox.xlsx"); Assert.AreEqual(XLColor.Red, ws.Column(1).Cell(1).Style.Fill.BackgroundColor); Assert.AreEqual(XLColor.Red, ws.Column(1).Cell(2).Style.Fill.BackgroundColor); diff --git a/ClosedXML/ClosedXML/ClosedXML_Tests/Excel/DataValidations/DataValidationTests.cs b/ClosedXML/ClosedXML/ClosedXML_Tests/Excel/DataValidations/DataValidationTests.cs index 8c09d87..8f862c4 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Tests/Excel/DataValidations/DataValidationTests.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Tests/Excel/DataValidations/DataValidationTests.cs @@ -74,7 +74,7 @@ cell.DataValidation.InputTitle = "Title for B2"; Assert.AreEqual(cell.DataValidation.AllowedValues, XLAllowedValues.List); - Assert.AreEqual(cell.DataValidation.Value, "'Data Validation Issue'!$E$1:$E$4"); + Assert.AreEqual(cell.DataValidation.Value, "$E$1:$E$4"); Assert.AreEqual(cell.DataValidation.InputTitle, "Title for B2"); @@ -84,7 +84,7 @@ cell.DataValidation.InputMessage = "Message for C2"; Assert.AreEqual(cell.DataValidation.AllowedValues, XLAllowedValues.List); - Assert.AreEqual(cell.DataValidation.Value, "'Data Validation Issue'!$E$1:$E$4"); + Assert.AreEqual(cell.DataValidation.Value, "$E$1:$E$4"); Assert.AreEqual(cell.DataValidation.InputMessage, "Message for C2"); ws.Cell("D1").SetValue("Cell below has Validation with title and message."); @@ -94,7 +94,7 @@ cell.DataValidation.InputMessage = "Message for D2"; Assert.AreEqual(cell.DataValidation.AllowedValues, XLAllowedValues.List); - Assert.AreEqual(cell.DataValidation.Value, "'Data Validation Issue'!$E$1:$E$4"); + Assert.AreEqual(cell.DataValidation.Value, "$E$1:$E$4"); Assert.AreEqual(cell.DataValidation.InputTitle, "Title for D2"); Assert.AreEqual(cell.DataValidation.InputMessage, "Message for D2"); } @@ -120,7 +120,7 @@ var wb = new XLWorkbook(); var ws = wb.Worksheets.Add("Sheet1"); ws.Cell("A1").SetValue("A"); - ws.Cell("B1").SetDataValidation().Value = "A1"; + ws.Cell("B1").SetDataValidation().Custom("A1"); ws.FirstRow().InsertRowsAbove(1); Assert.AreEqual("A2", ws.Cell("B2").DataValidation.Value); @@ -143,7 +143,7 @@ var wb = new XLWorkbook(); var ws = wb.Worksheets.Add("Sheet1"); ws.Cell("A1").SetValue("A"); - ws.Cell("B1").SetDataValidation().Value = "A1"; + ws.Cell("B1").SetDataValidation().Custom("A1"); ws.FirstColumn().InsertColumnsBefore(1); Assert.AreEqual("B1", ws.Cell("C1").DataValidation.Value); diff --git a/ClosedXML/ClosedXML/ClosedXML_Tests/Excel/Tables/TablesTests.cs b/ClosedXML/ClosedXML/ClosedXML_Tests/Excel/Tables/TablesTests.cs index e5f14d3..e164b98 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Tests/Excel/Tables/TablesTests.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Tests/Excel/Tables/TablesTests.cs @@ -106,7 +106,7 @@ row = table.DataRange.InsertRowsBelow(1).First(); row.Field("Value").Value = 3; - wb.SaveAs(@"D:\Excel Files\ForTesting\Sandbox.xlsx"); + //wb.SaveAs(@"D:\Excel Files\ForTesting\Sandbox.xlsx"); Assert.AreEqual(1, ws.Cell(2, 1).GetDouble()); Assert.AreEqual(2, ws.Cell(3, 1).GetDouble()); diff --git a/ClosedXML/ClosedXML/ClosedXML_Tests/Resource/Examples/Misc/DataValidation.xlsx b/ClosedXML/ClosedXML/ClosedXML_Tests/Resource/Examples/Misc/DataValidation.xlsx index 8fba4bc..68fbe2c 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Tests/Resource/Examples/Misc/DataValidation.xlsx +++ b/ClosedXML/ClosedXML/ClosedXML_Tests/Resource/Examples/Misc/DataValidation.xlsx Binary files differ