diff --git a/ClosedXML/Excel/AutoFilters/XLAutoFilter.cs b/ClosedXML/Excel/AutoFilters/XLAutoFilter.cs index 3e33697..ec79a5c 100644 --- a/ClosedXML/Excel/AutoFilters/XLAutoFilter.cs +++ b/ClosedXML/Excel/AutoFilters/XLAutoFilter.cs @@ -116,62 +116,59 @@ SortColumn = columnToSortBy; // Recalculate shown / hidden rows - if (Enabled) + using (var rows = Range.Rows(2, Range.RowCount())) { - using (var rows = Range.Rows(2, Range.RowCount())) - { - foreach (IXLRangeRow row in rows) - row.WorksheetRow().Unhide(); - } + foreach (IXLRangeRow row in rows) + row.WorksheetRow().Unhide(); + } - foreach (var kp in Filters) + foreach (var kp in Filters) + { + Boolean firstFilter = true; + foreach (XLFilter filter in kp.Value) { - Boolean firstFilter = true; - foreach (XLFilter filter in kp.Value) + var condition = filter.Condition; + var isText = filter.Value is String; + var isDateTime = filter.Value is DateTime; + + using (var rows = Range.Rows(2, Range.RowCount())) { - var condition = filter.Condition; - var isText = filter.Value is String; - var isDateTime = filter.Value is DateTime; - - using (var rows = Range.Rows(2, Range.RowCount())) + foreach (IXLRangeRow row in rows) { - foreach (IXLRangeRow row in rows) + //TODO : clean up filter matching - it's done in different place + Boolean match; + + if (isText) + match = condition(row.Cell(kp.Key).GetFormattedString()); + else if (isDateTime) + match = row.Cell(kp.Key).DataType == XLDataType.DateTime && condition(row.Cell(kp.Key).GetDateTime()); + else + match = row.Cell(kp.Key).DataType == XLDataType.Number && condition(row.Cell(kp.Key).GetDouble()); + + if (firstFilter) { - //TODO : clean up filter matching - it's done in different place - Boolean match; - - if (isText) - match = condition(row.Cell(kp.Key).GetFormattedString()); - else if (isDateTime) - match = row.Cell(kp.Key).DataType == XLDataType.DateTime && condition(row.Cell(kp.Key).GetDateTime()); + if (match) + row.WorksheetRow().Unhide(); else - match = row.Cell(kp.Key).DataType == XLDataType.Number && condition(row.Cell(kp.Key).GetDouble()); - - if (firstFilter) - { - if (match) - row.WorksheetRow().Unhide(); - else - row.WorksheetRow().Hide(); - } - else - { - if (filter.Connector == XLConnector.And) - { - if (!row.WorksheetRow().IsHidden) - { - if (match) - row.WorksheetRow().Unhide(); - else - row.WorksheetRow().Hide(); - } - } - else if (match) - row.WorksheetRow().Unhide(); - } + row.WorksheetRow().Hide(); } - firstFilter = false; + else + { + if (filter.Connector == XLConnector.And) + { + if (!row.WorksheetRow().IsHidden) + { + if (match) + row.WorksheetRow().Unhide(); + else + row.WorksheetRow().Hide(); + } + } + else if (match) + row.WorksheetRow().Unhide(); + } } + firstFilter = false; } } } diff --git a/ClosedXML/Excel/CalcEngine/Functions/Tally.cs b/ClosedXML/Excel/CalcEngine/Functions/Tally.cs index 93abf67..cd6b4d5 100644 --- a/ClosedXML/Excel/CalcEngine/Functions/Tally.cs +++ b/ClosedXML/Excel/CalcEngine/Functions/Tally.cs @@ -89,7 +89,7 @@ { double tmp; var vEnumerable = value as IEnumerable; - if (vEnumerable == null) + if (vEnumerable == null || vEnumerable is string) { if (TryParseToDouble(value, out tmp)) yield return tmp; @@ -100,7 +100,6 @@ { if (TryParseToDouble(v, out tmp)) yield return tmp; - break; } } } diff --git a/ClosedXML/Excel/CalcEngine/Functions/XLMath.cs b/ClosedXML/Excel/CalcEngine/Functions/XLMath.cs index 4354e04..081df15 100644 --- a/ClosedXML/Excel/CalcEngine/Functions/XLMath.cs +++ b/ClosedXML/Excel/CalcEngine/Functions/XLMath.cs @@ -91,11 +91,11 @@ public static Boolean IsEven(Int32 value) { - return Math.Abs(value % 2) < XLHelper.Epsilon; + return Math.Abs(value % 2) == 0; } public static Boolean IsOdd(Int32 value) { - return Math.Abs(value % 2) > XLHelper.Epsilon; + return Math.Abs(value % 2) != 0; } public static string ToRoman(int number) diff --git a/ClosedXML/Excel/Cells/XLCell.cs b/ClosedXML/Excel/Cells/XLCell.cs index 45bddd5..f9f30dd 100644 --- a/ClosedXML/Excel/Cells/XLCell.cs +++ b/ClosedXML/Excel/Cells/XLCell.cs @@ -929,7 +929,7 @@ _richText = null; } - if (_cellValue.Length > 0) + if (!string.IsNullOrEmpty(_cellValue)) { if (value == XLDataType.Boolean) { @@ -1617,8 +1617,8 @@ var cell = cells.First(); var field = table.Fields.First(f => f.Column.ColumnNumber() == cell.WorksheetColumn().ColumnNumber()); field.TotalsRowFunction = XLTotalsRowFunction.None; - field.TotalsRowLabel = value.ToString(); - this._cellValue = value.ToString(); + _cellValue = value.ToString(); + field.TotalsRowLabel = _cellValue; this.DataType = XLDataType.Text; return true; } diff --git a/ClosedXML/Excel/ConditionalFormats/Save/XLCFCellIsConverter.cs b/ClosedXML/Excel/ConditionalFormats/Save/XLCFCellIsConverter.cs index effbaca..72c297a 100644 --- a/ClosedXML/Excel/ConditionalFormats/Save/XLCFCellIsConverter.cs +++ b/ClosedXML/Excel/ConditionalFormats/Save/XLCFCellIsConverter.cs @@ -16,11 +16,7 @@ conditionalFormattingRule.Operator = cf.Operator.ToOpenXml(); - var formula = new Formula(); - if (cf.Operator == XLCFOperator.Equal || cf.Operator == XLCFOperator.NotEqual) - formula.Text = val; - else - formula.Text = val; + var formula = new Formula(val); conditionalFormattingRule.Append(formula); if (cf.Operator == XLCFOperator.Between || cf.Operator == XLCFOperator.NotBetween) diff --git a/ClosedXML/Excel/DataValidation/IXLDataValidation.cs b/ClosedXML/Excel/DataValidation/IXLDataValidation.cs index 1c7b9fd..0d87c3c 100644 --- a/ClosedXML/Excel/DataValidation/IXLDataValidation.cs +++ b/ClosedXML/Excel/DataValidation/IXLDataValidation.cs @@ -5,7 +5,7 @@ public enum XLErrorStyle { Stop, Warning, Information } public enum XLAllowedValues { AnyValue, WholeNumber, Decimal, Date, Time, TextLength, List, Custom } public enum XLOperator { EqualTo, NotEqualTo, GreaterThan, LessThan, EqualOrGreaterThan, EqualOrLessThan, Between, NotBetween } - public interface IXLDataValidation + public interface IXLDataValidation : IDisposable { IXLRanges Ranges { get; set; } //void Delete(); diff --git a/ClosedXML/Excel/DataValidation/IXLDataValidations.cs b/ClosedXML/Excel/DataValidation/IXLDataValidations.cs index 9dfca5f..dccd8d1 100644 --- a/ClosedXML/Excel/DataValidation/IXLDataValidations.cs +++ b/ClosedXML/Excel/DataValidation/IXLDataValidations.cs @@ -3,7 +3,7 @@ namespace ClosedXML.Excel { - public interface IXLDataValidations: IEnumerable + public interface IXLDataValidations: IEnumerable, IDisposable { void Add(IXLDataValidation dataValidation); Boolean ContainsSingle(IXLRange range); diff --git a/ClosedXML/Excel/DataValidation/XLDataValidation.cs b/ClosedXML/Excel/DataValidation/XLDataValidation.cs index 3ee5896..9d5ec8b 100644 --- a/ClosedXML/Excel/DataValidation/XLDataValidation.cs +++ b/ClosedXML/Excel/DataValidation/XLDataValidation.cs @@ -197,5 +197,10 @@ { Initialize(); } + + public void Dispose() + { + Ranges?.Dispose(); + } } } diff --git a/ClosedXML/Excel/DataValidation/XLDataValidations.cs b/ClosedXML/Excel/DataValidation/XLDataValidations.cs index fa339f6..3387588 100644 --- a/ClosedXML/Excel/DataValidation/XLDataValidations.cs +++ b/ClosedXML/Excel/DataValidation/XLDataValidations.cs @@ -50,5 +50,10 @@ { _dataValidations.RemoveAll(dv => dv.Ranges.Contains(range)); } + + public void Dispose() + { + _dataValidations.ForEach(dv => dv.Dispose()); + } } } diff --git a/ClosedXML/Excel/Drawings/XLPicture.cs b/ClosedXML/Excel/Drawings/XLPicture.cs index b1e44e8..d0732db 100644 --- a/ClosedXML/Excel/Drawings/XLPicture.cs +++ b/ClosedXML/Excel/Drawings/XLPicture.cs @@ -333,12 +333,12 @@ internal void SetName(string value) { - if (value.IndexOfAny(InvalidNameChars.ToCharArray()) != -1) - throw new ArgumentException($"Picture names cannot contain any of the following characters: {InvalidNameChars}"); - if (String.IsNullOrWhiteSpace(value)) throw new ArgumentException("Picture names cannot be empty"); + if (value.IndexOfAny(InvalidNameChars.ToCharArray()) != -1) + throw new ArgumentException($"Picture names cannot contain any of the following characters: {InvalidNameChars}"); + if (value.Length > 31) throw new ArgumentException("Picture names cannot be more than 31 characters"); diff --git a/ClosedXML/Excel/Ranges/XLRange.cs b/ClosedXML/Excel/Ranges/XLRange.cs index e4d4c85..7a20194 100644 --- a/ClosedXML/Excel/Ranges/XLRange.cs +++ b/ClosedXML/Excel/Ranges/XLRange.cs @@ -803,7 +803,9 @@ public override bool Equals(object obj) { - var other = (XLRange)obj; + var other = obj as XLRange; + if (other == null) + return false; return RangeAddress.Equals(other.RangeAddress) && Worksheet.Equals(other.Worksheet); } diff --git a/ClosedXML/Excel/Ranges/XLRangeAddress.cs b/ClosedXML/Excel/Ranges/XLRangeAddress.cs index d900347..2594558 100644 --- a/ClosedXML/Excel/Ranges/XLRangeAddress.cs +++ b/ClosedXML/Excel/Ranges/XLRangeAddress.cs @@ -191,7 +191,9 @@ public override bool Equals(object obj) { - var other = (XLRangeAddress)obj; + var other = obj as XLRangeAddress; + if (other == null) + return false; return Worksheet.Equals(other.Worksheet) && FirstAddress.Equals(other.FirstAddress) && LastAddress.Equals(other.LastAddress); diff --git a/ClosedXML/Excel/Rows/XLRow.cs b/ClosedXML/Excel/Rows/XLRow.cs index 9e263b7..b4076ca 100644 --- a/ClosedXML/Excel/Rows/XLRow.cs +++ b/ClosedXML/Excel/Rows/XLRow.cs @@ -331,7 +331,7 @@ else { Double rotation; - if (textRotation == 90 || textRotation == 180 || textRotation == 255) + if (textRotation == 90 || textRotation == 180) rotation = 90; else rotation = textRotation % 90; diff --git a/ClosedXML/Excel/Tables/IXLTableField.cs b/ClosedXML/Excel/Tables/IXLTableField.cs index 4c2fb00..9fb10ec 100644 --- a/ClosedXML/Excel/Tables/IXLTableField.cs +++ b/ClosedXML/Excel/Tables/IXLTableField.cs @@ -16,7 +16,7 @@ Custom } - public interface IXLTableField + public interface IXLTableField : IDisposable { /// /// Gets the corresponding column for this table field. diff --git a/ClosedXML/Excel/Tables/XLTable.cs b/ClosedXML/Excel/Tables/XLTable.cs index 528eb6d..6eb0a9e 100644 --- a/ClosedXML/Excel/Tables/XLTable.cs +++ b/ClosedXML/Excel/Tables/XLTable.cs @@ -22,13 +22,14 @@ public XLTable(XLRange range, Boolean addToTables, Boolean setAutofilter = true) : base(new XLRangeParameters(range.RangeAddress, range.Style)) { + CheckRangeNotInTable(range); InitializeValues(setAutofilter); Int32 id = 1; while (true) { string tableName = String.Concat("Table", id); - if (Worksheet.Tables.All(t => t.Name != tableName)) + if (!Worksheet.Tables.Any(t => t.Name.Equals(tableName, StringComparison.OrdinalIgnoreCase))) { Name = tableName; AddToTables(range, addToTables); @@ -41,6 +42,7 @@ public XLTable(XLRange range, String name, Boolean addToTables, Boolean setAutofilter = true) : base(new XLRangeParameters(range.RangeAddress, range.Style)) { + CheckRangeNotInTable(range); InitializeValues(setAutofilter); Name = name; @@ -562,6 +564,8 @@ if (AutoFilter != null) AutoFilter.Dispose(); + Fields?.ForEach(field => field.Dispose()); + base.Dispose(); } @@ -858,5 +862,12 @@ return table; } + + private static void CheckRangeNotInTable(XLRange range) + { + var overlappingTables = range.Worksheet.Tables.Where(t => t.RangeUsed().Intersects(range)); + if (overlappingTables.Any()) + throw new ArgumentException(nameof(range), $"The range {range.RangeAddress.ToStringRelative(true)} is already part of table '{overlappingTables.First().Name}'"); + } } } diff --git a/ClosedXML/Excel/Tables/XLTableField.cs b/ClosedXML/Excel/Tables/XLTableField.cs index dabb701..32c5c17 100644 --- a/ClosedXML/Excel/Tables/XLTableField.cs +++ b/ClosedXML/Excel/Tables/XLTableField.cs @@ -213,5 +213,10 @@ } } } + + public void Dispose() + { + _column.Dispose(); + } } } diff --git a/ClosedXML/Excel/XLWorkbook_Load.cs b/ClosedXML/Excel/XLWorkbook_Load.cs index 7ca1145..0d9de6c 100644 --- a/ClosedXML/Excel/XLWorkbook_Load.cs +++ b/ClosedXML/Excel/XLWorkbook_Load.cs @@ -278,7 +278,7 @@ var dTable = tableDefinitionPart.Table; String reference = dTable.Reference.Value; - String tableName = dTable?.Name ?? dTable.DisplayName ?? string.Empty; + String tableName = dTable.Name ?? dTable.DisplayName ?? string.Empty; if (String.IsNullOrWhiteSpace(tableName)) throw new InvalidDataException("The table name is missing."); @@ -324,7 +324,7 @@ if (dTable.AutoFilter != null) { xlTable.ShowAutoFilter = true; - LoadAutoFilterColumns(dTable.AutoFilter, (xlTable as XLTable).AutoFilter); + LoadAutoFilterColumns(dTable.AutoFilter, xlTable.AutoFilter); } else xlTable.ShowAutoFilter = false; @@ -374,7 +374,7 @@ // find cell by reference var cell = ws.Cell(c.Reference); - XLComment xlComment = cell.Comment as XLComment; + var xlComment = cell.Comment; xlComment.Author = authors[(int)c.AuthorId.Value].InnerText; //xlComment.ShapeId = (Int32)c.ShapeId.Value; //ShapeIdManager.Add(xlComment.ShapeId); @@ -384,7 +384,7 @@ { var runProperties = run.RunProperties; String text = run.Text.InnerText.FixNewLines(); - var rt = cell.Comment.AddText(text); + var rt = xlComment.AddText(text); LoadFont(runProperties, rt); } @@ -908,7 +908,7 @@ xdoc = XDocumentExtensions.Load(vmlPart.GetStream(FileMode.Open)); //Probe for comments - if (xdoc.Root == null) continue; + if (xdoc?.Root == null) continue; var shape = GetCommentShape(xdoc); if (shape != null) break; } @@ -1360,12 +1360,9 @@ else formula = cell.CellFormula.Text; - if (cell.CellFormula.Reference != null) - { - // Parent cell of shared formulas - // Child cells will use this shared index to set its R1C1 style formula - xlCell.FormulaReference = ws.Range(cell.CellFormula.Reference.Value).RangeAddress; - } + // Parent cell of shared formulas + // Child cells will use this shared index to set its R1C1 style formula + xlCell.FormulaReference = ws.Range(cell.CellFormula.Reference.Value).RangeAddress; xlCell.FormulaA1 = formula; sharedFormulasR1C1.Add(cell.CellFormula.SharedIndex.Value, xlCell.FormulaR1C1); @@ -2146,7 +2143,7 @@ if (conditionalFormat.ConditionalFormatType == XLConditionalFormatType.CellIs && fr.Operator != null) conditionalFormat.Operator = fr.Operator.Value.ToClosedXml(); - if (fr.Text != null && !String.IsNullOrWhiteSpace(fr.Text)) + if (!String.IsNullOrWhiteSpace(fr.Text)) conditionalFormat.Values.Add(GetFormula(fr.Text.Value)); if (conditionalFormat.ConditionalFormatType == XLConditionalFormatType.Top10) diff --git a/ClosedXML/Excel/XLWorkbook_Save.cs b/ClosedXML/Excel/XLWorkbook_Save.cs index fa3e568..0b4dea1 100644 --- a/ClosedXML/Excel/XLWorkbook_Save.cs +++ b/ClosedXML/Excel/XLWorkbook_Save.cs @@ -1066,6 +1066,9 @@ { if (c.HasArrayFormula) { + if (c.FormulaReference == null) + c.FormulaReference = c.AsRange().RangeAddress; + if (c.FormulaReference.FirstAddress.Equals(c.Address)) { var cc = new CalculationCell @@ -1074,9 +1077,6 @@ SheetId = worksheet.SheetId }; - if (c.FormulaReference == null) - c.FormulaReference = c.AsRange().RangeAddress; - cc.Array = true; calculationChain.AppendChild(cc); @@ -2495,8 +2495,9 @@ if (labelOrFilterField != null && labelOrFilterField.Collapsed) item.HideDetails = BooleanValue.FromBoolean(false); - if (labelOrFilterField.SelectedValues.Count > 1 - && !labelOrFilterField.SelectedValues.Contains(value)) + if (labelOrFilterField != null && + labelOrFilterField.SelectedValues.Count > 1 && + !labelOrFilterField.SelectedValues.Contains(value)) item.Hidden = BooleanValue.FromBoolean(true); fieldItems.AppendChild(item); @@ -5463,7 +5464,9 @@ cm.SetElement(XLWSContentManager.XLWSContents.Drawing, worksheetPart.Worksheet.Elements().First()); } - if (!xlWorksheet.Pictures.Any() && worksheetPart.DrawingsPart != null) + // Instead of saving a file with an empty Drawings.xml file, rather remove the .xml file + if (!xlWorksheet.Pictures.Any() && worksheetPart.DrawingsPart != null + && !worksheetPart.DrawingsPart.Parts.Any()) { var id = worksheetPart.GetIdOfPart(worksheetPart.DrawingsPart); worksheetPart.Worksheet.RemoveChild(worksheetPart.Worksheet.OfType().FirstOrDefault(p => p.Id == id)); diff --git a/ClosedXML/Excel/XLWorksheet.cs b/ClosedXML/Excel/XLWorksheet.cs index 5775416..e9e1af5 100644 --- a/ClosedXML/Excel/XLWorksheet.cs +++ b/ClosedXML/Excel/XLWorksheet.cs @@ -157,13 +157,13 @@ get { return _name; } set { + if (String.IsNullOrWhiteSpace(value)) + throw new ArgumentException("Worksheet names cannot be empty"); + if (value.IndexOfAny(InvalidNameChars.ToCharArray()) != -1) throw new ArgumentException("Worksheet names cannot contain any of the following characters: " + InvalidNameChars); - if (String.IsNullOrWhiteSpace(value)) - throw new ArgumentException("Worksheet names cannot be empty"); - if (value.Length > 31) throw new ArgumentException("Worksheet names cannot be more than 31 characters"); @@ -471,7 +471,7 @@ public IXLWorksheet ExpandColumns() { - Enumerable.Range(1, 8).ForEach(i => ExpandRows(i)); + Enumerable.Range(1, 8).ForEach(i => ExpandColumns(i)); return this; } @@ -976,6 +976,8 @@ Internals.Dispose(); + SelectedRanges?.Dispose(); + DataValidations?.Dispose(); this.Pictures.ForEach(p => p.Dispose()); base.Dispose(); diff --git a/ClosedXML/XLHelper.cs b/ClosedXML/XLHelper.cs index 5bb1bd5..e505099 100644 --- a/ClosedXML/XLHelper.cs +++ b/ClosedXML/XLHelper.cs @@ -116,8 +116,10 @@ public static bool IsValidColumn(string column) { + if (String.IsNullOrWhiteSpace(column)) + return false; var length = column.Length; - if (String.IsNullOrWhiteSpace(column) || length > 3) + if (length > 3) return false; var theColumn = column.ToUpper(); diff --git a/ClosedXML_Tests/Excel/ConditionalFormats/ConditionalFormatTests.cs b/ClosedXML_Tests/Excel/ConditionalFormats/ConditionalFormatTests.cs index 983a5d6..ffa7bd2 100644 --- a/ClosedXML_Tests/Excel/ConditionalFormats/ConditionalFormatTests.cs +++ b/ClosedXML_Tests/Excel/ConditionalFormats/ConditionalFormatTests.cs @@ -1,11 +1,6 @@ using ClosedXML.Excel; using NUnit.Framework; -using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace ClosedXML_Tests.Excel.ConditionalFormats { @@ -15,7 +10,7 @@ [Test] public void MaintainConditionalFormattingOrder() { - using (var stream = TestHelper.GetStreamFromResource(TestHelper.GetResourcePath(@"StyleReferenceFiles\ConditionalFormattingOrder\inputfile.xlsx"))) + using (var stream = TestHelper.GetStreamFromResource(TestHelper.GetResourcePath(@"Other\StyleReferenceFiles\ConditionalFormattingOrder\inputfile.xlsx"))) using (var ms = new MemoryStream()) { TestHelper.CreateAndCompare(() => @@ -23,9 +18,8 @@ var wb = new XLWorkbook(stream); wb.SaveAs(ms); return wb; - }, @"StyleReferenceFiles\ConditionalFormattingOrder\ConditionalFormattingOrder.xlsx"); + }, @"Other\StyleReferenceFiles\ConditionalFormattingOrder\ConditionalFormattingOrder.xlsx"); } } - } } diff --git a/ClosedXML_Tests/Excel/Saving/SavingTests.cs b/ClosedXML_Tests/Excel/Saving/SavingTests.cs index 4b19a6b..e0fa221 100644 --- a/ClosedXML_Tests/Excel/Saving/SavingTests.cs +++ b/ClosedXML_Tests/Excel/Saving/SavingTests.cs @@ -254,5 +254,38 @@ wb.SaveAs(ms); } } + + [Test] + public void PreserveChartsWhenSaving() + { + using (var stream = TestHelper.GetStreamFromResource(TestHelper.GetResourcePath(@"Other\Charts\PreserveCharts\inputfile.xlsx"))) + using (var ms = new MemoryStream()) + { + TestHelper.CreateAndCompare(() => + { + var wb = new XLWorkbook(stream); + wb.SaveAs(ms); + return wb; + }, @"Other\Charts\PreserveCharts\outputfile.xlsx"); + } + } + + [Test] + public void DeletingAllPicturesRemovesDrawingPart() + { + TestHelper.CreateAndCompare(() => + { + var stream = TestHelper.GetStreamFromResource(TestHelper.GetResourcePath(@"Examples\ImageHandling\ImageAnchors.xlsx")); + var wb = new XLWorkbook(stream); + foreach (var ws in wb.Worksheets) + { + var pictureNames = ws.Pictures.Select(pic => pic.Name).ToArray(); + foreach (var name in pictureNames) + ws.Pictures.Delete(name); + } + + return wb; + }, @"Other\Drawings\NoDrawings\outputfile.xlsx"); + } } -} \ No newline at end of file +} diff --git a/ClosedXML_Tests/Excel/Styles/XLFillTests.cs b/ClosedXML_Tests/Excel/Styles/XLFillTests.cs index 90183cb..90c3e08 100644 --- a/ClosedXML_Tests/Excel/Styles/XLFillTests.cs +++ b/ClosedXML_Tests/Excel/Styles/XLFillTests.cs @@ -66,7 +66,7 @@ [Test] public void LoadAndSaveTransparentBackgroundFill() { - using (var stream = TestHelper.GetStreamFromResource(TestHelper.GetResourcePath(@"StyleReferenceFiles\TransparentBackgroundFill\inputfile.xlsx"))) + using (var stream = TestHelper.GetStreamFromResource(TestHelper.GetResourcePath(@"Other\StyleReferenceFiles\TransparentBackgroundFill\inputfile.xlsx"))) using (var ms = new MemoryStream()) { TestHelper.CreateAndCompare(() => @@ -74,7 +74,7 @@ var wb = new XLWorkbook(stream); wb.SaveAs(ms); return wb; - }, @"StyleReferenceFiles\TransparentBackgroundFill\TransparentBackgroundFill.xlsx"); + }, @"Other\StyleReferenceFiles\TransparentBackgroundFill\TransparentBackgroundFill.xlsx"); } } } diff --git a/ClosedXML_Tests/Excel/Tables/TablesTests.cs b/ClosedXML_Tests/Excel/Tables/TablesTests.cs index e5868fa..f440bd3 100644 --- a/ClosedXML_Tests/Excel/Tables/TablesTests.cs +++ b/ClosedXML_Tests/Excel/Tables/TablesTests.cs @@ -763,6 +763,24 @@ } } + [Test] + public void CannotCreateDuplicateTablesOverSameRange() + { + var l = new List() + { + new TestObjectWithAttributes() { Column1 = "a", Column2 = "b", MyField = 4, UnOrderedColumn = 999 }, + new TestObjectWithAttributes() { Column1 = "c", Column2 = "d", MyField = 5, UnOrderedColumn = 777 } + }; + + using (var wb = new XLWorkbook()) + { + IXLWorksheet ws = wb.AddWorksheet("Sheet1"); + ws.FirstCell().InsertTable(l); + Assert.Throws(() => ws.RangeUsed().CreateTable()); + } + + } + //TODO: Delete table (not underlying range) } } diff --git a/ClosedXML_Tests/Resource/Other/Charts/PreserveCharts/inputfile.xlsx b/ClosedXML_Tests/Resource/Other/Charts/PreserveCharts/inputfile.xlsx new file mode 100644 index 0000000..f2c41f2 --- /dev/null +++ b/ClosedXML_Tests/Resource/Other/Charts/PreserveCharts/inputfile.xlsx Binary files differ diff --git a/ClosedXML_Tests/Resource/Other/Charts/PreserveCharts/outputfile.xlsx b/ClosedXML_Tests/Resource/Other/Charts/PreserveCharts/outputfile.xlsx new file mode 100644 index 0000000..fe5db26 --- /dev/null +++ b/ClosedXML_Tests/Resource/Other/Charts/PreserveCharts/outputfile.xlsx Binary files differ diff --git a/ClosedXML_Tests/Resource/Other/Drawings/NoDrawings/outputfile.xlsx b/ClosedXML_Tests/Resource/Other/Drawings/NoDrawings/outputfile.xlsx new file mode 100644 index 0000000..4cf9bea --- /dev/null +++ b/ClosedXML_Tests/Resource/Other/Drawings/NoDrawings/outputfile.xlsx Binary files differ diff --git a/ClosedXML_Tests/Resource/Other/StyleReferenceFiles/ConditionalFormattingOrder/ConditionalFormattingOrder.xlsx b/ClosedXML_Tests/Resource/Other/StyleReferenceFiles/ConditionalFormattingOrder/ConditionalFormattingOrder.xlsx new file mode 100644 index 0000000..84c186d --- /dev/null +++ b/ClosedXML_Tests/Resource/Other/StyleReferenceFiles/ConditionalFormattingOrder/ConditionalFormattingOrder.xlsx Binary files differ diff --git a/ClosedXML_Tests/Resource/Other/StyleReferenceFiles/ConditionalFormattingOrder/inputfile.xlsx b/ClosedXML_Tests/Resource/Other/StyleReferenceFiles/ConditionalFormattingOrder/inputfile.xlsx new file mode 100644 index 0000000..28a7fcd --- /dev/null +++ b/ClosedXML_Tests/Resource/Other/StyleReferenceFiles/ConditionalFormattingOrder/inputfile.xlsx Binary files differ diff --git a/ClosedXML_Tests/Resource/Other/StyleReferenceFiles/TransparentBackgroundFill/TransparentBackgroundFill.xlsx b/ClosedXML_Tests/Resource/Other/StyleReferenceFiles/TransparentBackgroundFill/TransparentBackgroundFill.xlsx new file mode 100644 index 0000000..ffd35b3 --- /dev/null +++ b/ClosedXML_Tests/Resource/Other/StyleReferenceFiles/TransparentBackgroundFill/TransparentBackgroundFill.xlsx Binary files differ diff --git a/ClosedXML_Tests/Resource/Other/StyleReferenceFiles/TransparentBackgroundFill/inputfile.xlsx b/ClosedXML_Tests/Resource/Other/StyleReferenceFiles/TransparentBackgroundFill/inputfile.xlsx new file mode 100644 index 0000000..6d6f1a8 --- /dev/null +++ b/ClosedXML_Tests/Resource/Other/StyleReferenceFiles/TransparentBackgroundFill/inputfile.xlsx Binary files differ diff --git a/ClosedXML_Tests/Resource/StyleReferenceFiles/ConditionalFormattingOrder/ConditionalFormattingOrder.xlsx b/ClosedXML_Tests/Resource/StyleReferenceFiles/ConditionalFormattingOrder/ConditionalFormattingOrder.xlsx deleted file mode 100644 index 84c186d..0000000 --- a/ClosedXML_Tests/Resource/StyleReferenceFiles/ConditionalFormattingOrder/ConditionalFormattingOrder.xlsx +++ /dev/null Binary files differ diff --git a/ClosedXML_Tests/Resource/StyleReferenceFiles/ConditionalFormattingOrder/inputfile.xlsx b/ClosedXML_Tests/Resource/StyleReferenceFiles/ConditionalFormattingOrder/inputfile.xlsx deleted file mode 100644 index 28a7fcd..0000000 --- a/ClosedXML_Tests/Resource/StyleReferenceFiles/ConditionalFormattingOrder/inputfile.xlsx +++ /dev/null Binary files differ diff --git a/ClosedXML_Tests/Resource/StyleReferenceFiles/TransparentBackgroundFill/TransparentBackgroundFill.xlsx b/ClosedXML_Tests/Resource/StyleReferenceFiles/TransparentBackgroundFill/TransparentBackgroundFill.xlsx deleted file mode 100644 index ffd35b3..0000000 --- a/ClosedXML_Tests/Resource/StyleReferenceFiles/TransparentBackgroundFill/TransparentBackgroundFill.xlsx +++ /dev/null Binary files differ diff --git a/ClosedXML_Tests/Resource/StyleReferenceFiles/TransparentBackgroundFill/inputfile.xlsx b/ClosedXML_Tests/Resource/StyleReferenceFiles/TransparentBackgroundFill/inputfile.xlsx deleted file mode 100644 index 6d6f1a8..0000000 --- a/ClosedXML_Tests/Resource/StyleReferenceFiles/TransparentBackgroundFill/inputfile.xlsx +++ /dev/null Binary files differ diff --git a/ClosedXML_Tests/TestHelper.cs b/ClosedXML_Tests/TestHelper.cs index 1887cd5..476247c 100644 --- a/ClosedXML_Tests/TestHelper.cs +++ b/ClosedXML_Tests/TestHelper.cs @@ -28,7 +28,6 @@ public const string ActualTestResultPostFix = ""; public static readonly string ExampleTestsOutputDirectory = Path.Combine(TestsOutputDirectory, "Examples"); - public static readonly string OtherTestsOutputDirectory = Path.Combine(TestsOutputDirectory, "Other"); private const bool CompareWithResources = true; @@ -101,7 +100,7 @@ Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); string[] pathParts = referenceResource.Split(new char[] { '\\' }); - string filePath1 = Path.Combine(new List() { OtherTestsOutputDirectory }.Concat(pathParts).ToArray()); + string filePath1 = Path.Combine(new List() { TestsOutputDirectory }.Concat(pathParts).ToArray()); var extension = Path.GetExtension(filePath1); var directory = Path.GetDirectoryName(filePath1);