diff --git a/ClosedXML/ClosedXML/ClosedXML/..svnbridge/.svnbridge b/ClosedXML/ClosedXML/ClosedXML/..svnbridge/.svnbridge index bdf168c..ee46f87 100644 --- a/ClosedXML/ClosedXML/ClosedXML/..svnbridge/.svnbridge +++ b/ClosedXML/ClosedXML/ClosedXML/..svnbridge/.svnbridge @@ -1,3 +1,6 @@ svn:ignorebin obj +svn:ignorebin +obj +*.ReSharper \ No newline at end of file diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell.cs index db7739e..8ebc81d 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell.cs @@ -1339,28 +1339,29 @@ _cellValue = source._cellValue; _dataType = source._dataType; FormulaR1C1 = source.FormulaR1C1; - _richText = new XLRichText(source._richText, source.Style.Font); + _richText = source._richText != null ? new XLRichText(source._richText, source.Style.Font) : null; } public IXLCell CopyFrom(XLCell otherCell) { - var source = otherCell; - _cellValue = source._cellValue; - _richText = new XLRichText(source._richText, source.Style.Font); - _dataType = source._dataType; - FormulaR1C1 = source.FormulaR1C1; - m_style = new XLStyle(this, source.m_style); - - if (source._hyperlink != null) + _cellValue = otherCell._cellValue; + _dataType = otherCell._dataType; + FormulaR1C1 = otherCell.FormulaR1C1; + m_style = new XLStyle(this, otherCell.m_style); + if (otherCell._richText != null) + { + _richText = new XLRichText(otherCell._richText, otherCell.Style.Font); + } + if (otherCell._hyperlink != null) { SettingHyperlink = true; - Hyperlink = new XLHyperlink(source.Hyperlink); + Hyperlink = new XLHyperlink(otherCell.Hyperlink); SettingHyperlink = false; } - var asRange = source.AsRange(); - if (source.Worksheet.DataValidations.Any(dv => dv.Ranges.Contains(asRange))) - (DataValidation as XLDataValidation).CopyFrom(source.DataValidation); + var asRange = otherCell.AsRange(); + if (otherCell.Worksheet.DataValidations.Any(dv => dv.Ranges.Contains(asRange))) + (DataValidation as XLDataValidation).CopyFrom(otherCell.DataValidation); return this; } diff --git a/ClosedXML/ClosedXML/ClosedXML_Tests/Excel/Misc/CopyContentsTest.cs b/ClosedXML/ClosedXML/ClosedXML_Tests/Excel/Misc/CopyContentsTest.cs index 3f37d9e..878234e 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Tests/Excel/Misc/CopyContentsTest.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Tests/Excel/Misc/CopyContentsTest.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Text; using System.Collections.Generic; using System.Linq; @@ -41,6 +42,37 @@ TestHelper.SaveWorkbook(workbook, "CopyRowContents.xlsx"); } + [TestMethod] + public void TestDefaultRowHeight() + { + var workbook = new XLWorkbook(Path.Combine(TestHelper.TestsOutputDirectory, "TestDefaultRowHeight.xlsx")); + + var originalSheet = workbook.Worksheets.Add("original"); + var copyRowSheet = workbook.Worksheets.Add("copy row"); + var copyRowAsRangeSheet = workbook.Worksheets.Add("copy row as range"); + var copyRangeSheet = workbook.Worksheets.Add("copy range"); + + originalSheet.Cell("A2").SetValue("test value"); + originalSheet.Range("A2:E2").Merge(); + + { + var originalRange = originalSheet.Range("A2:E2"); + var destinationRange = copyRangeSheet.Range("A2:E2"); + + originalRange.CopyTo(destinationRange); + } + CopyRowAsRange(originalSheet, 2, copyRowAsRangeSheet, 3); + { + var originalRow = originalSheet.Row(2); + var destinationRow = copyRowSheet.Row(2); + copyRowSheet.Cell("G2").Value = "must be removed after copy"; + originalRow.CopyTo(destinationRow); + } + + TestHelper.SaveWorkbook(workbook, "TestDefaultRowHeight_SavedByClosedXML.xlsx"); + + } + private static void CopyRowAsRange(IXLWorksheet originalSheet, int originalRowNumber, IXLWorksheet destSheet, int destRowNumber) { {