diff --git a/ClosedXML/Attributes/XLColumnAttribute.cs b/ClosedXML/Attributes/XLColumnAttribute.cs index 526dcb0..a86a1be 100644 --- a/ClosedXML/Attributes/XLColumnAttribute.cs +++ b/ClosedXML/Attributes/XLColumnAttribute.cs @@ -1,8 +1,7 @@ +using ClosedXML.Excel; using System; using System.Linq; using System.Reflection; -using ClosedXML; -using ClosedXML.Excel; namespace ClosedXML.Attributes { @@ -23,7 +22,7 @@ { var attribute = GetXLColumnAttribute(mi); if (attribute == null) return null; - return String.IsNullOrWhiteSpace(attribute.Header) ? null : attribute.Header; + return XLHelper.IsNullOrWhiteSpace(attribute.Header) ? null : attribute.Header; } internal static Int32 GetOrder(MemberInfo mi) diff --git a/ClosedXML/ClosedXML.csproj b/ClosedXML/ClosedXML.csproj index 4500c11..ac2e5f0 100644 --- a/ClosedXML/ClosedXML.csproj +++ b/ClosedXML/ClosedXML.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net40;net461 + netstandard2.0;net35;net40;net461 0.9 Manuel de Leon, Amir Ghezelbash, Francois Botha @@ -17,6 +17,10 @@ $(DefineConstants);_NETSTANDARD_;_NETSTANDARD2_0_ + + $(DefineConstants);_NETFRAMEWORK_;_NET35_ + + $(DefineConstants);_NETFRAMEWORK_;_NET40_ @@ -36,6 +40,11 @@ + + + + + diff --git a/ClosedXML/Excel/CalcEngine/XLCalcEngine.cs b/ClosedXML/Excel/CalcEngine/XLCalcEngine.cs index 108ea40..96a8f62 100644 --- a/ClosedXML/Excel/CalcEngine/XLCalcEngine.cs +++ b/ClosedXML/Excel/CalcEngine/XLCalcEngine.cs @@ -98,7 +98,7 @@ { _evaluating = true; var f = cell.FormulaA1; - if (String.IsNullOrWhiteSpace(f)) + if (XLHelper.IsNullOrWhiteSpace(f)) return cell.Value; else return new XLCalcEngine(cell.Worksheet).Evaluate(f); diff --git a/ClosedXML/Excel/Cells/XLCell.cs b/ClosedXML/Excel/Cells/XLCell.cs index 23bbba7..1bdf58f 100644 --- a/ClosedXML/Excel/Cells/XLCell.cs +++ b/ClosedXML/Excel/Cells/XLCell.cs @@ -368,7 +368,7 @@ get { var fA1 = FormulaA1; - if (!String.IsNullOrWhiteSpace(fA1)) + if (!XLHelper.IsNullOrWhiteSpace(fA1)) { if (fA1[0] == '{') fA1 = fA1.Substring(1, fA1.Length - 2); @@ -503,7 +503,7 @@ if (!hasTitles) { var fieldName = XLColumnAttribute.GetHeader(itemType); - if (String.IsNullOrWhiteSpace(fieldName)) + if (XLHelper.IsNullOrWhiteSpace(fieldName)) fieldName = itemType.Name; SetValue(fieldName, fRo, co); @@ -581,7 +581,7 @@ if (!hasTitles) { foreach (var fieldName in from DataColumn column in row.Table.Columns - select String.IsNullOrWhiteSpace(column.Caption) + select XLHelper.IsNullOrWhiteSpace(column.Caption) ? column.ColumnName : column.Caption) { @@ -634,7 +634,7 @@ if ((mi as IEnumerable) == null) { var fieldName = XLColumnAttribute.GetHeader(mi); - if (String.IsNullOrWhiteSpace(fieldName)) + if (XLHelper.IsNullOrWhiteSpace(fieldName)) fieldName = mi.Name; SetValue(fieldName, fRo, co); @@ -1017,9 +1017,9 @@ { get { - if (String.IsNullOrWhiteSpace(_formulaA1)) + if (XLHelper.IsNullOrWhiteSpace(_formulaA1)) { - if (!String.IsNullOrWhiteSpace(_formulaR1C1)) + if (!XLHelper.IsNullOrWhiteSpace(_formulaR1C1)) { _formulaA1 = GetFormulaA1(_formulaR1C1); return FormulaA1; @@ -1039,7 +1039,7 @@ set { - _formulaA1 = String.IsNullOrWhiteSpace(value) ? null : value; + _formulaA1 = XLHelper.IsNullOrWhiteSpace(value) ? null : value; _formulaR1C1 = null; } @@ -1049,7 +1049,7 @@ { get { - if (String.IsNullOrWhiteSpace(_formulaR1C1)) + if (XLHelper.IsNullOrWhiteSpace(_formulaR1C1)) _formulaR1C1 = GetFormulaR1C1(FormulaA1); return _formulaR1C1; @@ -1057,7 +1057,7 @@ set { - _formulaR1C1 = String.IsNullOrWhiteSpace(value) ? null : value; + _formulaR1C1 = XLHelper.IsNullOrWhiteSpace(value) ? null : value; } } @@ -1598,7 +1598,7 @@ { var style = GetStyleForRead(); return _dataType == XLCellValues.Number - && String.IsNullOrWhiteSpace(style.NumberFormat.Format) + && XLHelper.IsNullOrWhiteSpace(style.NumberFormat.Format) && ((style.NumberFormat.NumberFormatId >= 14 && style.NumberFormat.NumberFormatId <= 22) || (style.NumberFormat.NumberFormatId >= 45 @@ -1609,7 +1609,7 @@ { var format = String.Empty; var style = GetStyleForRead(); - if (String.IsNullOrWhiteSpace(style.NumberFormat.Format)) + if (XLHelper.IsNullOrWhiteSpace(style.NumberFormat.Format)) { var formatCodes = GetFormatCodes(); if (formatCodes.ContainsKey(style.NumberFormat.NumberFormatId)) @@ -1853,7 +1853,7 @@ private string GetFormula(string strValue, FormulaConversionType conversionType, int rowsToShift, int columnsToShift) { - if (String.IsNullOrWhiteSpace(strValue)) + if (XLHelper.IsNullOrWhiteSpace(strValue)) return String.Empty; var value = ">" + strValue + "<"; @@ -2127,7 +2127,7 @@ internal static String ShiftFormulaRows(String formulaA1, XLWorksheet worksheetInAction, XLRange shiftedRange, int rowsShifted) { - if (String.IsNullOrWhiteSpace(formulaA1)) return String.Empty; + if (XLHelper.IsNullOrWhiteSpace(formulaA1)) return String.Empty; var value = formulaA1; // ">" + formulaA1 + "<"; @@ -2332,7 +2332,7 @@ internal static String ShiftFormulaColumns(String formulaA1, XLWorksheet worksheetInAction, XLRange shiftedRange, int columnsShifted) { - if (String.IsNullOrWhiteSpace(formulaA1)) return String.Empty; + if (XLHelper.IsNullOrWhiteSpace(formulaA1)) return String.Empty; var value = formulaA1; // ">" + formulaA1 + "<"; @@ -2660,7 +2660,7 @@ #endregion XLCell Right - public Boolean HasFormula { get { return !String.IsNullOrWhiteSpace(FormulaA1); } } + public Boolean HasFormula { get { return !XLHelper.IsNullOrWhiteSpace(FormulaA1); } } public Boolean HasArrayFormula { get { return FormulaA1.StartsWith("{"); } } diff --git a/ClosedXML/Excel/DataValidation/XLDataValidation.cs b/ClosedXML/Excel/DataValidation/XLDataValidation.cs index 17164c0..321e6d8 100644 --- a/ClosedXML/Excel/DataValidation/XLDataValidation.cs +++ b/ClosedXML/Excel/DataValidation/XLDataValidation.cs @@ -41,9 +41,9 @@ return AllowedValues != XLAllowedValues.AnyValue || (ShowInputMessage && - (!String.IsNullOrWhiteSpace(InputTitle) || !String.IsNullOrWhiteSpace(InputMessage))) + (!XLHelper.IsNullOrWhiteSpace(InputTitle) || !XLHelper.IsNullOrWhiteSpace(InputMessage))) ||(ShowErrorMessage && - (!String.IsNullOrWhiteSpace(ErrorTitle) || !String.IsNullOrWhiteSpace(ErrorMessage))); + (!XLHelper.IsNullOrWhiteSpace(ErrorTitle) || !XLHelper.IsNullOrWhiteSpace(ErrorMessage))); } diff --git a/ClosedXML/Excel/Drawings/XLPicture.cs b/ClosedXML/Excel/Drawings/XLPicture.cs index 612a3cb..7628b3b 100644 --- a/ClosedXML/Excel/Drawings/XLPicture.cs +++ b/ClosedXML/Excel/Drawings/XLPicture.cs @@ -1,3 +1,4 @@ +using ClosedXML.Extensions; using MetadataExtractor; using MetadataExtractor.Formats.Bmp; using MetadataExtractor.Formats.Exif; @@ -326,7 +327,7 @@ if (value.IndexOfAny(InvalidNameChars.ToCharArray()) != -1) throw new ArgumentException($"Picture names cannot contain any of the following characters: {InvalidNameChars}"); - if (String.IsNullOrWhiteSpace(value)) + if (XLHelper.IsNullOrWhiteSpace(value)) throw new ArgumentException("Picture names cannot be empty"); if (value.Length > 31) diff --git a/ClosedXML/Excel/Misc/XLFormula.cs b/ClosedXML/Excel/Misc/XLFormula.cs index 8027667..34cea84 100644 --- a/ClosedXML/Excel/Misc/XLFormula.cs +++ b/ClosedXML/Excel/Misc/XLFormula.cs @@ -44,7 +44,7 @@ else { _value = value.Trim(); - IsFormula = !String.IsNullOrWhiteSpace(_value) && _value.TrimStart()[0] == '=' ; + IsFormula = !XLHelper.IsNullOrWhiteSpace(_value) && _value.TrimStart()[0] == '=' ; if (IsFormula) _value = _value.Substring(1); } diff --git a/ClosedXML/Excel/Ranges/XLRangeBase.cs b/ClosedXML/Excel/Ranges/XLRangeBase.cs index 0534107..0f692ea 100644 --- a/ClosedXML/Excel/Ranges/XLRangeBase.cs +++ b/ClosedXML/Excel/Ranges/XLRangeBase.cs @@ -1102,7 +1102,7 @@ { foreach (XLWorksheet ws in Worksheet.Workbook.WorksheetsInternal) { - foreach (XLCell cell in ws.Internals.CellsCollection.GetCells(c => !String.IsNullOrWhiteSpace(c.FormulaA1))) + foreach (XLCell cell in ws.Internals.CellsCollection.GetCells(c => !XLHelper.IsNullOrWhiteSpace(c.FormulaA1))) using (var asRange = AsRange()) cell.ShiftFormulaColumns(asRange, numberOfColumns); } @@ -1338,7 +1338,7 @@ using (var asRange = AsRange()) foreach (XLWorksheet ws in Worksheet.Workbook.WorksheetsInternal) { - foreach (XLCell cell in ws.Internals.CellsCollection.GetCells(c => !String.IsNullOrWhiteSpace(c.FormulaA1))) + foreach (XLCell cell in ws.Internals.CellsCollection.GetCells(c => !XLHelper.IsNullOrWhiteSpace(c.FormulaA1))) cell.ShiftFormulaRows(asRange, numberOfRows); } @@ -1514,7 +1514,7 @@ XLCell cell in Worksheet.Workbook.Worksheets.Cast().SelectMany( xlWorksheet => (xlWorksheet).Internals.CellsCollection.GetCells( - c => !String.IsNullOrWhiteSpace(c.FormulaA1)))) + c => !XLHelper.IsNullOrWhiteSpace(c.FormulaA1)))) { if (shiftDeleteCells == XLShiftDeletedCells.ShiftCellsUp) cell.ShiftFormulaRows((XLRange)shiftedRangeFormula, numberOfRows * -1); @@ -1794,7 +1794,7 @@ public IXLRangeBase Sort(String columnsToSortBy, XLSortOrder sortOrder = XLSortOrder.Ascending, Boolean matchCase = false, Boolean ignoreBlanks = true) { SortColumns.Clear(); - if (String.IsNullOrWhiteSpace(columnsToSortBy)) + if (XLHelper.IsNullOrWhiteSpace(columnsToSortBy)) { columnsToSortBy = String.Empty; Int32 maxColumn = ColumnCount(); diff --git a/ClosedXML/Excel/SaveOptions.cs b/ClosedXML/Excel/SaveOptions.cs index 7dcd9a1..62edb53 100644 --- a/ClosedXML/Excel/SaveOptions.cs +++ b/ClosedXML/Excel/SaveOptions.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace ClosedXML.Excel { @@ -19,6 +15,7 @@ this.EvaluateFormulasBeforeSaving = false; this.GenerateCalculationChain = true; } + public Boolean ValidatePackage; public Boolean EvaluateFormulasBeforeSaving; public Boolean GenerateCalculationChain; diff --git a/ClosedXML/Excel/Tables/XLTable.cs b/ClosedXML/Excel/Tables/XLTable.cs index 6048e33..3f82075 100644 --- a/ClosedXML/Excel/Tables/XLTable.cs +++ b/ClosedXML/Excel/Tables/XLTable.cs @@ -66,7 +66,7 @@ foreach (var cell in headersRow.Cells()) { var name = cell.GetString(); - if (String.IsNullOrWhiteSpace(name)) + if (XLHelper.IsNullOrWhiteSpace(name)) { name = "Column" + (cellPos + 1); cell.SetValue(name); @@ -405,7 +405,7 @@ Int32 co = 1; foreach (IXLCell c in range.Row(1).Cells()) { - if (String.IsNullOrWhiteSpace(((XLCell)c).InnerText)) + if (XLHelper.IsNullOrWhiteSpace(((XLCell)c).InnerText)) c.Value = GetUniqueName("Column" + co.ToInvariantString()); _uniqueNames.Add(c.GetString()); co++; @@ -459,7 +459,7 @@ Int32 co = 1; foreach (IXLCell c in headersRow.Cells()) { - if (String.IsNullOrWhiteSpace(((XLCell)c).InnerText)) + if (XLHelper.IsNullOrWhiteSpace(((XLCell)c).InnerText)) c.Value = GetUniqueName("Column" + co.ToInvariantString()); _uniqueNames.Add(c.GetString()); co++; diff --git a/ClosedXML/Excel/XLWorkbook_Load.cs b/ClosedXML/Excel/XLWorkbook_Load.cs index 9b6d306..13daf1e 100644 --- a/ClosedXML/Excel/XLWorkbook_Load.cs +++ b/ClosedXML/Excel/XLWorkbook_Load.cs @@ -21,6 +21,7 @@ namespace ClosedXML.Excel { using Ap; + using ClosedXML.Extensions; using Drawings; using Op; using System.Drawing; @@ -272,7 +273,7 @@ var dTable = tablePart.Table; String reference = dTable.Reference.Value; String tableName = dTable?.Name ?? dTable.DisplayName ?? string.Empty; - if (String.IsNullOrWhiteSpace(tableName)) + if (XLHelper.IsNullOrWhiteSpace(tableName)) throw new InvalidDataException("The table name is missing."); XLTable xlTable = ws.Range(reference).CreateTable(tableName, false) as XLTable; @@ -1206,7 +1207,7 @@ { if (cell.CellFormula.SharedIndex != null) xlCell.FormulaR1C1 = sharedFormulasR1C1[cell.CellFormula.SharedIndex.Value]; - else if (!String.IsNullOrWhiteSpace(cell.CellFormula.Text)) + else if (!XLHelper.IsNullOrWhiteSpace(cell.CellFormula.Text)) { String formula; if (cell.CellFormula.FormulaType != null && cell.CellFormula.FormulaType == CellFormulaValues.Array) @@ -1251,7 +1252,7 @@ } else if (cell.DataType == CellValues.SharedString) { - if (cell.CellValue != null && !String.IsNullOrWhiteSpace(cell.CellValue.Text)) + if (cell.CellValue != null && !XLHelper.IsNullOrWhiteSpace(cell.CellValue.Text)) { var sharedString = sharedStrings[Int32.Parse(cell.CellValue.Text, XLHelper.NumberStyle, XLHelper.ParseCulture)]; ParseCellValue(sharedString, xlCell); @@ -1263,7 +1264,7 @@ } else if (cell.DataType == CellValues.Date) { - if (cell.CellValue != null && !String.IsNullOrWhiteSpace(cell.CellValue.Text)) + if (cell.CellValue != null && !XLHelper.IsNullOrWhiteSpace(cell.CellValue.Text)) xlCell._cellValue = Double.Parse(cell.CellValue.Text, XLHelper.NumberStyle, XLHelper.ParseCulture).ToInvariantString(); xlCell._dataType = XLCellValues.DateTime; } @@ -1275,7 +1276,7 @@ } else if (cell.DataType == CellValues.Number) { - if (cell.CellValue != null && !String.IsNullOrWhiteSpace(cell.CellValue.Text)) + if (cell.CellValue != null && !XLHelper.IsNullOrWhiteSpace(cell.CellValue.Text)) xlCell._cellValue = Double.Parse(cell.CellValue.Text, XLHelper.NumberStyle, XLHelper.ParseCulture).ToInvariantString(); if (s == null) @@ -1293,7 +1294,7 @@ else { var numberFormatId = ((CellFormat)(s.CellFormats).ElementAt(styleIndex)).NumberFormatId; - if (!String.IsNullOrWhiteSpace(cell.CellValue.Text)) + if (!XLHelper.IsNullOrWhiteSpace(cell.CellValue.Text)) xlCell._cellValue = Double.Parse(cell.CellValue.Text, CultureInfo.InvariantCulture).ToInvariantString(); if (s.NumberingFormats != null && @@ -1585,7 +1586,7 @@ return XLCellValues.Text; else { - if (!String.IsNullOrWhiteSpace(numberFormat.Format)) + if (!XLHelper.IsNullOrWhiteSpace(numberFormat.Format)) { var dataType = GetDataTypeFromFormat(numberFormat.Format); return dataType.HasValue ? dataType.Value : XLCellValues.Number; @@ -1800,7 +1801,7 @@ foreach (DataValidation dvs in dataValidations.Elements()) { String txt = dvs.SequenceOfReferences.InnerText; - if (String.IsNullOrWhiteSpace(txt)) continue; + if (XLHelper.IsNullOrWhiteSpace(txt)) continue; foreach (var dvt in txt.Split(' ').Select(rangeAddress => ws.Range(rangeAddress).DataValidation)) { if (dvs.AllowBlank != null) dvt.IgnoreBlanks = dvs.AllowBlank; @@ -1848,7 +1849,7 @@ if (conditionalFormat.ConditionalFormatType == XLConditionalFormatType.CellIs && fr.Operator != null) conditionalFormat.Operator = fr.Operator.Value.ToClosedXml(); - if (fr.Text != null && !String.IsNullOrWhiteSpace(fr.Text)) + if (fr.Text != null && !XLHelper.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 ddc265a..0772682 100644 --- a/ClosedXML/Excel/XLWorkbook_Save.cs +++ b/ClosedXML/Excel/XLWorkbook_Save.cs @@ -1,3 +1,4 @@ +using ClosedXML.Extensions; using ClosedXML.Utils; using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.CustomProperties; @@ -45,7 +46,6 @@ using VerticalTextAlignment = DocumentFormat.OpenXml.Spreadsheet.VerticalTextAlignment; using Vml = DocumentFormat.OpenXml.Vml; using Xdr = DocumentFormat.OpenXml.Drawing.Spreadsheet; -using ClosedXML.Extensions; #if _NETSTANDARD_ @@ -241,12 +241,12 @@ // Ensure all RelId's have been added to the context context.RelIdGenerator.AddValues(workbookPart.Parts.Select(p => p.RelationshipId), RelType.Workbook); - context.RelIdGenerator.AddValues(WorksheetsInternal.Cast().Where(ws => !String.IsNullOrWhiteSpace(ws.RelId)).Select(ws => ws.RelId), RelType.Workbook); - context.RelIdGenerator.AddValues(WorksheetsInternal.Cast().Where(ws => !String.IsNullOrWhiteSpace(ws.LegacyDrawingId)).Select(ws => ws.LegacyDrawingId), RelType.Workbook); + context.RelIdGenerator.AddValues(WorksheetsInternal.Cast().Where(ws => !XLHelper.IsNullOrWhiteSpace(ws.RelId)).Select(ws => ws.RelId), RelType.Workbook); + context.RelIdGenerator.AddValues(WorksheetsInternal.Cast().Where(ws => !XLHelper.IsNullOrWhiteSpace(ws.LegacyDrawingId)).Select(ws => ws.LegacyDrawingId), RelType.Workbook); context.RelIdGenerator.AddValues(WorksheetsInternal .Cast() .SelectMany(ws => ws.Tables.Cast()) - .Where(t => !String.IsNullOrWhiteSpace(t.RelId)) + .Where(t => !XLHelper.IsNullOrWhiteSpace(t.RelId)) .Select(t => t.RelId), RelType.Workbook); var extendedFilePropertiesPart = document.ExtendedFilePropertiesPart ?? @@ -303,7 +303,7 @@ var vmlDrawingPart = worksheetPart.VmlDrawingParts.FirstOrDefault(); if (vmlDrawingPart == null) { - if (String.IsNullOrWhiteSpace(worksheet.LegacyDrawingId)) + if (XLHelper.IsNullOrWhiteSpace(worksheet.LegacyDrawingId)) { worksheet.LegacyDrawingId = context.RelIdGenerator.GetNext(RelType.Workbook); worksheet.LegacyDrawingIsNew = true; @@ -481,7 +481,7 @@ if (Properties.Manager != null) { - if (!String.IsNullOrWhiteSpace(Properties.Manager)) + if (!XLHelper.IsNullOrWhiteSpace(Properties.Manager)) { if (properties.Manager == null) properties.Manager = new Manager(); @@ -494,7 +494,7 @@ if (Properties.Company == null) return; - if (!String.IsNullOrWhiteSpace(Properties.Company)) + if (!XLHelper.IsNullOrWhiteSpace(Properties.Company)) { if (properties.Company == null) properties.Company = new Company(); @@ -624,7 +624,7 @@ foreach (var xlSheet in WorksheetsInternal.Cast().OrderBy(w => w.Position)) { string rId; - if (xlSheet.SheetId == 0 && String.IsNullOrWhiteSpace(xlSheet.RelId)) + if (xlSheet.SheetId == 0 && XLHelper.IsNullOrWhiteSpace(xlSheet.RelId)) { rId = context.RelIdGenerator.GetNext(RelType.Workbook); @@ -636,7 +636,7 @@ } else { - if (String.IsNullOrWhiteSpace(xlSheet.RelId)) + if (XLHelper.IsNullOrWhiteSpace(xlSheet.RelId)) { rId = String.Format("rId{0}", xlSheet.SheetId); context.RelIdGenerator.AddValues(new List { rId }, RelType.Workbook); @@ -781,7 +781,7 @@ if (!nr.Visible) definedName.Hidden = BooleanValue.FromBoolean(true); - if (!String.IsNullOrWhiteSpace(nr.Comment)) + if (!XLHelper.IsNullOrWhiteSpace(nr.Comment)) definedName.Comment = nr.Comment; definedNames.AppendChild(definedName); } @@ -835,7 +835,7 @@ if (!nr.Visible) definedName.Hidden = BooleanValue.FromBoolean(true); - if (!String.IsNullOrWhiteSpace(nr.Comment)) + if (!XLHelper.IsNullOrWhiteSpace(nr.Comment)) definedName.Comment = nr.Comment; definedNames.AppendChild(definedName); } @@ -881,7 +881,7 @@ w.Internals.CellsCollection.GetCells( c => ((c.DataType == XLCellValues.Text && c.ShareString) || c.HasRichText) && (c as XLCell).InnerText.Length > 0 - && String.IsNullOrWhiteSpace(c.FormulaA1) + && XLHelper.IsNullOrWhiteSpace(c.FormulaA1) ))) { c.DataType = XLCellValues.Text; @@ -1032,7 +1032,7 @@ var cellsWithoutFormulas = new HashSet(); foreach (var c in worksheet.Internals.CellsCollection.GetCells()) { - if (String.IsNullOrWhiteSpace(c.FormulaA1)) + if (XLHelper.IsNullOrWhiteSpace(c.FormulaA1)) cellsWithoutFormulas.Add(c.Address.ToStringRelative()); else { @@ -1862,7 +1862,7 @@ tableColumn1.TotalsRowFormula = new TotalsRowFormula(xlField.TotalsRowFormulaA1); } - if (!String.IsNullOrWhiteSpace(xlField.TotalsRowLabel)) + if (!XLHelper.IsNullOrWhiteSpace(xlField.TotalsRowLabel)) tableColumn1.TotalsRowLabel = xlField.TotalsRowLabel; } tableColumns1.AppendChild(tableColumn1); @@ -1924,7 +1924,7 @@ var workbookCacheRelId = pt.WorkbookCacheRelId; PivotCache pivotCache; PivotTableCacheDefinitionPart pivotTableCacheDefinitionPart; - if (!String.IsNullOrWhiteSpace(pt.WorkbookCacheRelId)) + if (!XLHelper.IsNullOrWhiteSpace(pt.WorkbookCacheRelId)) { pivotCache = pivotCaches.Cast().Single(pc => pc.Id.Value == pt.WorkbookCacheRelId); pivotTableCacheDefinitionPart = workbookPart.GetPartById(pt.WorkbookCacheRelId) as PivotTableCacheDefinitionPart; @@ -1938,18 +1938,18 @@ GeneratePivotTableCacheDefinitionPartContent(pivotTableCacheDefinitionPart, pt); - if (String.IsNullOrWhiteSpace(pt.WorkbookCacheRelId)) + if (XLHelper.IsNullOrWhiteSpace(pt.WorkbookCacheRelId)) pivotCaches.AppendChild(pivotCache); PivotTablePart pivotTablePart; - if (String.IsNullOrWhiteSpace(pt.RelId)) + if (XLHelper.IsNullOrWhiteSpace(pt.RelId)) pivotTablePart = worksheetPart.AddNewPart(context.RelIdGenerator.GetNext(RelType.Workbook)); else pivotTablePart = worksheetPart.GetPartById(pt.RelId) as PivotTablePart; GeneratePivotTablePartContent(pivotTablePart, pt, pivotCache.CacheId, context); - if (String.IsNullOrWhiteSpace(pt.RelId)) + if (XLHelper.IsNullOrWhiteSpace(pt.RelId)) pivotTablePart.AddPart(pivotTableCacheDefinitionPart, context.RelIdGenerator.GetNext(RelType.Workbook)); } } @@ -1983,7 +1983,11 @@ { var columnNumber = c.ColumnNumber(); var columnName = c.FirstCell().Value.ToString(); - var xlpf = pt.Fields.Add(columnName); + IXLPivotField xlpf; + if (pt.Fields.Any(f => f.SourceName == columnName)) + xlpf = pt.Fields.Single(f => f.SourceName == columnName); + else + xlpf = pt.Fields.Add(columnName); var field = pt.RowLabels.Union(pt.ColumnLabels).Union(pt.ReportFilters).FirstOrDefault(f => f.SourceName == columnName); @@ -2568,7 +2572,7 @@ StrokeWeight = String.Format(CultureInfo.InvariantCulture, "{0}pt", c.Comment.Style.ColorsAndLines.LineWeight), InsetMode = c.Comment.Style.Margins.Automatic ? InsetMarginValues.Auto : InsetMarginValues.Custom }; - if (!String.IsNullOrWhiteSpace(c.Comment.Style.Web.AlternateText)) + if (!XLHelper.IsNullOrWhiteSpace(c.Comment.Style.Web.AlternateText)) shape.Alternate = c.Comment.Style.Web.AlternateText; return shape; @@ -3125,7 +3129,7 @@ { var differentialFormat = new DifferentialFormat(); differentialFormat.Append(GetNewFont(new FontInfo { Font = cf.Style.Font as XLFont }, false)); - if (!String.IsNullOrWhiteSpace(cf.Style.NumberFormat.Format)) + if (!XLHelper.IsNullOrWhiteSpace(cf.Style.NumberFormat.Format)) { var numberFormat = new NumberingFormat { @@ -3769,7 +3773,7 @@ { var newXLNumberFormat = new XLNumberFormat(); - if (nf.FormatCode != null && !String.IsNullOrWhiteSpace(nf.FormatCode.Value)) + if (nf.FormatCode != null && !XLHelper.IsNullOrWhiteSpace(nf.FormatCode.Value)) newXLNumberFormat.Format = nf.FormatCode.Value; else if (nf.NumberFormatId != null) newXLNumberFormat.NumberFormatId = (Int32)nf.NumberFormatId.Value; @@ -4378,7 +4382,7 @@ var protection = xlWorksheet.Protection; sheetProtection.Sheet = protection.Protected; - if (!String.IsNullOrWhiteSpace(protection.PasswordHash)) + if (!XLHelper.IsNullOrWhiteSpace(protection.PasswordHash)) sheetProtection.Password = protection.PasswordHash; sheetProtection.FormatCells = GetBooleanValue(!protection.FormatCells, true); sheetProtection.FormatColumns = GetBooleanValue(!protection.FormatColumns, true); @@ -4579,7 +4583,7 @@ Display = hl.Cell.GetFormattedString() }; } - if (!String.IsNullOrWhiteSpace(hl.Tooltip)) + if (!XLHelper.IsNullOrWhiteSpace(hl.Tooltip)) hyperlink.Tooltip = hl.Tooltip; hyperlinks.AppendChild(hyperlink); } @@ -4836,7 +4840,7 @@ { worksheetPart.Worksheet.RemoveAllChildren(); { - if (!String.IsNullOrWhiteSpace(xlWorksheet.LegacyDrawingId)) + if (!XLHelper.IsNullOrWhiteSpace(xlWorksheet.LegacyDrawingId)) { var previousElement = cm.GetPreviousElementFor(XLWSContentManager.XLWSContents.LegacyDrawing); worksheetPart.Worksheet.InsertAfter(new LegacyDrawing { Id = xlWorksheet.LegacyDrawingId }, @@ -4916,7 +4920,7 @@ } else if (dataType == XLCellValues.DateTime || dataType == XLCellValues.Number) { - if (!String.IsNullOrWhiteSpace(xlCell.InnerText)) + if (!XLHelper.IsNullOrWhiteSpace(xlCell.InnerText)) { var cellValue = new CellValue(); cellValue.Text = Double.Parse(xlCell.InnerText, XLHelper.NumberStyle, XLHelper.ParseCulture).ToInvariantString(); diff --git a/ClosedXML/Excel/XLWorksheet.cs b/ClosedXML/Excel/XLWorksheet.cs index 0296632..9400d19 100644 --- a/ClosedXML/Excel/XLWorksheet.cs +++ b/ClosedXML/Excel/XLWorksheet.cs @@ -176,7 +176,7 @@ throw new ArgumentException("Worksheet names cannot contain any of the following characters: " + InvalidNameChars); - if (String.IsNullOrWhiteSpace(value)) + if (XLHelper.IsNullOrWhiteSpace(value)) throw new ArgumentException("Worksheet names cannot be empty"); if (value.Length > 31) @@ -658,7 +658,7 @@ private String ReplaceRelativeSheet(string newSheetName, String value) { - if (String.IsNullOrWhiteSpace(value)) return value; + if (XLHelper.IsNullOrWhiteSpace(value)) return value; var newValue = new StringBuilder(); var addresses = value.Split(','); diff --git a/ClosedXML/Excel/XLWorksheets.cs b/ClosedXML/Excel/XLWorksheets.cs index 9061e1d..8f68e66 100644 --- a/ClosedXML/Excel/XLWorksheets.cs +++ b/ClosedXML/Excel/XLWorksheets.cs @@ -137,7 +137,7 @@ "Can't delete the worksheet because there are multiple worksheets associated with that index."); var ws = _worksheets.Values.Single(w => w.Position == position); - if (!String.IsNullOrWhiteSpace(ws.RelId) && !Deleted.Contains(ws.RelId)) + if (!XLHelper.IsNullOrWhiteSpace(ws.RelId) && !Deleted.Contains(ws.RelId)) Deleted.Add(ws.RelId); _worksheets.RemoveAll(w => w.Position == position); @@ -178,7 +178,7 @@ public void Rename(String oldSheetName, String newSheetName) { - if (String.IsNullOrWhiteSpace(oldSheetName) || !_worksheets.ContainsKey(oldSheetName)) return; + if (XLHelper.IsNullOrWhiteSpace(oldSheetName) || !_worksheets.ContainsKey(oldSheetName)) return; if (!oldSheetName.Equals(newSheetName, StringComparison.OrdinalIgnoreCase) && _worksheets.Any(ws1 => ws1.Key.Equals(newSheetName, StringComparison.OrdinalIgnoreCase))) diff --git a/ClosedXML/Extensions.cs b/ClosedXML/Extensions.cs index 4be8ac5..bc42b67 100644 --- a/ClosedXML/Extensions.cs +++ b/ClosedXML/Extensions.cs @@ -210,7 +210,7 @@ { public static Double GetWidth(this IXLFontBase fontBase, String text, Dictionary fontCache) { - if (String.IsNullOrWhiteSpace(text)) + if (XLHelper.IsNullOrWhiteSpace(text)) return 0; var font = GetCachedFont(fontBase, fontCache); diff --git a/ClosedXML/Extensions/StreamExtensions.cs b/ClosedXML/Extensions/StreamExtensions.cs new file mode 100644 index 0000000..268a82e --- /dev/null +++ b/ClosedXML/Extensions/StreamExtensions.cs @@ -0,0 +1,20 @@ +#if _NET35_ +using System.IO; + +namespace ClosedXML.Extensions +{ + internal static class StreamExtensions + { + public static void CopyTo(this Stream input, Stream output) + { + byte[] buffer = new byte[16 * 1024]; // Fairly arbitrary size + int bytesRead; + + while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0) + { + output.Write(buffer, 0, bytesRead); + } + } + } +} +#endif diff --git a/ClosedXML/Extensions/StringExtensions.cs b/ClosedXML/Extensions/StringExtensions.cs index facf0a5..13adc8c 100644 --- a/ClosedXML/Extensions/StringExtensions.cs +++ b/ClosedXML/Extensions/StringExtensions.cs @@ -1,8 +1,5 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace ClosedXML.Extensions { @@ -33,6 +30,5 @@ hash ^= pLength; return hash.ToString("X"); } - } } diff --git a/ClosedXML/NetStandard/XLColorTranslator.cs b/ClosedXML/NetStandard/XLColorTranslator.cs index 257f909..c7683c6 100644 --- a/ClosedXML/NetStandard/XLColorTranslator.cs +++ b/ClosedXML/NetStandard/XLColorTranslator.cs @@ -1,5 +1,6 @@ #if _NETSTANDARD_ +using ClosedXML.Excel; using System; using System.Collections.Generic; using System.Drawing; @@ -190,7 +191,7 @@ throw new ArgumentException("Invalid HTML color: " + htmlColor); } } - if (String.IsNullOrWhiteSpace(m.Groups[1].Value)) + if (XLHelper.IsNullOrWhiteSpace(m.Groups[1].Value)) return Color.FromArgb( Convert.ToInt32(m.Groups[2].Value.PadRight(2, m.Groups[2].Value[0]), 16), Convert.ToInt32(m.Groups[3].Value.PadRight(2, m.Groups[3].Value[0]), 16), diff --git a/ClosedXML/XLHelper.cs b/ClosedXML/XLHelper.cs index 2efabeb..98bec54 100644 --- a/ClosedXML/XLHelper.cs +++ b/ClosedXML/XLHelper.cs @@ -122,7 +122,7 @@ public static bool IsValidColumn(string column) { var length = column.Length; - if (String.IsNullOrWhiteSpace(column) || length > 3) + if (XLHelper.IsNullOrWhiteSpace(column) || length > 3) return false; var theColumn = column.ToUpper(); @@ -158,7 +158,7 @@ public static bool IsValidA1Address(string address) { - if (String.IsNullOrWhiteSpace(address)) + if (XLHelper.IsNullOrWhiteSpace(address)) return false; address = address.Replace("$", ""); @@ -233,6 +233,16 @@ return rows; } + + public static bool IsNullOrWhiteSpace(string value) + { +#if _NET35_ + if (value == null) return true; + return value.All(c => char.IsWhiteSpace(c)); +#else + return String.IsNullOrWhiteSpace(value); +#endif + } private static readonly Regex A1RegexRelative = new Regex( @"(?<=\W)(?\$?[a-zA-Z]{1,3}\$?\d{1,7})(?=\W)" // A1 + @"|(?<=\W)(?\$?\d{1,7}:\$?\d{1,7})(?=\W)" // 1:1 diff --git a/ClosedXML_Examples/ClosedXML_Examples.csproj b/ClosedXML_Examples/ClosedXML_Examples.csproj index 6e5731d..0de4f7a 100644 --- a/ClosedXML_Examples/ClosedXML_Examples.csproj +++ b/ClosedXML_Examples/ClosedXML_Examples.csproj @@ -1,17 +1,18 @@  - netstandard2.0;net40;net461 - - - - $(DefineConstants);_NETSTANDARD_;_NETSTANDARD1_6_ + netstandard2.0;net35;net40;net461 + Exe $(DefineConstants);_NETSTANDARD_;_NETSTANDARD2_0_ + + $(DefineConstants);_NETFRAMEWORK_;_NET35_ + + $(DefineConstants);_NETFRAMEWORK_;_NET40_ @@ -29,6 +30,12 @@ + + + + + + diff --git a/ClosedXML_Examples/Creating/CreateFiles.cs b/ClosedXML_Examples/Creating/CreateFiles.cs index 1e639dd..a93aec3 100644 --- a/ClosedXML_Examples/Creating/CreateFiles.cs +++ b/ClosedXML_Examples/Creating/CreateFiles.cs @@ -86,7 +86,7 @@ new ShiftingFormulas().Create(Path.Combine(path, "ShiftingFormulas.xlsx")); new CopyingRowsAndColumns().Create(Path.Combine(path, "CopyingRowsAndColumns.xlsx")); new UsingRichText().Create(Path.Combine(path, "UsingRichText.xlsx")); - new UsingPhonetics().Create(Path.Combine(path, "UsingPhonetics.xlsx")); + //new UsingPhonetics().Create(Path.Combine(path, "UsingPhonetics.xlsx")); new WalkingRanges().Create(Path.Combine(path, "CellMoves.xlsx")); new AddingComments().Create(Path.Combine(path, "AddingComments.xlsx")); new PivotTables().Create(Path.Combine(path, "PivotTables.xlsx")); diff --git a/ClosedXML_Tests/ClosedXML_Tests.csproj b/ClosedXML_Tests/ClosedXML_Tests.csproj index 712748b..e6e321b 100644 --- a/ClosedXML_Tests/ClosedXML_Tests.csproj +++ b/ClosedXML_Tests/ClosedXML_Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.0;net40;net452;net461 + netcoreapp2.0;net40;net461 false @@ -9,20 +9,16 @@ $(AppVeyor) - - $(DefineConstants);_NETSTANDARD_;_NETSTANDARD1_6_ - - $(DefineConstants);_NETSTANDARD_;_netcoreapp2_0_ - - $(DefineConstants);_NETFRAMEWORK_;_NET40_ + + $(DefineConstants);_NETFRAMEWORK_;_NET35_ - - $(DefineConstants);_NETFRAMEWORK_;_NET452_ + + $(DefineConstants);_NETFRAMEWORK_;_NET40_ @@ -35,7 +31,7 @@ - + @@ -52,11 +48,11 @@ - + - + diff --git a/ClosedXML_Tests/Excel/Columns/ColumnTests.cs b/ClosedXML_Tests/Excel/Columns/ColumnTests.cs index 5410863..4d634ad 100644 --- a/ClosedXML_Tests/Excel/Columns/ColumnTests.cs +++ b/ClosedXML_Tests/Excel/Columns/ColumnTests.cs @@ -3,6 +3,7 @@ using System.Linq; using ClosedXML.Excel; using NUnit.Framework; +using ClosedXML_Tests.Utils; namespace ClosedXML_Tests.Excel { @@ -107,7 +108,7 @@ IXLColumn column3 = ws.Column(3); IXLColumn columnIns = ws.Column(2).InsertColumnsBefore(1).First(); - string outputPath = Path.Combine(TestHelper.TestsOutputDirectory, "ForTesting", "Sandbox.xlsx"); + string outputPath = PathHelper.Combine(TestHelper.TestsOutputDirectory, "ForTesting", "Sandbox.xlsx"); wb.SaveAs(outputPath, true); Assert.AreEqual(XLColor.Red, ws.Column(1).Cell(1).Style.Fill.BackgroundColor); diff --git a/ClosedXML_Tests/Excel/Comments/CommentsTests.cs b/ClosedXML_Tests/Excel/Comments/CommentsTests.cs index 1ba4e76..34b8382 100644 --- a/ClosedXML_Tests/Excel/Comments/CommentsTests.cs +++ b/ClosedXML_Tests/Excel/Comments/CommentsTests.cs @@ -1,10 +1,6 @@ using ClosedXML.Excel; using NUnit.Framework; -using System; -using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace ClosedXML_Tests.Excel.Comments { @@ -23,11 +19,9 @@ Assert.AreEqual(XLColorType.Indexed, xlColor.ColorType); Assert.AreEqual(81, xlColor.Indexed); - var color = xlColor.Color.ToHex(); Assert.AreEqual("FF000000", color); } - } } } diff --git a/ClosedXML_Tests/Excel/ImageHandling/PictureTests.cs b/ClosedXML_Tests/Excel/ImageHandling/PictureTests.cs index b076390..16e609b 100644 --- a/ClosedXML_Tests/Excel/ImageHandling/PictureTests.cs +++ b/ClosedXML_Tests/Excel/ImageHandling/PictureTests.cs @@ -1,5 +1,6 @@ using ClosedXML.Excel; using ClosedXML.Excel.Drawings; +using ClosedXML_Tests.Utils; using NUnit.Framework; using System; using System.Drawing; diff --git a/ClosedXML_Tests/OpenXMLTests.cs b/ClosedXML_Tests/OpenXMLTests.cs index 4780881..787e170 100644 --- a/ClosedXML_Tests/OpenXMLTests.cs +++ b/ClosedXML_Tests/OpenXMLTests.cs @@ -2,6 +2,7 @@ using ClosedXML_Examples; using DocumentFormat.OpenXml.Packaging; using NUnit.Framework; +using ClosedXML_Tests.Utils; namespace ClosedXML_Tests { diff --git a/ClosedXML_Tests/TestHelper.cs b/ClosedXML_Tests/TestHelper.cs index 7425752..2620be4 100644 --- a/ClosedXML_Tests/TestHelper.cs +++ b/ClosedXML_Tests/TestHelper.cs @@ -1,5 +1,6 @@ using ClosedXML.Excel; using ClosedXML_Examples; +using ClosedXML_Tests.Utils; using NUnit.Framework; using System; using System.Collections.Generic; @@ -35,7 +36,7 @@ public static void SaveWorkbook(XLWorkbook workbook, params string[] fileNameParts) { - workbook.SaveAs(Path.Combine(new string[] { TestsOutputDirectory }.Concat(fileNameParts).ToArray()), true); + workbook.SaveAs(PathHelper.Combine(new string[] { TestsOutputDirectory }.Concat(fileNameParts).ToArray()), true); } // Because different fonts are installed on Unix, @@ -59,7 +60,7 @@ var example = new T(); string[] pathParts = filePartName.Split(new char[] { '\\' }); - string filePath1 = Path.Combine(new List() { TestsExampleOutputDirectory }.Concat(pathParts).ToArray()); + string filePath1 = PathHelper.Combine(new List() { TestsExampleOutputDirectory }.Concat(pathParts).ToArray()); var extension = Path.GetExtension(filePath1); var directory = Path.GetDirectoryName(filePath1); diff --git a/ClosedXML_Tests/Utils/PackageHelper.cs b/ClosedXML_Tests/Utils/PackageHelper.cs index cb4bd3f..3d20488 100644 --- a/ClosedXML_Tests/Utils/PackageHelper.cs +++ b/ClosedXML_Tests/Utils/PackageHelper.cs @@ -1,3 +1,4 @@ +using ClosedXML_Tests.Utils; using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/ClosedXML_Tests/Utils/PathHelper.cs b/ClosedXML_Tests/Utils/PathHelper.cs new file mode 100644 index 0000000..7dbd610 --- /dev/null +++ b/ClosedXML_Tests/Utils/PathHelper.cs @@ -0,0 +1,22 @@ +using System; +using System.IO; +using System.Linq; + +namespace ClosedXML_Tests.Utils +{ + public static class PathHelper + { + public static string Combine(params string[] paths) + { +#if _NET35_ + if (paths == null) + { + throw new ArgumentNullException("paths"); + } + return paths.Aggregate(Path.Combine); +#else + return Path.Combine(paths); +#endif + } + } +} diff --git a/ClosedXML_Tests/Utils/StreamExtensions.cs b/ClosedXML_Tests/Utils/StreamExtensions.cs new file mode 100644 index 0000000..dd905c6 --- /dev/null +++ b/ClosedXML_Tests/Utils/StreamExtensions.cs @@ -0,0 +1,20 @@ +#if _NET35_ +using System.IO; + +namespace ClosedXML_Tests.Utils +{ + internal static class StreamExtensions + { + public static void CopyTo(this Stream input, Stream output) + { + byte[] buffer = new byte[16 * 1024]; // Fairly arbitrary size + int bytesRead; + + while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0) + { + output.Write(buffer, 0, bytesRead); + } + } + } +} +#endif diff --git a/appveyor.yml b/appveyor.yml index b81994f..2c5a1e6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -29,7 +29,6 @@ assemblies: - ClosedXML_Tests/bin/Release/netcoreapp2.0/ClosedXML_Tests.dll - ClosedXML_Tests/bin/Release/net40/ClosedXML_Tests.dll - - ClosedXML_Tests/bin/Release/net452/ClosedXML_Tests.dll - ClosedXML_Tests/bin/Release/net461/ClosedXML_Tests.dll @@ -41,5 +40,6 @@ artifacts: - path: ClosedXML/bin/Release/netstandard2.0/ClosedXML.dll + - path: ClosedXML/bin/Release/net35/ClosedXML.dll - path: ClosedXML/bin/Release/net40/ClosedXML.dll - path: ClosedXML/bin/Release/net461/ClosedXML.dll