diff --git a/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj b/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj
index be87678..93b2e36 100644
--- a/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj
+++ b/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj
@@ -130,6 +130,8 @@
+
+
@@ -157,12 +159,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -290,6 +308,7 @@
+
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Comments/IXLComment.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Comments/IXLComment.cs
index 4d3b727..8d95448 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Comments/IXLComment.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Comments/IXLComment.cs
@@ -3,8 +3,14 @@
namespace ClosedXML.Excel
{
- public interface IXLComment : IXLFormattedText
+ public interface IXLComment : IXLFormattedText, IXLDrawing
{
+ String Author { get; set; }
+ IXLComment SetAuthor(String value);
+
+ Boolean Visible { get; set; }
+ IXLComment SetVisible(); IXLComment SetVisible(Boolean value);
+
}
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Comments/XLComment.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Comments/XLComment.cs
index e6e4ff6..971d8d0 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Comments/XLComment.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Comments/XLComment.cs
@@ -11,21 +11,188 @@
public XLComment(IXLFontBase defaultFont)
: base(defaultFont)
{
- Container = this;
+ Initialize();
}
public XLComment(XLFormattedText defaultComment, IXLFontBase defaultFont)
- : base(defaultComment, defaultFont)
+ : base(defaultComment, defaultFont)
{
- Container = this;
+ Initialize();
}
public XLComment(String text, IXLFontBase defaultFont)
: base(text, defaultFont)
{
- Container = this;
+ Initialize();
}
+ private void Initialize()
+ {
+ Container = this;
+ Anchor = XLDrawingAnchor.MoveAndSizeWithCells;
+ Style = new XLDrawingStyle();
+ }
+
+ public String Author { get; set; }
+ public IXLComment SetAuthor(String value)
+ {
+ Author = value;
+ return this;
+ }
+
+ public Boolean Visible { get; set; } public IXLComment SetVisible() { Visible = true; return this; } public IXLComment SetVisible(Boolean value) { Visible = value; return this; }
+
+ #region IXLDrawing
+
+ public Int32 Id { get; internal set; }
+
+ public Boolean Hidden { get; set; }
+ public IXLComment SetHidden()
+ {
+ Hidden = true;
+ return Container;
+ }
+ public IXLComment SetHidden(Boolean hidden)
+ {
+ Hidden = hidden;
+ return Container;
+ }
+
+ public String Name { get; set; }
+ public IXLComment SetName(String name)
+ {
+ Name = name;
+ return Container;
+ }
+
+ public String Description { get; set; }
+ public IXLComment SetDescription(String description)
+ {
+ Description = description;
+ return Container;
+ }
+
+ public XLDrawingAnchor Anchor { get; set; }
+
+ public Int32 FirstColumn { get; set; }
+ public IXLComment SetFirstColumn(Int32 firstColumn)
+ {
+ FirstColumn = firstColumn;
+ return Container;
+ }
+ public Int32 FirstColumnOffset { get; set; }
+ public IXLComment SetFirstColumnOffset(Int32 firstColumnOffset)
+ {
+ FirstColumnOffset = firstColumnOffset;
+ return Container;
+ }
+ public Int32 FirstRow { get; set; }
+ public IXLComment SetFirstRow(Int32 firstRow)
+ {
+ FirstRow = firstRow;
+ return Container;
+ }
+ public Int32 FirstRowOffset { get; set; }
+ public IXLComment SetFirstRowOffset(Int32 firstRowOffset)
+ {
+ FirstRowOffset = firstRowOffset;
+ return Container;
+ }
+
+ public Int32 LastColumn { get; set; }
+ public IXLComment SetLastColumn(Int32 firstColumn)
+ {
+ LastColumn = firstColumn;
+ return Container;
+ }
+ public Int32 LastColumnOffset { get; set; }
+ public IXLComment SetLastColumnOffset(Int32 firstColumnOffset)
+ {
+ LastColumnOffset = firstColumnOffset;
+ return Container;
+ }
+ public Int32 LastRow { get; set; }
+ public IXLComment SetLastRow(Int32 firstRow)
+ {
+ LastRow = firstRow;
+ return Container;
+ }
+ public Int32 LastRowOffset { get; set; }
+ public IXLComment SetLastRowOffset(Int32 firstRowOffset)
+ {
+ LastRowOffset = firstRowOffset;
+ return Container;
+ }
+
+ public Int32 ZOrder { get; set; }
+ public IXLComment SetZOrder(Int32 zOrder)
+ {
+ ZOrder = zOrder;
+ return Container;
+ }
+
+ public Boolean HorizontalFlip { get; set; }
+ public IXLComment SetHorizontalFlip()
+ {
+ HorizontalFlip = true;
+ return Container;
+ }
+ public IXLComment SetHorizontalFlip(Boolean horizontalFlip)
+ {
+ HorizontalFlip = horizontalFlip;
+ return Container;
+ }
+
+ public Boolean VerticalFlip { get; set; }
+ public IXLComment SetVerticalFlip()
+ {
+ VerticalFlip = true;
+ return Container;
+ }
+ public IXLComment SetVerticalFlip(Boolean verticalFlip)
+ {
+ VerticalFlip = verticalFlip;
+ return Container;
+ }
+
+ public Int32 Rotation { get; set; }
+ public IXLComment SetRotation(Int32 rotation)
+ {
+ Rotation = rotation;
+ return Container;
+ }
+
+ public Int32 OffsetX { get; set; }
+ public IXLComment SetOffsetX(Int32 offsetX)
+ {
+ OffsetX = offsetX;
+ return Container;
+ }
+
+ public Int32 OffsetY { get; set; }
+ public IXLComment SetOffsetY(Int32 offsetY)
+ {
+ OffsetY = offsetY;
+ return Container;
+ }
+
+ public Int32 ExtentLength { get; set; }
+ public IXLComment SetExtentLength(Int32 extentLength)
+ {
+ ExtentLength = extentLength;
+ return Container;
+ }
+
+ public Int32 ExtentWidth { get; set; }
+ public IXLComment SetExtentWidth(Int32 extentWidth)
+ {
+ ExtentWidth = extentWidth;
+ return Container;
+ }
+
+ public IXLDrawingStyle Style { get; private set; }
+ #endregion
+
}
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/IXLDrawing.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/IXLDrawing.cs
index 9220794..f70d90b 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/IXLDrawing.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/IXLDrawing.cs
@@ -62,5 +62,7 @@
Int32 ExtentWidth { get; set; }
T SetExtentWidth(Int32 extentWidth);
+
+ IXLDrawingStyle Style { get; }
}
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingAlignment.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingAlignment.cs
new file mode 100644
index 0000000..876331e
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingAlignment.cs
@@ -0,0 +1,36 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ClosedXML.Excel
+{
+ public enum XLDrawingTextDirection
+ {
+ Context,
+ LeftToRight,
+ RightToLeft
+ }
+ public enum XLDrawingTextOrientation
+ {
+ LeftToRight,
+ Vertical,
+ BottomToTop,
+ TopToBottom
+ }
+ public interface IXLDrawingAlignment
+ {
+ XLAlignmentHorizontalValues Horizontal { get; set; }
+ XLAlignmentVerticalValues Vertical { get; set; }
+ Boolean AutomaticSize { get; set; }
+ XLDrawingTextDirection Direction { get; set; }
+ XLDrawingTextOrientation Orientation { get; set; }
+
+ IXLDrawingStyle SetHorizontal(XLAlignmentHorizontalValues value);
+ IXLDrawingStyle SetVertical(XLAlignmentVerticalValues value);
+ IXLDrawingStyle SetAutomaticSize(); IXLDrawingStyle SetAutomaticSize(Boolean value);
+ IXLDrawingStyle SetDirection(XLDrawingTextDirection value);
+ IXLDrawingStyle SetOrientation(XLDrawingTextOrientation value);
+
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingColorsAndLines.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingColorsAndLines.cs
new file mode 100644
index 0000000..68e2e41
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingColorsAndLines.cs
@@ -0,0 +1,52 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ClosedXML.Excel
+{
+ public enum XLDashTypes
+ {
+ Solid,
+ RoundDot,
+ SquareDot,
+ Dash,
+ DashDot,
+ LongDash,
+ LongDashDot,
+ LongDashDotDot
+ }
+ public enum XLLineStyles
+ {
+ OneQuarter,
+ OneHalf,
+ ThreeQuarters,
+ One,
+ OneAndOneHalf,
+ TwoAndOneQuarter,
+ Three,
+ FourAndOneHalf,
+ Six,
+ ThreeSplit,
+ FourAndOneHalfSplit1,
+ FourAndOneHalfSplit2,
+ SixSplit
+ }
+ public interface IXLDrawingColorsAndLines
+ {
+ IXLColor FillColor { get; set; }
+ Int32 FillTransparency { get; set; }
+ IXLColor LineColor { get; set; }
+ Double LineWeight { get; set; }
+ XLDashTypes LineDash { get; set; }
+ XLLineStyles LineStyle { get; set; }
+
+ IXLDrawingStyle SetFillColor(XLColor value);
+ IXLDrawingStyle SetFillTransparency(Int32 value);
+ IXLDrawingStyle SetLineColor(XLColor value);
+ IXLDrawingStyle SetLineWeight(Double value);
+ IXLDrawingStyle SetLineDash(XLDashTypes value);
+ IXLDrawingStyle SetLineStyle(XLLineStyles value);
+
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingFont.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingFont.cs
new file mode 100644
index 0000000..bae7c2a
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingFont.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ClosedXML.Excel
+{
+ public interface IXLDrawingFont : IXLFontBase
+ {
+ IXLDrawingStyle SetBold(); IXLDrawingStyle SetBold(Boolean value);
+ IXLDrawingStyle SetItalic(); IXLDrawingStyle SetItalic(Boolean value);
+ IXLDrawingStyle SetUnderline(); IXLDrawingStyle SetUnderline(XLFontUnderlineValues value);
+ IXLDrawingStyle SetStrikethrough(); IXLDrawingStyle SetStrikethrough(Boolean value);
+ IXLDrawingStyle SetVerticalAlignment(XLFontVerticalTextAlignmentValues value);
+ IXLDrawingStyle SetShadow(); IXLDrawingStyle SetShadow(Boolean value);
+ IXLDrawingStyle SetFontSize(Double value);
+ IXLDrawingStyle SetFontColor(IXLColor value);
+ IXLDrawingStyle SetFontName(String value);
+ IXLDrawingStyle SetFontFamilyNumbering(XLFontFamilyNumberingValues value);
+
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingMargins.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingMargins.cs
new file mode 100644
index 0000000..7822100
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingMargins.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ClosedXML.Excel
+{
+ public interface IXLDrawingMargins
+ {
+ Boolean Automatic { get; set; }
+ Double Left { get; set; }
+ Double Right { get; set; }
+ Double Top { get; set; }
+ Double Bottom { get; set; }
+
+ IXLDrawingStyle SetAutomatic(); IXLDrawingStyle SetAutomatic(Boolean value);
+ IXLDrawingStyle SetLeft(Double value);
+ IXLDrawingStyle SetRight(Double value);
+ IXLDrawingStyle SetTop(Double value);
+ IXLDrawingStyle SetBottom(Double value);
+
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingProperties.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingProperties.cs
new file mode 100644
index 0000000..cf2118b
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingProperties.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ClosedXML.Excel
+{
+ public interface IXLDrawingProperties
+ {
+ XLDrawingAnchor Positioning { get; set; }
+ IXLDrawingStyle SetPositioning(XLDrawingAnchor value);
+
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingProtection.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingProtection.cs
new file mode 100644
index 0000000..67ff8cd
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingProtection.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ClosedXML.Excel
+{
+ public interface IXLDrawingProtection
+ {
+ Boolean Locked { get; set; }
+ Boolean LockText { get; set; }
+
+ IXLDrawingStyle SetLocked(); IXLDrawingStyle SetLocked(Boolean value);
+ IXLDrawingStyle SetLockText(); IXLDrawingStyle SetLockText(Boolean value);
+
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingSize.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingSize.cs
new file mode 100644
index 0000000..f2537fb
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingSize.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ClosedXML.Excel
+{
+ public interface IXLDrawingSize
+ {
+ Double Height { get; set; }
+ Double Width { get; set; }
+ Double ScaleHeight { get; set; }
+ Double ScaleWidth { get; set; }
+ Boolean LockAspectRatio { get; set; }
+
+ IXLDrawingStyle SetHeight(Double value);
+ IXLDrawingStyle SetWidth(Double value);
+ IXLDrawingStyle SetScaleHeight(Double value);
+ IXLDrawingStyle SetScaleWidth(Double value);
+ IXLDrawingStyle SetLockAspectRatio(); IXLDrawingStyle SetLockAspectRatio(Boolean value);
+
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingStyle.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingStyle.cs
new file mode 100644
index 0000000..3c1bce3
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingStyle.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ClosedXML.Excel
+{
+ public interface IXLDrawingStyle
+ {
+ IXLDrawingFont Font { get; }
+ IXLDrawingAlignment Alignment { get; }
+ IXLDrawingColorsAndLines ColorsAndLines { get; }
+ IXLDrawingSize Size { get; }
+ IXLDrawingProtection Protection { get; }
+ IXLDrawingProperties Properties { get; }
+ IXLDrawingMargins Margins { get; }
+ IXLDrawingWeb Web { get; }
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingWeb.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingWeb.cs
new file mode 100644
index 0000000..73556bb
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/IXLDrawingWeb.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ClosedXML.Excel
+{
+ public interface IXLDrawingWeb
+ {
+ String AlternativeText { get; set; }
+ IXLDrawingStyle SetAlternativeText(String value);
+
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingAlignment.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingAlignment.cs
new file mode 100644
index 0000000..f9f3b82
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingAlignment.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ClosedXML.Excel
+{
+ internal class XLDrawingAlignment: IXLDrawingAlignment
+ {
+ private readonly IXLDrawingStyle _style;
+
+ public XLDrawingAlignment(IXLDrawingStyle style)
+ {
+ _style = style;
+ Horizontal = XLAlignmentHorizontalValues.Left;
+ Vertical = XLAlignmentVerticalValues.Top;
+ Direction = XLDrawingTextDirection.Context;
+ Orientation = XLDrawingTextOrientation.LeftToRight;
+ }
+ public XLAlignmentHorizontalValues Horizontal { get; set; } public IXLDrawingStyle SetHorizontal(XLAlignmentHorizontalValues value) { Horizontal = value; return _style; }
+ public XLAlignmentVerticalValues Vertical { get; set; } public IXLDrawingStyle SetVertical(XLAlignmentVerticalValues value) { Vertical = value; return _style; }
+ public Boolean AutomaticSize { get; set; } public IXLDrawingStyle SetAutomaticSize() { AutomaticSize = true; return _style; } public IXLDrawingStyle SetAutomaticSize(Boolean value) { AutomaticSize = value; return _style; }
+ public XLDrawingTextDirection Direction { get; set; } public IXLDrawingStyle SetDirection(XLDrawingTextDirection value) { Direction = value; return _style; }
+ public XLDrawingTextOrientation Orientation { get; set; } public IXLDrawingStyle SetOrientation(XLDrawingTextOrientation value) { Orientation = value; return _style; }
+
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingColorsAndLines.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingColorsAndLines.cs
new file mode 100644
index 0000000..16b9b06
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingColorsAndLines.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ClosedXML.Excel
+{
+ internal class XLDrawingColorsAndLines: IXLDrawingColorsAndLines
+ {
+ private readonly IXLDrawingStyle _style;
+
+ public XLDrawingColorsAndLines(IXLDrawingStyle style)
+ {
+ _style = style;
+ FillColor = XLColor.FromArgb(255, 255, 225);
+ LineColor = XLColor.Black;
+ LineDash = XLDashTypes.Solid;
+ LineStyle = XLLineStyles.OneQuarter;
+ LineWeight = 0.75;
+ }
+ public IXLColor FillColor { get; set; } public IXLDrawingStyle SetFillColor(XLColor value) { FillColor = value; return _style; }
+ public Int32 FillTransparency { get; set; } public IXLDrawingStyle SetFillTransparency(Int32 value) { FillTransparency = value; return _style; }
+ public IXLColor LineColor { get; set; } public IXLDrawingStyle SetLineColor(XLColor value) { LineColor = value; return _style; }
+ public Double LineWeight { get; set; } public IXLDrawingStyle SetLineWeight(Double value) { LineWeight = value; return _style; }
+ public XLDashTypes LineDash { get; set; } public IXLDrawingStyle SetLineDash(XLDashTypes value) { LineDash = value; return _style; }
+ public XLLineStyles LineStyle { get; set; } public IXLDrawingStyle SetLineStyle(XLLineStyles value) { LineStyle = value; return _style; }
+
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingFont.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingFont.cs
new file mode 100644
index 0000000..1927b89
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingFont.cs
@@ -0,0 +1,124 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ClosedXML.Excel
+{
+ internal class XLDrawingFont : IXLDrawingFont
+ {
+ private readonly IXLDrawingStyle _style;
+
+ public XLDrawingFont(IXLDrawingStyle style)
+ {
+ _style = style;
+ FontName = "Tahoma";
+ FontSize = 9;
+ Underline = XLFontUnderlineValues.None;
+ FontColor = XLColor.FromIndex(64);
+ }
+
+ public Boolean Bold { get; set; }
+ public Boolean Italic { get; set; }
+ public XLFontUnderlineValues Underline { get; set; }
+ public Boolean Strikethrough { get; set; }
+ public XLFontVerticalTextAlignmentValues VerticalAlignment { get; set; }
+ public Boolean Shadow { get; set; }
+ public Double FontSize { get; set; }
+ public IXLColor FontColor { get; set; }
+ public String FontName { get; set; }
+ public XLFontFamilyNumberingValues FontFamilyNumbering { get; set; }
+
+
+ public IXLDrawingStyle SetBold()
+ {
+ Bold = true;
+ return _style;
+ }
+
+ public IXLDrawingStyle SetBold(Boolean value)
+ {
+ Bold = value;
+ return _style;
+ }
+
+ public IXLDrawingStyle SetItalic()
+ {
+ Italic = true;
+ return _style;
+ }
+
+ public IXLDrawingStyle SetItalic(Boolean value)
+ {
+ Italic = value;
+ return _style;
+ }
+
+ public IXLDrawingStyle SetUnderline()
+ {
+ Underline = XLFontUnderlineValues.Single;
+ return _style;
+ }
+
+ public IXLDrawingStyle SetUnderline(XLFontUnderlineValues value)
+ {
+ Underline = value;
+ return _style;
+ }
+
+ public IXLDrawingStyle SetStrikethrough()
+ {
+ Strikethrough = true;
+ return _style;
+ }
+
+ public IXLDrawingStyle SetStrikethrough(Boolean value)
+ {
+ Strikethrough = value;
+ return _style;
+ }
+
+ public IXLDrawingStyle SetVerticalAlignment(XLFontVerticalTextAlignmentValues value)
+ {
+ VerticalAlignment = value;
+ return _style;
+ }
+
+ public IXLDrawingStyle SetShadow()
+ {
+ Shadow = true;
+ return _style;
+ }
+
+ public IXLDrawingStyle SetShadow(Boolean value)
+ {
+ Shadow = value;
+ return _style;
+ }
+
+ public IXLDrawingStyle SetFontSize(Double value)
+ {
+ FontSize = value;
+ return _style;
+ }
+
+ public IXLDrawingStyle SetFontColor(IXLColor value)
+ {
+ FontColor = value;
+ return _style;
+ }
+
+ public IXLDrawingStyle SetFontName(String value)
+ {
+ FontName = value;
+ return _style;
+ }
+
+ public IXLDrawingStyle SetFontFamilyNumbering(XLFontFamilyNumberingValues value)
+ {
+ FontFamilyNumbering = value;
+ return _style;
+ }
+
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingMargins.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingMargins.cs
new file mode 100644
index 0000000..6d5ebb6
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingMargins.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ClosedXML.Excel
+{
+ internal class XLDrawingMargins: IXLDrawingMargins
+ {
+ private readonly IXLDrawingStyle _style;
+
+ public XLDrawingMargins(IXLDrawingStyle style)
+ {
+ _style = style;
+ Automatic = true;
+ }
+ public Boolean Automatic { get; set; } public IXLDrawingStyle SetAutomatic() { Automatic = true; return _style; } public IXLDrawingStyle SetAutomatic(Boolean value) { Automatic = value; return _style; }
+ public Double Left { get; set; } public IXLDrawingStyle SetLeft(Double value) { Left = value; return _style; }
+ public Double Right { get; set; } public IXLDrawingStyle SetRight(Double value) { Right = value; return _style; }
+ public Double Top { get; set; } public IXLDrawingStyle SetTop(Double value) { Top = value; return _style; }
+ public Double Bottom { get; set; } public IXLDrawingStyle SetBottom(Double value) { Bottom = value; return _style; }
+
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingProperties.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingProperties.cs
new file mode 100644
index 0000000..b55d3ce
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingProperties.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ClosedXML.Excel
+{
+ internal class XLDrawingProperties : IXLDrawingProperties
+ {
+ private readonly IXLDrawingStyle _style;
+
+ public XLDrawingProperties(IXLDrawingStyle style)
+ {
+ _style = style;
+ Positioning = XLDrawingAnchor.Absolute;
+ }
+ public XLDrawingAnchor Positioning { get; set; } public IXLDrawingStyle SetPositioning(XLDrawingAnchor value) { Positioning = value; return _style; }
+
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingProtection.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingProtection.cs
new file mode 100644
index 0000000..1ea3ec9
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingProtection.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ClosedXML.Excel
+{
+ internal class XLDrawingProtection : IXLDrawingProtection
+ {
+ private readonly IXLDrawingStyle _style;
+
+ public XLDrawingProtection(IXLDrawingStyle style)
+ {
+ _style = style;
+ Locked = true;
+ LockText = true;
+ }
+ public Boolean Locked { get; set; } public IXLDrawingStyle SetLocked() { Locked = true; return _style; } public IXLDrawingStyle SetLocked(Boolean value) { Locked = value; return _style; }
+ public Boolean LockText { get; set; } public IXLDrawingStyle SetLockText() { LockText = true; return _style; } public IXLDrawingStyle SetLockText(Boolean value) { LockText = value; return _style; }
+
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingSize.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingSize.cs
new file mode 100644
index 0000000..b8eee0a
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingSize.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ClosedXML.Excel
+{
+ internal class XLDrawingSize : IXLDrawingSize
+ {
+ private readonly IXLDrawingStyle _style;
+
+ public XLDrawingSize(IXLDrawingStyle style)
+ {
+ _style = style;
+ Height = 0.82;
+ Width = 1.5;
+ ScaleHeight = 100;
+ ScaleWidth = 100;
+ }
+ public Double Height { get; set; } public IXLDrawingStyle SetHeight(Double value) { Height = value; return _style; }
+ public Double Width { get; set; } public IXLDrawingStyle SetWidth(Double value) { Width = value; return _style; }
+ public Double ScaleHeight { get; set; } public IXLDrawingStyle SetScaleHeight(Double value) { ScaleHeight = value; return _style; }
+ public Double ScaleWidth { get; set; } public IXLDrawingStyle SetScaleWidth(Double value) { ScaleWidth = value; return _style; }
+ public Boolean LockAspectRatio { get; set; } public IXLDrawingStyle SetLockAspectRatio() { LockAspectRatio = true; return _style; } public IXLDrawingStyle SetLockAspectRatio(Boolean value) { LockAspectRatio = value; return _style; }
+
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingStyle.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingStyle.cs
new file mode 100644
index 0000000..dbfb362
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingStyle.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ClosedXML.Excel
+{
+ internal class XLDrawingStyle: IXLDrawingStyle
+ {
+ public XLDrawingStyle()
+ {
+ Font = new XLDrawingFont(this);
+ Alignment = new XLDrawingAlignment(this);
+ ColorsAndLines = new XLDrawingColorsAndLines(this);
+ Size = new XLDrawingSize(this);
+ Protection = new XLDrawingProtection(this);
+ Properties = new XLDrawingProperties(this);
+ Margins = new XLDrawingMargins(this);
+ Web = new XLDrawingWeb(this);
+ }
+ public IXLDrawingFont Font { get; private set; }
+ public IXLDrawingAlignment Alignment { get; private set; }
+ public IXLDrawingColorsAndLines ColorsAndLines { get; private set; }
+ public IXLDrawingSize Size { get; private set; }
+ public IXLDrawingProtection Protection { get; private set; }
+ public IXLDrawingProperties Properties { get; private set; }
+ public IXLDrawingMargins Margins { get; private set; }
+ public IXLDrawingWeb Web { get; private set; }
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingWeb.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingWeb.cs
new file mode 100644
index 0000000..bcff831
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/Style/XLDrawingWeb.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ClosedXML.Excel
+{
+ internal class XLDrawingWeb : IXLDrawingWeb
+ {
+ private readonly IXLDrawingStyle _style;
+
+ public XLDrawingWeb(IXLDrawingStyle style)
+ {
+ _style = style;
+ }
+ public String AlternativeText { get; set; } public IXLDrawingStyle SetAlternativeText(String value) { AlternativeText = value; return _style; }
+
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/XLDrawing.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/XLDrawing.cs
index 96ae86c..005d000 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/XLDrawing.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Drawings/XLDrawing.cs
@@ -8,6 +8,7 @@
public XLDrawing()
{
Anchor = XLDrawingAnchor.MoveAndSizeWithCells;
+ Style = new XLDrawingStyle();
}
public Int32 Id { get; internal set; }
@@ -155,5 +156,7 @@
ExtentWidth = extentWidth;
return Container;
}
+
+ public IXLDrawingStyle Style { get; private set; }
}
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/IXLBaseCollection.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/IXLBaseCollection.cs
new file mode 100644
index 0000000..115776c
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/IXLBaseCollection.cs
@@ -0,0 +1,77 @@
+using System;
+using System.Collections.Generic;
+
+namespace ClosedXML.Excel
+{
+ public interface IXLBaseCollection: IEnumerable
+ {
+ Int32 Count { get; }
+
+ IXLStyle Style { get; set; }
+
+ IXLDataValidation DataValidation { get; }
+
+ ///
+ /// Creates a named range out of these ranges.
+ /// If the named range exists, it will add these ranges to that named range.
+ /// The default scope for the named range is Workbook.
+ ///
+ /// Name of the range.
+ TMultiple AddToNamed(String rangeName);
+
+ ///
+ /// Creates a named range out of these ranges.
+ /// If the named range exists, it will add these ranges to that named range.
+ /// Name of the range.
+ /// The scope for the named range.
+ ///
+ TMultiple AddToNamed(String rangeName, XLScope scope);
+
+ ///
+ /// Creates a named range out of these ranges.
+ /// If the named range exists, it will add these ranges to that named range.
+ /// Name of the range.
+ /// The scope for the named range.
+ /// The comments for the named range.
+ ///
+ TMultiple AddToNamed(String rangeName, XLScope scope, String comment);
+
+ ///
+ /// Sets the cells' value.
+ /// If the object is an IEnumerable ClosedXML will copy the collection's data into a table starting from each cell.
+ /// If the object is a range ClosedXML will copy the range starting from each cell.
+ /// Setting the value to an object (not IEnumerable/range) will call the object's ToString() method.
+ /// ClosedXML will try to translate it to the corresponding type, if it can't then the value will be left as a string.
+ ///
+ ///
+ /// The object containing the value(s) to set.
+ ///
+ Object Value { set; }
+
+ TMultiple SetValue(T value);
+
+ ///
+ /// Returns the collection of cells.
+ ///
+ IXLCells Cells();
+
+ ///
+ /// Returns the collection of cells that have a value.
+ ///
+ IXLCells CellsUsed();
+
+ ///
+ /// Returns the collection of cells that have a value.
+ ///
+ /// if set to true will return all cells with a value or a style different than the default.
+ IXLCells CellsUsed(Boolean includeStyles);
+
+ TMultiple SetDataType(XLCellValues dataType);
+
+ ///
+ /// Clears the contents of these ranges.
+ ///
+ /// Specify what you want to clear.
+ TMultiple Clear(XLClearOptions clearOptions = XLClearOptions.ContentsAndFormats);
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLFont.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLFont.cs
index 47c8ad0..54cad5e 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLFont.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLFont.cs
@@ -30,8 +30,6 @@
public interface IXLFont : IXLFontBase, IEquatable
{
-
-
IXLStyle SetBold(); IXLStyle SetBold(Boolean value);
IXLStyle SetItalic(); IXLStyle SetItalic(Boolean value);
IXLStyle SetUnderline(); IXLStyle SetUnderline(XLFontUnderlineValues value);
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.NestedTypes.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.NestedTypes.cs
index 41c0380..51bf44b 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.NestedTypes.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.NestedTypes.cs
@@ -65,7 +65,8 @@
#region Nested type: RelType
private enum RelType
{
- Workbook
+ Workbook,
+ Worksheet
}
#endregion
#region Nested type: RelIdGenerator
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs
index 809d4cb..ca6726e 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs
@@ -10,6 +10,7 @@
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using DocumentFormat.OpenXml.VariantTypes;
+using Vml = DocumentFormat.OpenXml.Vml;
using BackgroundColor = DocumentFormat.OpenXml.Spreadsheet.BackgroundColor;
using BottomBorder = DocumentFormat.OpenXml.Spreadsheet.BottomBorder;
using Break = DocumentFormat.OpenXml.Spreadsheet.Break;
@@ -142,7 +143,14 @@
GenerateWorksheetPartContent(worksheetPart, worksheet, context);
- GeneratePivotTables(workbookPart, worksheetPart, worksheet, context);
+ //GeneratePivotTables(workbookPart, worksheetPart, worksheet, context);
+
+ WorksheetCommentsPart worksheetCommentsPart = worksheetPart.AddNewPart(context.RelIdGenerator.GetNext(RelType.Worksheet));
+ GenerateWorksheetCommentsPartContent(worksheetCommentsPart, worksheet);
+
+ worksheet.LegacyDrawingId = context.RelIdGenerator.GetNext(RelType.Worksheet);
+ VmlDrawingPart vmlDrawingPart = worksheetPart.AddNewPart(worksheet.LegacyDrawingId);
+ GenerateVmlDrawingPartContent(vmlDrawingPart, worksheet, context);
//DrawingsPart drawingsPart = worksheetPart.AddNewPart("rId1");
//GenerateDrawingsPartContent(drawingsPart, worksheet);
@@ -587,8 +595,7 @@
workbook.CalculationProperties.ReferenceMode = ReferenceStyle.ToOpenXml();
}
- private void GenerateSharedStringTablePartContent(SharedStringTablePart sharedStringTablePart,
- SaveContext context)
+ private void GenerateSharedStringTablePartContent(SharedStringTablePart sharedStringTablePart, SaveContext context)
{
sharedStringTablePart.SharedStringTable = new SharedStringTable {Count = 0, UniqueCount = 0};
@@ -609,45 +616,7 @@
var sharedStringItem = new SharedStringItem();
foreach (IXLRichString rt in c.RichText)
{
- var run = new DocumentFormat.OpenXml.Spreadsheet.Run();
-
- var runProperties = new DocumentFormat.OpenXml.Spreadsheet.RunProperties();
-
- var bold = rt.Bold ? new Bold() : null;
- var italic = rt.Italic ? new Italic() : null;
- var underline = rt.Underline != XLFontUnderlineValues.None
- ? new Underline {Val = rt.Underline.ToOpenXml()}
- : null;
- var strike = rt.Strikethrough ? new Strike() : null;
- var verticalAlignment = new VerticalTextAlignment
- {Val = rt.VerticalAlignment.ToOpenXml()};
- var shadow = rt.Shadow ? new Shadow() : null;
- var fontSize = new FontSize {Val = rt.FontSize};
- var color = GetNewColor(rt.FontColor);
- var fontName = new RunFont {Val = rt.FontName};
- var fontFamilyNumbering = new FontFamily {Val = (Int32)rt.FontFamilyNumbering};
-
- if (bold != null) runProperties.Append(bold);
- if (italic != null) runProperties.Append(italic);
-
- if (strike != null) runProperties.Append(strike);
- if (shadow != null) runProperties.Append(shadow);
- if (underline != null) runProperties.Append(underline);
- runProperties.Append(verticalAlignment);
-
- runProperties.Append(fontSize);
- runProperties.Append(color);
- runProperties.Append(fontName);
- runProperties.Append(fontFamilyNumbering);
-
- var text = new Text {Text = rt.Text};
- if (rt.Text.PreserveSpaces())
- text.Space = SpaceProcessingModeValues.Preserve;
-
- run.Append(runProperties);
- run.Append(text);
-
- sharedStringItem.Append(run);
+ sharedStringItem.Append(GetRun(rt));
}
if (c.RichText.HasPhonetics)
@@ -721,6 +690,48 @@
}
}
+ private static DocumentFormat.OpenXml.Spreadsheet.Run GetRun(IXLRichString rt)
+ {
+ var run = new DocumentFormat.OpenXml.Spreadsheet.Run();
+
+ var runProperties = new DocumentFormat.OpenXml.Spreadsheet.RunProperties();
+
+ var bold = rt.Bold ? new Bold() : null;
+ var italic = rt.Italic ? new Italic() : null;
+ var underline = rt.Underline != XLFontUnderlineValues.None
+ ? new Underline {Val = rt.Underline.ToOpenXml()}
+ : null;
+ var strike = rt.Strikethrough ? new Strike() : null;
+ var verticalAlignment = new VerticalTextAlignment
+ {Val = rt.VerticalAlignment.ToOpenXml()};
+ var shadow = rt.Shadow ? new Shadow() : null;
+ var fontSize = new FontSize {Val = rt.FontSize};
+ var color = GetNewColor(rt.FontColor);
+ var fontName = new RunFont {Val = rt.FontName};
+ var fontFamilyNumbering = new FontFamily {Val = (Int32)rt.FontFamilyNumbering};
+
+ if (bold != null) runProperties.Append(bold);
+ if (italic != null) runProperties.Append(italic);
+
+ if (strike != null) runProperties.Append(strike);
+ if (shadow != null) runProperties.Append(shadow);
+ if (underline != null) runProperties.Append(underline);
+ runProperties.Append(verticalAlignment);
+
+ runProperties.Append(fontSize);
+ runProperties.Append(color);
+ runProperties.Append(fontName);
+ runProperties.Append(fontFamilyNumbering);
+
+ var text = new Text {Text = rt.Text};
+ if (rt.Text.PreserveSpaces())
+ text.Space = SpaceProcessingModeValues.Preserve;
+
+ run.Append(runProperties);
+ run.Append(text);
+ return run;
+ }
+
private void GenerateCalculationChainPartContent(WorkbookPart workbookPart, SaveContext context)
{
string thisRelId = context.RelIdGenerator.GetNext(RelType.Workbook);
@@ -1655,9 +1666,8 @@
xlStyles.Add(s);
}
- foreach (Int32 id in xlStyles)
+ foreach (var xlStyle in xlStyles.Select(GetStyleById))
{
- var xlStyle = GetStyleById(id);
if (!context.SharedFonts.ContainsKey(xlStyle.Font))
context.SharedFonts.Add(xlStyle.Font, new FontInfo {FontId = fontCount++, Font = xlStyle.Font});
@@ -1668,7 +1678,7 @@
sharedBorders.Add(xlStyle.Border, new BorderInfo {BorderId = borderCount++, Border = xlStyle.Border});
if ( xlStyle.NumberFormat.NumberFormatId != -1
- || sharedNumberFormats.ContainsKey(xlStyle.NumberFormat))
+ || sharedNumberFormats.ContainsKey(xlStyle.NumberFormat))
continue;
sharedNumberFormats.Add(xlStyle.NumberFormat,
@@ -2739,11 +2749,9 @@
foreach (XLSheetPoint c in xlWorksheet.Internals.CellsCollection.Deleted.ToList())
{
String key = ExcelHelper.GetColumnLetterFromNumber(c.Column) + c.Row.ToStringLookup();
- if (cellsByReference.ContainsKey(key))
- {
- row.RemoveChild(cellsByReference[key]);
- xlWorksheet.Internals.CellsCollection.Deleted.Remove(c);
- }
+ if (!cellsByReference.ContainsKey(key)) continue;
+ row.RemoveChild(cellsByReference[key]);
+ xlWorksheet.Internals.CellsCollection.Deleted.Remove(c);
}
if (!cellsByRow.ContainsKey(distinctRow)) continue;
@@ -2859,13 +2867,10 @@
}
xlWorksheet.Internals.CellsCollection.Deleted.RemoveWhere(d => d.Row == distinctRow);
}
- foreach (var r in xlWorksheet.Internals.CellsCollection.Deleted.Select(c=>c.Row).Distinct())
+ foreach (var r in xlWorksheet.Internals.CellsCollection.Deleted.Select(c=>c.Row).Distinct().Where(sheetDataRows.ContainsKey))
{
- if (sheetDataRows.ContainsKey(r))
- {
- sheetData.RemoveChild(sheetDataRows[r]);
- sheetDataRows.Remove(r);
- }
+ sheetData.RemoveChild(sheetDataRows[r]);
+ sheetDataRows.Remove(r);
}
#endregion
@@ -3292,22 +3297,21 @@
tableParts.AppendChild(tablePart);
#endregion
+
+ #region LegacyDrawing
+ worksheetPart.Worksheet.RemoveAllChildren();
+ {
+ var previousElement = cm.GetPreviousElementFor(XLWSContentManager.XLWSContents.LegacyDrawing);
+ worksheetPart.Worksheet.InsertAfter(new LegacyDrawing { Id = xlWorksheet.LegacyDrawingId }, previousElement);
+ }
+ #endregion
}
private static BooleanValue GetBooleanValue(bool value, bool defaultValue)
{
return value == defaultValue ? null : new BooleanValue(value);
}
- private struct MinMax
- {
- public MinMax (UInt32 min, UInt32 max)
- {
- Min = min;
- Max = max;
- }
- public UInt32 Min;
- public UInt32 Max;
- }
+
private static void CollapseColumns(Columns columns, Dictionary sheetColumns)
{
UInt32 lastMin = 1;
@@ -3321,19 +3325,18 @@
for (int i = 0; i < count; i++)
{
var kp = arr[i];
- if (i+1 ==count || !ColumnsAreEqual(kp.Value, arr[i + 1].Value))
- {
- var newColumn = (Column)kp.Value.CloneNode(true);
- newColumn.Min = lastMin;
- uint newColumnMax = newColumn.Max.Value;
- var columnsToRemove =
- columns.Elements().Where(co => co.Min >= lastMin && co.Max <= newColumnMax).
- Select(co => co).ToList();
- columnsToRemove.ForEach(c => columns.RemoveChild(c));
+ if (i + 1 != count && ColumnsAreEqual(kp.Value, arr[i + 1].Value)) continue;
- columns.AppendChild(newColumn);
- lastMin = kp.Key + 1;
- }
+ var newColumn = (Column)kp.Value.CloneNode(true);
+ newColumn.Min = lastMin;
+ uint newColumnMax = newColumn.Max.Value;
+ var columnsToRemove =
+ columns.Elements().Where(co => co.Min >= lastMin && co.Max <= newColumnMax).
+ Select(co => co).ToList();
+ columnsToRemove.ForEach(c => columns.RemoveChild(c));
+
+ columns.AppendChild(newColumn);
+ lastMin = kp.Key + 1;
//i++;
}
@@ -3845,15 +3848,12 @@
}
else
{
- foreach (var cell in source.Cells().Where(cell =>
- cell.Address.ColumnNumber == columnNumber &&
- cell.Address.RowNumber > source.FirstRow().RowNumber()))
+ foreach (var cellValue in source.Cells().Where(cell =>
+ cell.Address.ColumnNumber == columnNumber &&
+ cell.Address.RowNumber > source.FirstRow().RowNumber()).Select(cell => cell.Value.ToString())
+ .Where(cellValue => !xlpf.SharedStrings.Contains(cellValue)))
{
- var cellValue = cell.Value.ToString();
- if (!xlpf.SharedStrings.Contains(cellValue))
- {
- xlpf.SharedStrings.Add(cellValue);
- }
+ xlpf.SharedStrings.Add(cellValue);
}
foreach (var li in xlpf.SharedStrings)
@@ -3969,6 +3969,7 @@
rowItemTotal.AppendChild(new MemberPropertyIndex());
rowItems.AppendChild(rowItemTotal);
+
}
else if (pt.ColumnLabels.Where(p => p.SourceName == xlpf.SourceName).FirstOrDefault() != null)
{
@@ -4110,38 +4111,37 @@
foreach (var value in pt.Values)
{
var sourceColumn = pt.SourceRange.Columns().Where(c => c.Cell(1).Value.ToString() == value.SourceName).FirstOrDefault();
- if (sourceColumn != null)
+ if (sourceColumn == null) continue;
+
+ var df = new DataField
+ {
+ Name = value.SourceName,
+ Field = (UInt32)sourceColumn.ColumnNumber() - 1,
+ Subtotal = value.SummaryFormula.ToOpenXml(),
+ ShowDataAs = value.Calculation.ToOpenXml(),
+ NumberFormatId = (UInt32)value.NumberFormat.NumberFormatId
+ };
+
+ if (!String.IsNullOrEmpty(value.BaseField))
{
- var df = new DataField
- {
- Name = value.SourceName,
- Field = (UInt32)sourceColumn.ColumnNumber() - 1,
- Subtotal = value.SummaryFormula.ToOpenXml(),
- ShowDataAs = value.Calculation.ToOpenXml(),
- NumberFormatId = (UInt32)value.NumberFormat.NumberFormatId
- };
-
- if (!String.IsNullOrEmpty(value.BaseField))
- {
- var baseField = pt.SourceRange.Columns().Where(c => c.Cell(1).Value.ToString() == value.BaseField).FirstOrDefault();
- if (baseField != null)
- df.BaseField = baseField.ColumnNumber() - 1;
- }
- else
- {
- df.BaseField = 0;
- }
-
- if (value.CalculationItem == XLPivotCalculationItem.Previous)
- df.BaseItem = 1048828U;
- else if (value.CalculationItem == XLPivotCalculationItem.Next)
- df.BaseItem = 1048829U;
- else
- df.BaseItem = 0U;
-
-
- dataFields.AppendChild(df);
+ var baseField = pt.SourceRange.Columns().Where(c => c.Cell(1).Value.ToString() == value.BaseField).FirstOrDefault();
+ if (baseField != null)
+ df.BaseField = baseField.ColumnNumber() - 1;
}
+ else
+ {
+ df.BaseField = 0;
+ }
+
+ if (value.CalculationItem == XLPivotCalculationItem.Previous)
+ df.BaseItem = 1048828U;
+ else if (value.CalculationItem == XLPivotCalculationItem.Next)
+ df.BaseItem = 1048829U;
+ else
+ df.BaseItem = 0U;
+
+
+ dataFields.AppendChild(df);
}
pivotTableDefinition.AppendChild(dataFields);
@@ -4167,5 +4167,180 @@
pivotTablePart1.PivotTableDefinition = pivotTableDefinition;
}
+
+ private static void GenerateWorksheetCommentsPartContent(WorksheetCommentsPart worksheetCommentsPart, XLWorksheet xlWorksheet)
+ {
+ Comments comments = new Comments();
+ CommentList commentList = new CommentList();
+ var authorsDict = new Dictionary();
+ foreach (var c in xlWorksheet.Internals.CellsCollection.GetCells(c=>c.HasComment))
+ {
+ Comment comment = new Comment() { Reference = c.Address.ToStringRelative() };
+ String authorName = StringExtensions.IsNullOrWhiteSpace(c.Comment.Author)
+ ? Environment.UserName
+ : c.Comment.Author;
+
+ Int32 authorId;
+ if (!authorsDict.TryGetValue(authorName, out authorId))
+ {
+ authorId = authorsDict.Count;
+ authorsDict.Add(authorName, authorId);
+ }
+ comment.AuthorId = (UInt32)authorId;
+
+ CommentText commentText = new CommentText();
+ foreach (var rt in c.Comment)
+ {
+ commentText.Append(GetRun(rt));
+ }
+
+ comment.Append(commentText);
+ commentList.Append(comment);
+ }
+
+ Authors authors = new Authors();
+ foreach (Author author in authorsDict.Select(a => new Author() {Text = a.Key}))
+ {
+ authors.Append(author);
+ }
+ comments.Append(authors);
+ comments.Append(commentList);
+
+ worksheetCommentsPart.Comments = comments;
+ }
+
+ // Generates content of vmlDrawingPart1.
+ private static void GenerateVmlDrawingPartContent(VmlDrawingPart vmlDrawingPart, XLWorksheet xlWorksheet, SaveContext context)
+ {
+
+ #region Office VML
+ //
+
+ //
+ //
+ //
+
+ //
+ //
+ //
+ //
+ //
+ //
+
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ // {leftCol}, 15, {topRow}, 4, {rightCol}, 10, {bottomRow}, 1
+ // {rowIndex}
+ // {colIndex}
+ //
+ //
+ //
+ #endregion
+
+ System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(vmlDrawingPart.GetStream(System.IO.FileMode.Create), System.Text.Encoding.UTF8);
+ writer.WriteStartElement("xml");
+
+ // o:shapelayout
+ new Vml.Office.ShapeLayout(
+ new Vml.Office.ShapeIdMap()
+ {
+ Extension = Vml.ExtensionHandlingBehaviorValues.Edit,
+ Data = "1"
+ }
+ ) { Extension = Vml.ExtensionHandlingBehaviorValues.Edit }
+ .WriteTo(writer);
+
+ const string shapeTypeId = "_x0000_t202"; // arbitrary, assigned by office
+
+ // v:shapetype
+ new Vml.Shapetype(
+ new Vml.Stroke() { JoinStyle = Vml.StrokeJoinStyleValues.Miter },
+ new Vml.Path() { AllowGradientShape = true, ConnectionPointType = Vml.Office.ConnectValues.Rectangle }
+ )
+ {
+ Id = shapeTypeId,
+ CoordinateSize = "21600,21600",
+ OptionalNumber = 202,
+ EdgePath = "m,l,21600r21600,l21600,xe",
+ }
+ .WriteTo(writer);
+
+ // v:shape
+ var cellWithComments = xlWorksheet.Internals.CellsCollection.GetCells().Where(c => c.HasComment);
+
+ foreach (XLCell c in cellWithComments)
+ {
+ GenerateShape(c, shapeTypeId).WriteTo(writer);
+ }
+
+ writer.Flush();
+ writer.Close();
+
+ }
+
+ // VML Shape for Comment
+ private static Vml.Shape GenerateShape(XLCell c, string shapeTypeId)
+ {
+
+ #region Office VML
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ // {leftCol}, 15, {topRow}, 4, {rightCol}, 10, {bottomRow}, 1
+ // {rowIndex}
+ // {colIndex}
+ //
+ //
+ #endregion
+
+ // Limitaion: Most of the shape properties hard coded.
+
+
+ var rowNumber = c.Address.RowNumber;
+ var columnNumber = c.Address.ColumnNumber;
+ var leftCol = columnNumber;
+ var topRow = rowNumber == 1 ? rowNumber - 1 : rowNumber - 2; // -1 : zero based index, -2 : moved up
+ var topOffset = rowNumber == 1 ? 2 : 15; // on first row, comment is 2px down, on any other is 15 px up
+ var rightCol = leftCol + c.Comment.Style.Size.Width;
+ var bottomRow = topRow + c.Comment.Style.Size.Height;
+
+ var shapeId = string.Format("_x0000_s{0}", c.GetHashCode().ToString()); // Unique per cell, e.g.: "_x0000_s1026"
+
+ return new Vml.Shape(
+ new Vml.Fill { Color2 = "#" + c.Comment.Style.ColorsAndLines.FillColor.Color.ToHex().Substring(2) },
+ new Vml.Shadow() { On = true, Color = "black", Obscured = true },
+ new Vml.Path() { ConnectionPointType = Vml.Office.ConnectValues.None },
+ new Vml.TextBox( /* */ ) { Style = "mso-direction-alt:auto" },
+ new Vml.Spreadsheet.ClientData(
+ new Vml.Spreadsheet.MoveWithCells() { },
+ new Vml.Spreadsheet.ResizeWithCells() { },
+ new Vml.Spreadsheet.Anchor() { Text = string.Format(" {0}, 15, {1}, {2}, {3}, 10, {4}, 1", leftCol, topRow, topOffset, rightCol, bottomRow) },
+ new Vml.Spreadsheet.AutoFill("False") { },
+ new Vml.Spreadsheet.CommentRowTarget() { Text = (rowNumber - 1).ToString() },
+ new Vml.Spreadsheet.CommentColumnTarget() { Text = (columnNumber - 1).ToString() }
+ ) { ObjectType = Vml.Spreadsheet.ObjectValues.Note }
+ )
+ {
+ Id = shapeId,
+ Type = "#" + shapeTypeId,
+ Style = "visibility:hidden",
+ FillColor = "#" + c.Comment.Style.ColorsAndLines.FillColor.Color.ToHex().Substring(2),
+ InsetMode = Vml.Office.InsetMarginValues.Auto
+ };
+ }
}
}
\ No newline at end of file
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorksheet.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorksheet.cs
index 9aae4f2..0bf80c4 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorksheet.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorksheet.cs
@@ -156,6 +156,8 @@
}
private Double _columnWidth;
+ public string LegacyDrawingId;
+
public Double ColumnWidth
{
get
diff --git a/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj b/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj
index 48b9af4..d8859e6 100644
--- a/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj
+++ b/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj
@@ -235,6 +235,60 @@
Excel\Drawings\IXLDrawing.cs
+
+ Excel\Drawings\Style\IXLDrawingAlignment.cs
+
+
+ Excel\Drawings\Style\IXLDrawingColorsAndLines.cs
+
+
+ Excel\Drawings\Style\IXLDrawingFont.cs
+
+
+ Excel\Drawings\Style\IXLDrawingMargins.cs
+
+
+ Excel\Drawings\Style\IXLDrawingProperties.cs
+
+
+ Excel\Drawings\Style\IXLDrawingProtection.cs
+
+
+ Excel\Drawings\Style\IXLDrawingSize.cs
+
+
+ Excel\Drawings\Style\IXLDrawingStyle.cs
+
+
+ Excel\Drawings\Style\IXLDrawingWeb.cs
+
+
+ Excel\Drawings\Style\XLDrawingAlignment.cs
+
+
+ Excel\Drawings\Style\XLDrawingColorsAndLines.cs
+
+
+ Excel\Drawings\Style\XLDrawingFont.cs
+
+
+ Excel\Drawings\Style\XLDrawingMargins.cs
+
+
+ Excel\Drawings\Style\XLDrawingProperties.cs
+
+
+ Excel\Drawings\Style\XLDrawingProtection.cs
+
+
+ Excel\Drawings\Style\XLDrawingSize.cs
+
+
+ Excel\Drawings\Style\XLDrawingStyle.cs
+
+
+ Excel\Drawings\Style\XLDrawingWeb.cs
+
Excel\Drawings\XLDrawing.cs