diff --git a/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj b/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj index 399eafc..48bee04 100644 --- a/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj +++ b/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj @@ -128,9 +128,11 @@ - + + + - + diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/IXLCell.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/IXLCell.cs index 4fd603b..1f2caba 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/IXLCell.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/IXLCell.cs @@ -238,6 +238,8 @@ IXLRichText RichText { get; } Boolean HasRichText { get; } + IXLComment Comment { get; } + Boolean HasComment { get; } Boolean IsMerged(); Boolean IsEmpty(); diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell.cs index 63972fc..491311e 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell.cs @@ -64,6 +64,7 @@ internal XLCellValues _dataType; private XLHyperlink _hyperlink; private XLRichText _richText; + private XLComment _comment; #endregion @@ -694,6 +695,7 @@ { Hyperlink = null; _richText = null; + _comment = null; _cellValue = String.Empty; FormulaA1 = String.Empty; } @@ -875,6 +877,25 @@ get { return _richText != null; } } + public IXLComment Comment + { + get + { + if (_comment == null) + { + var style = GetStyleForRead(); + _comment = new XLComment(style.Font); + } + + return _comment; + } + } + + public bool HasComment + { + get { return _comment != null; } + } + public Boolean IsMerged() { return Worksheet.Internals.MergedRanges.Any(AsRange().Intersects); @@ -966,6 +987,17 @@ return true; } + private bool SetComment(object value) + { + var asComment = value as XLComment; + + if (asComment == null) + return false; + + _comment = asComment; + return true; + } + private Boolean SetRange(Object rangeObject) { var asRange = rangeObject as XLRangeBase; @@ -1339,6 +1371,7 @@ _dataType = source._dataType; FormulaR1C1 = source.FormulaR1C1; _richText = source._richText == null ? null : new XLRichText(source._richText, source.Style.Font); + _comment = source._comment == null ? null : new XLComment(source._comment, source.Style.Font); } public IXLCell CopyFrom(XLCell otherCell) @@ -1346,6 +1379,7 @@ 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(source._comment, source.Style.Font); _dataType = source._dataType; FormulaR1C1 = source.FormulaR1C1; diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Charts/IXLDrawing.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Charts/IXLDrawing.cs deleted file mode 100644 index 9220794..0000000 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Charts/IXLDrawing.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; - -namespace ClosedXML.Excel -{ - public enum XLDrawingAnchor { MoveAndSizeWithCells, MoveWithCells, Absolute} - public interface IXLDrawing - { - Int32 Id { get; } - - Boolean Hidden { get; set; } - T SetHidden(); - T SetHidden(Boolean hidden); - - String Name { get; set; } - T SetName(String name); - - String Description { get; set; } - T SetDescription(String description); - - XLDrawingAnchor Anchor { get; set; } - - Int32 FirstColumn { get; set; } - T SetFirstColumn(Int32 firstColumn); - Int32 FirstColumnOffset { get; set; } - T SetFirstColumnOffset(Int32 firstColumnOffset); - Int32 FirstRow { get; set; } - T SetFirstRow(Int32 firstRow); - Int32 FirstRowOffset { get; set; } - T SetFirstRowOffset(Int32 firstRowOffset); - - Int32 LastColumn { get; set; } - T SetLastColumn(Int32 firstColumn); - Int32 LastColumnOffset { get; set; } - T SetLastColumnOffset(Int32 firstColumn); - Int32 LastRow { get; set; } - T SetLastRow(Int32 firstRow); - Int32 LastRowOffset { get; set; } - T SetLastRowOffset(Int32 firstRowOffset); - - Int32 ZOrder { get; set; } - T SetZOrder(Int32 zOrder); - - Boolean HorizontalFlip { get; set; } - T SetHorizontalFlip(); - T SetHorizontalFlip(Boolean horizontalFlip); - - Boolean VerticalFlip { get; set; } - T SetVerticalFlip(); - T SetVerticalFlip(Boolean verticalFlip); - - Int32 Rotation { get; set; } - T SetRotation(Int32 rotation); - - Int32 OffsetX { get; set; } - T SetOffsetX(Int32 offsetX); - - Int32 OffsetY { get; set; } - T SetOffsetY(Int32 offsetY); - - Int32 ExtentLength { get; set; } - T SetExtentLength(Int32 ExtentLength); - - Int32 ExtentWidth { get; set; } - T SetExtentWidth(Int32 extentWidth); - } -} diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Charts/XLDrawing.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Charts/XLDrawing.cs deleted file mode 100644 index 96ae86c..0000000 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Charts/XLDrawing.cs +++ /dev/null @@ -1,159 +0,0 @@ -using System; - -namespace ClosedXML.Excel -{ - internal class XLDrawing: IXLDrawing - { - internal T Container; - public XLDrawing() - { - Anchor = XLDrawingAnchor.MoveAndSizeWithCells; - } - - public Int32 Id { get; internal set; } - - public Boolean Hidden { get; set; } - public T SetHidden() - { - Hidden = true; - return Container; - } - public T SetHidden(Boolean hidden) - { - Hidden = hidden; - return Container; - } - - public String Name { get; set; } - public T SetName(String name) - { - Name = name; - return Container; - } - - public String Description { get; set; } - public T SetDescription(String description) - { - Description = description; - return Container; - } - - public XLDrawingAnchor Anchor { get; set; } - - public Int32 FirstColumn { get; set; } - public T SetFirstColumn(Int32 firstColumn) - { - FirstColumn = firstColumn; - return Container; - } - public Int32 FirstColumnOffset { get; set; } - public T SetFirstColumnOffset(Int32 firstColumnOffset) - { - FirstColumnOffset = firstColumnOffset; - return Container; - } - public Int32 FirstRow { get; set; } - public T SetFirstRow(Int32 firstRow) - { - FirstRow = firstRow; - return Container; - } - public Int32 FirstRowOffset { get; set; } - public T SetFirstRowOffset(Int32 firstRowOffset) - { - FirstRowOffset = firstRowOffset; - return Container; - } - - public Int32 LastColumn { get; set; } - public T SetLastColumn(Int32 firstColumn) - { - LastColumn = firstColumn; - return Container; - } - public Int32 LastColumnOffset { get; set; } - public T SetLastColumnOffset(Int32 firstColumnOffset) - { - LastColumnOffset = firstColumnOffset; - return Container; - } - public Int32 LastRow { get; set; } - public T SetLastRow(Int32 firstRow) - { - LastRow = firstRow; - return Container; - } - public Int32 LastRowOffset { get; set; } - public T SetLastRowOffset(Int32 firstRowOffset) - { - LastRowOffset = firstRowOffset; - return Container; - } - - public Int32 ZOrder { get; set; } - public T SetZOrder(Int32 zOrder) - { - ZOrder = zOrder; - return Container; - } - - public Boolean HorizontalFlip { get; set; } - public T SetHorizontalFlip() - { - HorizontalFlip = true; - return Container; - } - public T SetHorizontalFlip(Boolean horizontalFlip) - { - HorizontalFlip = horizontalFlip; - return Container; - } - - public Boolean VerticalFlip { get; set; } - public T SetVerticalFlip() - { - VerticalFlip = true; - return Container; - } - public T SetVerticalFlip(Boolean verticalFlip) - { - VerticalFlip = verticalFlip; - return Container; - } - - public Int32 Rotation { get; set; } - public T SetRotation(Int32 rotation) - { - Rotation = rotation; - return Container; - } - - public Int32 OffsetX { get; set; } - public T SetOffsetX(Int32 offsetX) - { - OffsetX = offsetX; - return Container; - } - - public Int32 OffsetY { get; set; } - public T SetOffsetY(Int32 offsetY) - { - OffsetY = offsetY; - return Container; - } - - public Int32 ExtentLength { get; set; } - public T SetExtentLength(Int32 extentLength) - { - ExtentLength = extentLength; - return Container; - } - - public Int32 ExtentWidth { get; set; } - public T SetExtentWidth(Int32 extentWidth) - { - ExtentWidth = extentWidth; - return Container; - } - } -} diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Comments/IXLComment.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Comments/IXLComment.cs new file mode 100644 index 0000000..773a0a4 --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Comments/IXLComment.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; + +namespace ClosedXML.Excel +{ + public interface IXLComment: IXLDrawing, IEnumerable, IEquatable + { + Boolean Bold { set; } + Boolean Italic { set; } + XLFontUnderlineValues Underline { set; } + Boolean Strikethrough { set; } + XLFontVerticalTextAlignmentValues VerticalAlignment { set; } + Boolean Shadow { set; } + Double FontSize { set; } + IXLColor FontColor { set; } + String FontName { set; } + XLFontFamilyNumberingValues FontFamilyNumbering { set; } + + IXLComment SetBold(); IXLComment SetBold(Boolean value); + IXLComment SetItalic(); IXLComment SetItalic(Boolean value); + IXLComment SetUnderline(); IXLComment SetUnderline(XLFontUnderlineValues value); + IXLComment SetStrikethrough(); IXLComment SetStrikethrough(Boolean value); + IXLComment SetVerticalAlignment(XLFontVerticalTextAlignmentValues value); + IXLComment SetShadow(); IXLComment SetShadow(Boolean value); + IXLComment SetFontSize(Double value); + IXLComment SetFontColor(IXLColor value); + IXLComment SetFontName(String value); + IXLComment SetFontFamilyNumbering(XLFontFamilyNumberingValues value); + + IXLRichString AddText(String text); + IXLRichString AddText(String text, IXLFontBase font); + IXLComment ClearText(); + IXLComment ClearFont(); + IXLComment Substring(Int32 index); + IXLComment Substring(Int32 index, Int32 length); + Int32 Count { get; } + Int32 Length { get; } + + String Text { get; } + IXLPhonetics Phonetics { get; } + Boolean HasPhonetics { get; } + } +} diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Comments/XLComment.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Comments/XLComment.cs new file mode 100644 index 0000000..ee929cf --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Comments/XLComment.cs @@ -0,0 +1,185 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ClosedXML.Excel +{ + internal class XLComment: XLDrawing, IXLComment + { + List _richTexts = new List(); + + readonly IXLFontBase _defaultFont; + public XLComment(IXLFontBase defaultFont) + { + Length = 0; + _defaultFont = defaultFont; + Container = this; + } + + public XLComment(IXLComment defaultComment, IXLFontBase defaultFont) + :this(defaultFont) + { + foreach (var rt in defaultComment) + AddText(rt.Text, rt); + if (defaultComment.HasPhonetics) + { + _phonetics = new XLPhonetics(defaultComment.Phonetics, defaultFont); + } + + } + + public XLComment(String text, IXLFontBase defaultFont) + :this(defaultFont) + { + AddText(text); + } + + public Int32 Count { get { return _richTexts.Count; } } + public int Length { get; private set; } + + public IXLRichString AddText(String text) + { + return AddText(text, _defaultFont); + } + public IXLRichString AddText(String text, IXLFontBase font) + { + var richText = new XLRichString(text, font); + return AddText(richText); + } + + public IXLRichString AddText(IXLRichString richText) + { + _richTexts.Add(richText); + Length += richText.Text.Length; + return richText; + } + public IXLComment ClearText() + { + _richTexts.Clear(); + Length = 0; + return Container; + } + public IXLComment ClearFont() + { + String text = Text; + ClearText(); + AddText(text); + return Container; + } + + public override string ToString() + { + var sb = new StringBuilder(_richTexts.Count); + _richTexts.ForEach(rt => sb.Append(rt.Text)); + return sb.ToString(); + } + + public IXLComment Substring(Int32 index) + { + return Substring(index, Length - index); + } + public IXLComment Substring(Int32 index, Int32 length) + { + if (index + 1 > Length || (Length - index + 1) < length || length <= 0) + throw new IndexOutOfRangeException("Index and length must refer to a location within the string."); + + List newRichTexts = new List(); + XLComment retVal = new XLComment(_defaultFont); + + Int32 lastPosition = 0; + foreach (var rt in _richTexts) + { + if (lastPosition >= index + 1 + length) // We already have what we need + { + newRichTexts.Add(rt); + } + else if (lastPosition + rt.Text.Length >= index + 1) // Eureka! + { + Int32 startIndex = index - lastPosition; + + if (startIndex > 0) + newRichTexts.Add(new XLRichString(rt.Text.Substring(0, startIndex), rt)); + else if (startIndex < 0) + startIndex = 0; + + Int32 leftToTake = length - retVal.Length; + if (leftToTake > rt.Text.Length - startIndex) + leftToTake = rt.Text.Length - startIndex; + + XLRichString newRt = new XLRichString(rt.Text.Substring(startIndex, leftToTake), rt); + newRichTexts.Add(newRt); + retVal.AddText(newRt); + + if (startIndex + leftToTake < rt.Text.Length) + newRichTexts.Add(new XLRichString(rt.Text.Substring(startIndex + leftToTake), rt)); + } + else // We haven't reached the desired position yet + { + newRichTexts.Add(rt); + } + lastPosition += rt.Text.Length; + } + _richTexts = newRichTexts; + return retVal; + } + + public IEnumerator GetEnumerator() + { + return _richTexts.GetEnumerator(); + } + + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public Boolean Bold { set { _richTexts.ForEach(rt => rt.Bold = value); } } + public Boolean Italic { set { _richTexts.ForEach(rt => rt.Italic = value); } } + public XLFontUnderlineValues Underline { set { _richTexts.ForEach(rt => rt.Underline = value); } } + public Boolean Strikethrough { set { _richTexts.ForEach(rt => rt.Strikethrough = value); } } + public XLFontVerticalTextAlignmentValues VerticalAlignment { set { _richTexts.ForEach(rt => rt.VerticalAlignment = value); } } + public Boolean Shadow { set { _richTexts.ForEach(rt => rt.Shadow = value); } } + public Double FontSize { set { _richTexts.ForEach(rt => rt.FontSize = value); } } + public IXLColor FontColor { set { _richTexts.ForEach(rt => rt.FontColor = value); } } + public String FontName { set { _richTexts.ForEach(rt => rt.FontName = value); } } + public XLFontFamilyNumberingValues FontFamilyNumbering { set { _richTexts.ForEach(rt => rt.FontFamilyNumbering = value); } } + + public IXLComment SetBold() { Bold = true; return Container; } public IXLComment SetBold(Boolean value) { Bold = value; return Container; } + public IXLComment SetItalic() { Italic = true; return Container; } public IXLComment SetItalic(Boolean value) { Italic = value; return Container; } + public IXLComment SetUnderline() { Underline = XLFontUnderlineValues.Single; return Container; } public IXLComment SetUnderline(XLFontUnderlineValues value) { Underline = value; return Container; } + public IXLComment SetStrikethrough() { Strikethrough = true; return Container; } public IXLComment SetStrikethrough(Boolean value) { Strikethrough = value; return Container; } + public IXLComment SetVerticalAlignment(XLFontVerticalTextAlignmentValues value) { VerticalAlignment = value; return Container; } + public IXLComment SetShadow() { Shadow = true; return Container; } public IXLComment SetShadow(Boolean value) { Shadow = value; return Container; } + public IXLComment SetFontSize(Double value) { FontSize = value; return Container; } + public IXLComment SetFontColor(IXLColor value) { FontColor = value; return Container; } + public IXLComment SetFontName(String value) { FontName = value; return Container; } + public IXLComment SetFontFamilyNumbering(XLFontFamilyNumberingValues value) { FontFamilyNumbering = value; return Container; } + + public bool Equals(IXLComment other) + { + Int32 count = Count; + if (count != other.Count) + return false; + + for (Int32 i = 0; i < count; i++) + { + if (_richTexts.ElementAt(i) != other.ElementAt(i)) + return false; + } + + return _phonetics == null || Phonetics.Equals(other.Phonetics); + } + + public String Text { get { return ToString(); } } + + private IXLPhonetics _phonetics; + public IXLPhonetics Phonetics + { + get { return _phonetics ?? (_phonetics = new XLPhonetics(_defaultFont)); } + } + + public Boolean HasPhonetics { get { return _phonetics != null; } } + } + +} diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/IXLDrawing.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/IXLDrawing.cs new file mode 100644 index 0000000..9220794 --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/IXLDrawing.cs @@ -0,0 +1,66 @@ +using System; + +namespace ClosedXML.Excel +{ + public enum XLDrawingAnchor { MoveAndSizeWithCells, MoveWithCells, Absolute} + public interface IXLDrawing + { + Int32 Id { get; } + + Boolean Hidden { get; set; } + T SetHidden(); + T SetHidden(Boolean hidden); + + String Name { get; set; } + T SetName(String name); + + String Description { get; set; } + T SetDescription(String description); + + XLDrawingAnchor Anchor { get; set; } + + Int32 FirstColumn { get; set; } + T SetFirstColumn(Int32 firstColumn); + Int32 FirstColumnOffset { get; set; } + T SetFirstColumnOffset(Int32 firstColumnOffset); + Int32 FirstRow { get; set; } + T SetFirstRow(Int32 firstRow); + Int32 FirstRowOffset { get; set; } + T SetFirstRowOffset(Int32 firstRowOffset); + + Int32 LastColumn { get; set; } + T SetLastColumn(Int32 firstColumn); + Int32 LastColumnOffset { get; set; } + T SetLastColumnOffset(Int32 firstColumn); + Int32 LastRow { get; set; } + T SetLastRow(Int32 firstRow); + Int32 LastRowOffset { get; set; } + T SetLastRowOffset(Int32 firstRowOffset); + + Int32 ZOrder { get; set; } + T SetZOrder(Int32 zOrder); + + Boolean HorizontalFlip { get; set; } + T SetHorizontalFlip(); + T SetHorizontalFlip(Boolean horizontalFlip); + + Boolean VerticalFlip { get; set; } + T SetVerticalFlip(); + T SetVerticalFlip(Boolean verticalFlip); + + Int32 Rotation { get; set; } + T SetRotation(Int32 rotation); + + Int32 OffsetX { get; set; } + T SetOffsetX(Int32 offsetX); + + Int32 OffsetY { get; set; } + T SetOffsetY(Int32 offsetY); + + Int32 ExtentLength { get; set; } + T SetExtentLength(Int32 ExtentLength); + + Int32 ExtentWidth { get; set; } + T SetExtentWidth(Int32 extentWidth); + } +} diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/XLDrawing.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/XLDrawing.cs new file mode 100644 index 0000000..96ae86c --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/XLDrawing.cs @@ -0,0 +1,159 @@ +using System; + +namespace ClosedXML.Excel +{ + internal class XLDrawing: IXLDrawing + { + internal T Container; + public XLDrawing() + { + Anchor = XLDrawingAnchor.MoveAndSizeWithCells; + } + + public Int32 Id { get; internal set; } + + public Boolean Hidden { get; set; } + public T SetHidden() + { + Hidden = true; + return Container; + } + public T SetHidden(Boolean hidden) + { + Hidden = hidden; + return Container; + } + + public String Name { get; set; } + public T SetName(String name) + { + Name = name; + return Container; + } + + public String Description { get; set; } + public T SetDescription(String description) + { + Description = description; + return Container; + } + + public XLDrawingAnchor Anchor { get; set; } + + public Int32 FirstColumn { get; set; } + public T SetFirstColumn(Int32 firstColumn) + { + FirstColumn = firstColumn; + return Container; + } + public Int32 FirstColumnOffset { get; set; } + public T SetFirstColumnOffset(Int32 firstColumnOffset) + { + FirstColumnOffset = firstColumnOffset; + return Container; + } + public Int32 FirstRow { get; set; } + public T SetFirstRow(Int32 firstRow) + { + FirstRow = firstRow; + return Container; + } + public Int32 FirstRowOffset { get; set; } + public T SetFirstRowOffset(Int32 firstRowOffset) + { + FirstRowOffset = firstRowOffset; + return Container; + } + + public Int32 LastColumn { get; set; } + public T SetLastColumn(Int32 firstColumn) + { + LastColumn = firstColumn; + return Container; + } + public Int32 LastColumnOffset { get; set; } + public T SetLastColumnOffset(Int32 firstColumnOffset) + { + LastColumnOffset = firstColumnOffset; + return Container; + } + public Int32 LastRow { get; set; } + public T SetLastRow(Int32 firstRow) + { + LastRow = firstRow; + return Container; + } + public Int32 LastRowOffset { get; set; } + public T SetLastRowOffset(Int32 firstRowOffset) + { + LastRowOffset = firstRowOffset; + return Container; + } + + public Int32 ZOrder { get; set; } + public T SetZOrder(Int32 zOrder) + { + ZOrder = zOrder; + return Container; + } + + public Boolean HorizontalFlip { get; set; } + public T SetHorizontalFlip() + { + HorizontalFlip = true; + return Container; + } + public T SetHorizontalFlip(Boolean horizontalFlip) + { + HorizontalFlip = horizontalFlip; + return Container; + } + + public Boolean VerticalFlip { get; set; } + public T SetVerticalFlip() + { + VerticalFlip = true; + return Container; + } + public T SetVerticalFlip(Boolean verticalFlip) + { + VerticalFlip = verticalFlip; + return Container; + } + + public Int32 Rotation { get; set; } + public T SetRotation(Int32 rotation) + { + Rotation = rotation; + return Container; + } + + public Int32 OffsetX { get; set; } + public T SetOffsetX(Int32 offsetX) + { + OffsetX = offsetX; + return Container; + } + + public Int32 OffsetY { get; set; } + public T SetOffsetY(Int32 offsetY) + { + OffsetY = offsetY; + return Container; + } + + public Int32 ExtentLength { get; set; } + public T SetExtentLength(Int32 extentLength) + { + ExtentLength = extentLength; + return Container; + } + + public Int32 ExtentWidth { get; set; } + public T SetExtentWidth(Int32 extentWidth) + { + ExtentWidth = extentWidth; + return Container; + } + } +} diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/PivotTables/IXLPivotTable.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/PivotTables/IXLPivotTable.cs index d5160b1..414f421 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/PivotTables/IXLPivotTable.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/PivotTables/IXLPivotTable.cs @@ -209,6 +209,5 @@ IXLPivotTable SetLayout(XLPivotLayout value); IXLPivotTable SetInsertBlankLines(); IXLPivotTable SetInsertBlankLines(Boolean value); - void SetExcelDefaults(); } } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/PivotTables/XLPivotTable.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/PivotTables/XLPivotTable.cs index 3f94fbd..940c4b9 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/PivotTables/XLPivotTable.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/PivotTables/XLPivotTable.cs @@ -15,6 +15,8 @@ RowLabels = new XLPivotFields(); Values = new XLPivotValues(); Theme = XLPivotTableTheme.PivotStyleLight16; + + SetExcelDefaults(); } public IXLCell TargetCell { get; set; } @@ -88,20 +90,20 @@ public IXLPivotTable SetInsertBlankLines() { InsertBlankLines = true; return this; } public IXLPivotTable SetInsertBlankLines(Boolean value) { InsertBlankLines = value; return this; } - public void SetExcelDefaults() + private void SetExcelDefaults() { - this.EmptyCellReplacement = String.Empty; - this.AutofitColumns = true; - this.PreserveCellFormatting = true; - this.ShowGrandTotalsColumns = true; - this.ShowGrandTotalsRows = true; - this.UseCustomListsForSorting = true; - this.ShowExpandCollapseButtons = true; - this.ShowContextualTooltips = true; - this.DisplayCaptionsAndDropdowns = true; - this.RepeatRowLabels = true; - this.SaveSourceData = true; - this.EnableShowDetails = true; + EmptyCellReplacement = String.Empty; + AutofitColumns = true; + PreserveCellFormatting = true; + ShowGrandTotalsColumns = true; + ShowGrandTotalsRows = true; + UseCustomListsForSorting = true; + ShowExpandCollapseButtons = true; + ShowContextualTooltips = true; + DisplayCaptionsAndDropdowns = true; + RepeatRowLabels = true; + SaveSourceData = true; + EnableShowDetails = true; } } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs index 27447d7..e238547 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs @@ -142,7 +142,7 @@ GenerateWorksheetPartContent(worksheetPart, worksheet, context); - //GeneratePivotTables(workbookPart, worksheetPart, worksheet, context); + GeneratePivotTables(workbookPart, worksheetPart, worksheet, context); //DrawingsPart drawingsPart = worksheetPart.AddNewPart("rId1"); //GenerateDrawingsPartContent(drawingsPart, worksheet); @@ -3796,7 +3796,7 @@ var pivotTablePart = worksheetPart.AddNewPart(context.RelIdGenerator.GetNext(RelType.Workbook)); GeneratePivotTablePartContent(pivotTablePart, pt); - pivotTablePart.AddPart(pivotTableCacheDefinitionPart, "rId1"); + pivotTablePart.AddPart(pivotTableCacheDefinitionPart, context.RelIdGenerator.GetNext(RelType.Workbook)); } } @@ -3832,7 +3832,7 @@ CacheField cacheField = new CacheField() { Name = fieldName }; SharedItems sharedItems; - if (fieldName == "Number") + if (fieldName == "Number") // TODO: Don't hard code value { sharedItems = new SharedItems() { ContainsSemiMixedTypes = false, ContainsString = false, ContainsNumber = true }; } @@ -3882,7 +3882,7 @@ { Name = pt.Name, CacheId = (UInt32Value)0U, - DataCaption = "Values", + DataCaption = "Values", // TODO: Don't hard code value MergeItem = pt.MergeAndCenterWithLabels, Indent = Convert.ToUInt32(pt.RowLabelIndent), PageOverThenDown = (pt.FilterAreaOrder == XLFilterAreaOrder.OverThenDown ? true : false), @@ -4023,7 +4023,7 @@ } pivotTableDefinition.Append(dataFields); - pivotTableDefinition.Append(new PivotTableStyle() { Name = "PivotStyleLight16", ShowRowHeaders = true, ShowColumnHeaders = true, ShowRowStripes = false, ShowColumnStripes = false, ShowLastColumn = true }); + pivotTableDefinition.Append(new PivotTableStyle() { Name = Enum.GetName(typeof(XLTableTheme), pt.Theme), ShowRowHeaders = pt.ShowRowHeaders, ShowColumnHeaders = pt.ShowColumnHeaders, ShowRowStripes = pt.ShowRowStripes, ShowColumnStripes = pt.ShowColumnStripes }); #region Excel 2010 Features diff --git a/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj b/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj index 090b3f1..231cf70 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj +++ b/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj @@ -145,18 +145,12 @@ Excel\Charts\IXLCharts.cs - - Excel\Charts\IXLDrawing.cs - Excel\Charts\XLChart.cs Excel\Charts\XLCharts.cs - - Excel\Charts\XLDrawing.cs - Excel\Columns\IXLColumn.cs @@ -175,6 +169,12 @@ Excel\Columns\XLColumns.cs + + Excel\Comments\IXLComment.cs + + + Excel\Comments\XLComment.cs + Excel\Coordinate\IXLAddress.cs @@ -232,6 +232,12 @@ Excel\DataValidation\XLWholeNumberCriteria.cs + + Excel\Drawings\IXLDrawing.cs + + + Excel\Drawings\XLDrawing.cs + Excel\EnumConverter.cs @@ -610,6 +616,7 @@ +