diff --git a/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj b/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj index a5e8c9b..183c99e 100644 --- a/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj +++ b/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj @@ -38,7 +38,7 @@ False - ..\..\..\My Documents\Code\OX.Copyable\havard-copyable-fd863c3\OX.Copyable\bin\Release\OX.Copyable.dll + ..\..\..\OX.Copyable\OX.Copyable\bin\Release\OX.Copyable.dll diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLAlignment.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLAlignment.cs index f1d4715..f45c633 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLAlignment.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLAlignment.cs @@ -39,7 +39,7 @@ XLAlignmentVerticalValues Vertical { get; set; } - UInt32 Indent { get; set; } + Int32 Indent { get; set; } Boolean JustifyLastLine { get; set; } @@ -49,7 +49,7 @@ Boolean ShrinkToFit { get; set; } - UInt32 TextRotation { get; set; } + Int32 TextRotation { get; set; } Boolean WrapText { get; set; } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLNumberFormat.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLNumberFormat.cs index 7e86c68..256e92b 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLNumberFormat.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLNumberFormat.cs @@ -7,7 +7,7 @@ { public interface IXLNumberFormat { - UInt32? NumberFormatId { get; set; } + Int32 NumberFormatId { get; set; } String Format { get; set; } } } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLAlignment.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLAlignment.cs index 20dd845..36af17d 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLAlignment.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLAlignment.cs @@ -7,24 +7,227 @@ { public class XLAlignment: IXLAlignment { - public XLAlignmentHorizontalValues Horizontal { get; set; } + IXLStylized container; + public XLAlignment(IXLStylized container, IXLAlignment d = null) + { + this.container = container; + if (d != null) + { + Horizontal = d.Horizontal; + Vertical = d.Vertical; + Indent = d.Indent; + JustifyLastLine = d.JustifyLastLine; + ReadingOrder = d.ReadingOrder; + RelativeIndent = d.RelativeIndent; + ShrinkToFit = d.ShrinkToFit; + TextRotation = d.TextRotation; + WrapText = d.WrapText; + TopToBottom = d.TopToBottom; + } + } - public XLAlignmentVerticalValues Vertical { get; set; } + private XLAlignmentHorizontalValues horizontal; + public XLAlignmentHorizontalValues Horizontal + { + get + { + return horizontal; + } + set + { + Boolean updateIndent = !( + value == XLAlignmentHorizontalValues.Left + || value == XLAlignmentHorizontalValues.Right + || value == XLAlignmentHorizontalValues.Distributed + ); - public uint Indent { get; set; } + if (container != null && !container.UpdatingStyle) + { + container.Styles.ForEach(s => { + s.Alignment.Horizontal = value; + if (updateIndent) + s.Alignment.Indent = 0; + }); + } + else + { + horizontal = value; + if (updateIndent) + indent = 0; + } + } + } - public bool JustifyLastLine { get; set; } + private XLAlignmentVerticalValues vertical; + public XLAlignmentVerticalValues Vertical + { + get + { + return vertical; + } + set + { + if (container != null && !container.UpdatingStyle) + container.Styles.ForEach(s => s.Alignment.Vertical = value); + else + vertical = value; + } + } - public XLAlignmentReadingOrderValues ReadingOrder { get; set; } + private Int32 indent; + public Int32 Indent + { + get + { + return indent; + } + set + { + if (value > 0 && !( + Horizontal == XLAlignmentHorizontalValues.Left + || Horizontal == XLAlignmentHorizontalValues.Right + || Horizontal == XLAlignmentHorizontalValues.Distributed + )) + { + throw new ArgumentException("For indents, only left, right, and distributed horizontal alignments are supported."); + } - public int RelativeIndent { get; set; } + if (container != null && !container.UpdatingStyle) + container.Styles.ForEach(s => s.Alignment.Indent = value); + else + indent = value; + } + } - public bool ShrinkToFit { get; set; } + private Boolean justifyLastLine; + public Boolean JustifyLastLine + { + get + { + return justifyLastLine; + } + set + { + if (container != null && !container.UpdatingStyle) + container.Styles.ForEach(s => s.Alignment.JustifyLastLine = value); + else + justifyLastLine = value; + } + } - public uint TextRotation { get; set; } + private XLAlignmentReadingOrderValues readingOrder; + public XLAlignmentReadingOrderValues ReadingOrder + { + get + { + return readingOrder; + } + set + { + if (container != null && !container.UpdatingStyle) + container.Styles.ForEach(s => s.Alignment.ReadingOrder = value); + else + readingOrder = value; + } + } - public bool WrapText { get; set; } + private Int32 relativeIndent; + public Int32 RelativeIndent + { + get + { + return relativeIndent; + } + set + { + if (container != null && !container.UpdatingStyle) + container.Styles.ForEach(s => s.Alignment.RelativeIndent = value); + else + relativeIndent = value; + } + } - public bool TopToBottom { get; set; } + private Boolean shrinkToFit; + public Boolean ShrinkToFit + { + get + { + return shrinkToFit; + } + set + { + if (container != null && !container.UpdatingStyle) + container.Styles.ForEach(s => s.Alignment.ShrinkToFit = value); + else + shrinkToFit = value; + } + } + + private Int32 textRotation; + public Int32 TextRotation + { + get + { + return textRotation; + } + set + { + if ( value != 255 && (value < 0 || value > 180) ) + throw new ArgumentException("TextRotation must be between 0 and 180 degrees, or 255."); + + if (container != null && !container.UpdatingStyle) + container.Styles.ForEach(s => s.Alignment.TextRotation = value); + else + textRotation = value; + } + } + + private Boolean wrapText; + public Boolean WrapText + { + get + { + return wrapText; + } + set + { + if (container != null && !container.UpdatingStyle) + container.Styles.ForEach(s => s.Alignment.WrapText = value); + else + wrapText = value; + } + } + + private Boolean topToBottom; + public Boolean TopToBottom + { + get + { + return textRotation == 255; + } + set + { + if (container != null && !container.UpdatingStyle) + container.Styles.ForEach(s => s.Alignment.TextRotation = value ? 255 : 0 ); + else + textRotation = value ? 255 : 0; + } + } + + + public override string ToString() + { + return + Horizontal.ToString() + + "-" + Vertical.ToString() + + "-" + Indent.ToString() + + "-" + JustifyLastLine.ToString() + + "-" + ReadingOrder.ToString() + + "-" + RelativeIndent.ToString() + + "-" + ShrinkToFit.ToString() + + "-" + TextRotation.ToString() + + "-" + WrapText.ToString() + ; + } } } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLBorder.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLBorder.cs index 7345d99..8178777 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLBorder.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLBorder.cs @@ -7,28 +7,235 @@ { public class XLBorder: IXLBorder { - public XLBorderStyleValues LeftBorder { get; set; } + IXLStylized container; + public XLBorder(IXLStylized container, IXLBorder defaultBorder = null) + { + this.container = container; + if (defaultBorder != null) + { + LeftBorder = defaultBorder.LeftBorder; + LeftBorderColor = defaultBorder.LeftBorderColor; + RightBorder = defaultBorder.RightBorder; + RightBorderColor = defaultBorder.RightBorderColor; + TopBorder = defaultBorder.TopBorder; + TopBorderColor = defaultBorder.TopBorderColor; + BottomBorder = defaultBorder.BottomBorder; + BottomBorderColor = defaultBorder.BottomBorderColor; + DiagonalBorder = defaultBorder.DiagonalBorder; + DiagonalBorderColor = defaultBorder.DiagonalBorderColor; + DiagonalUp = defaultBorder.DiagonalUp; + DiagonalDown = defaultBorder.DiagonalDown; + } + } - public Color LeftBorderColor { get; set; } + private XLBorderStyleValues leftBorder; + public XLBorderStyleValues LeftBorder + { + get + { + return leftBorder; + } + set + { + if (container != null && !container.UpdatingStyle) + container.Styles.ForEach(s => s.Border.LeftBorder = value); + else + leftBorder = value; + } + } - public XLBorderStyleValues RightBorder { get; set; } + private Color leftBorderColor; + public Color LeftBorderColor + { + get + { + return leftBorderColor; + } + set + { + if (container != null && !container.UpdatingStyle) + container.Styles.ForEach(s => s.Border.LeftBorderColor = value); + else + leftBorderColor = value; + } + } - public Color RightBorderColor { get; set; } + private XLBorderStyleValues rightBorder; + public XLBorderStyleValues RightBorder + { + get + { + return rightBorder; + } + set + { + if (container != null && !container.UpdatingStyle) + container.Styles.ForEach(s => s.Border.RightBorder = value); + else + rightBorder = value; + } + } - public XLBorderStyleValues TopBorder { get; set; } + private Color rightBorderColor; + public Color RightBorderColor + { + get + { + return rightBorderColor; + } + set + { + if (container != null && !container.UpdatingStyle) + container.Styles.ForEach(s => s.Border.RightBorderColor = value); + else + rightBorderColor = value; + } + } - public Color TopBorderColor { get; set; } + private XLBorderStyleValues topBorder; + public XLBorderStyleValues TopBorder + { + get + { + return topBorder; + } + set + { + if (container != null && !container.UpdatingStyle) + container.Styles.ForEach(s => s.Border.TopBorder = value); + else + topBorder = value; + } + } - public XLBorderStyleValues BottomBorder { get; set; } + private Color topBorderColor; + public Color TopBorderColor + { + get + { + return topBorderColor; + } + set + { + if (container != null && !container.UpdatingStyle) + container.Styles.ForEach(s => s.Border.TopBorderColor = value); + else + topBorderColor = value; + } + } - public Color BottomBorderColor { get; set; } + private XLBorderStyleValues bottomBorder; + public XLBorderStyleValues BottomBorder + { + get + { + return bottomBorder; + } + set + { + if (container != null && !container.UpdatingStyle) + container.Styles.ForEach(s => s.Border.BottomBorder = value); + else + bottomBorder = value; + } + } - public bool DiagonalUp { get; set; } + private Color bottomBorderColor; + public Color BottomBorderColor + { + get + { + return bottomBorderColor; + } + set + { + if (container != null && !container.UpdatingStyle) + container.Styles.ForEach(s => s.Border.BottomBorderColor = value); + else + bottomBorderColor = value; + } + } - public bool DiagonalDown { get; set; } + private XLBorderStyleValues diagonalBorder; + public XLBorderStyleValues DiagonalBorder + { + get + { + return diagonalBorder; + } + set + { + if (container != null && !container.UpdatingStyle) + container.Styles.ForEach(s => s.Border.DiagonalBorder = value); + else + diagonalBorder = value; + } + } - public XLBorderStyleValues DiagonalBorder { get; set; } + private Color diagonalBorderColor; + public Color DiagonalBorderColor + { + get + { + return diagonalBorderColor; + } + set + { + if (container != null && !container.UpdatingStyle) + container.Styles.ForEach(s => s.Border.DiagonalBorderColor = value); + else + diagonalBorderColor = value; + } + } - public Color DiagonalBorderColor { get; set; } + private Boolean diagonalUp; + public Boolean DiagonalUp + { + get + { + return diagonalUp; + } + set + { + if (container != null && !container.UpdatingStyle) + container.Styles.ForEach(s => s.Border.DiagonalUp = value); + else + diagonalUp = value; + } + } + + private Boolean diagonalDown; + public Boolean DiagonalDown + { + get + { + return diagonalDown; + } + set + { + if (container != null && !container.UpdatingStyle) + container.Styles.ForEach(s => s.Border.DiagonalDown = value); + else + diagonalDown = value; + } + } + + public override string ToString() + { + return + LeftBorder.ToString() + "-" + + LeftBorderColor.ToString() + "-" + + RightBorder.ToString() + "-" + + RightBorderColor.ToString() + "-" + + TopBorder.ToString() + "-" + + TopBorderColor.ToString() + "-" + + BottomBorder.ToString() + "-" + + BottomBorderColor.ToString() + "-" + + DiagonalBorder.ToString() + "-" + + DiagonalBorderColor.ToString() + "-" + + DiagonalUp.ToString() + "-" + + DiagonalDown.ToString(); + + } } } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLNumberFormat.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLNumberFormat.cs index e3e6c35..cbfd052 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLNumberFormat.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLNumberFormat.cs @@ -7,8 +7,71 @@ { public class XLNumberFormat: IXLNumberFormat { - public uint? NumberFormatId { get; set; } + #region Properties - public string Format { get; set; } + IXLStylized container; + + private Int32 numberFormatId; + public Int32 NumberFormatId + { + get { return numberFormatId; } + set + { + if (container != null && !container.UpdatingStyle) + { + container.Styles.ForEach(s => s.NumberFormat.NumberFormatId = value); + } + else + { + numberFormatId = value; + format = String.Empty; + } + } + } + + private String format = String.Empty; + public String Format + { + get { return format; } + set + { + if (container != null && !container.UpdatingStyle) + { + container.Styles.ForEach(s => s.NumberFormat.Format = value); + } + else + { + format = value; + numberFormatId = -1; + } + } + } + + #endregion + + #region Constructors + + public XLNumberFormat(IXLStylized container, IXLNumberFormat defaultNumberFormat = null) + { + this.container = container; + if (defaultNumberFormat != null) + { + if (defaultNumberFormat.NumberFormatId >= 0) + NumberFormatId = defaultNumberFormat.NumberFormatId; + else + Format = defaultNumberFormat.Format; + } + } + + #endregion + + #region Overridden + + public override string ToString() + { + return numberFormatId.ToString() + "-" + format.ToString(); + } + + #endregion } } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook.cs index b08d49a..aa41ba6 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook.cs @@ -61,45 +61,46 @@ Strikethrough = false, VerticalAlignment = XLFontVerticalTextAlignmentValues.Baseline, FontSize = 11, - FontColor = Color.FromArgb(0,0,0), + FontColor = Color.FromArgb(0, 0, 0), FontName = "Calibri", FontFamilyNumbering = XLFontFamilyNumberingValues.Swiss - } - , Alignment = new XLAlignment(), Border = new XLBorder(), NumberFormat = new XLNumberFormat(), - Fill = new XLFill(null) - { - BackgroundColor = Color.FromArgb(255,255,255), - PatternType = XLFillPatternValues.None, - PatternColor = Color.FromArgb(255, 255, 255) - } - //Border = new XLBorder(null) - // { - // BottomBorder = BorderStyleValues.None, - // DiagonalBorder = BorderStyleValues.None, - // DiagonalDown = false, - // DiagonalUp = false, - // LeftBorder = BorderStyleValues.None, - // RightBorder = BorderStyleValues.None, - // TopBorder = BorderStyleValues.None, - // BottomBorderColor = "000000", - // DiagonalBorderColor = "000000", - // LeftBorderColor = "000000", - // RightBorderColor = "000000", - // TopBorderColor = "000000" - // }, - //NumberFormat = new XLNumberFormat(0), - //Alignment = new XLAlignment(null) - // { - // Horizontal = HorizontalAlignmentValues.General, - // Indent = 0, - // JustifyLastLine = false, - // ReadingOrder = OPReadingOrders.ContextDependent, - // RelativeIndent = 0, - // ShrinkToFit = false, - // TextRotation = 0, - // Vertical = VerticalAlignmentValues.Bottom, - // WrapText = false - // } + }, + + Fill = new XLFill(null) + { + BackgroundColor = Color.FromArgb(255, 255, 255), + PatternType = XLFillPatternValues.None, + PatternColor = Color.FromArgb(255, 255, 255) + }, + + Border = new XLBorder(null) + { + BottomBorder = XLBorderStyleValues.None, + DiagonalBorder = XLBorderStyleValues.None, + DiagonalDown = false, + DiagonalUp = false, + LeftBorder = XLBorderStyleValues.None, + RightBorder = XLBorderStyleValues.None, + TopBorder = XLBorderStyleValues.None, + BottomBorderColor = Color.Black, + DiagonalBorderColor = Color.Black, + LeftBorderColor = Color.Black, + RightBorderColor = Color.Black, + TopBorderColor = Color.Black + }, + NumberFormat = new XLNumberFormat(null) { NumberFormatId = 0 }, + Alignment = new XLAlignment(null) + { + Horizontal = XLAlignmentHorizontalValues.General, + Indent = 0, + JustifyLastLine = false, + ReadingOrder = XLAlignmentReadingOrderValues.ContextDependent, + RelativeIndent = 0, + ShrinkToFit = false, + TextRotation = 0, + Vertical = XLAlignmentVerticalValues.Bottom, + WrapText = false + } }; } return defaultStyle; diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs index 79795d5..7c0e3ba 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs @@ -24,7 +24,7 @@ private struct FontInfo { public UInt32 FontId; public IXLFont Font; }; private struct FillInfo { public UInt32 FillId; public IXLFill Fill; }; private struct BorderInfo { public UInt32 BorderId; public IXLBorder Border; }; - private struct NumberFormatInfo { public UInt32 NumberFormatId; public IXLNumberFormat NumberFormat; }; + private struct NumberFormatInfo { public Int32 NumberFormatId; public IXLNumberFormat NumberFormat; }; private struct StyleInfo @@ -33,7 +33,7 @@ public UInt32 FontId; public UInt32 FillId; public UInt32 BorderId; - public UInt32 NumberFormatId; + public Int32 NumberFormatId; public IXLStyle Style; }; @@ -349,7 +349,7 @@ UInt32 fontCount = 1; UInt32 fillCount = 3; UInt32 borderCount = 1; - UInt32 numberFormatCount = 1; + Int32 numberFormatCount = 1; foreach (var worksheet in Worksheets) { @@ -370,7 +370,7 @@ sharedBorders.Add(cell.Style.Border.ToString(), new BorderInfo() { BorderId = borderCount++, Border = cell.Style.Border }); } - if (!cell.Style.NumberFormat.NumberFormatId.HasValue && !sharedNumberFormats.ContainsKey(cell.Style.NumberFormat.ToString())) + if (cell.Style.NumberFormat.NumberFormatId == -1 && !sharedNumberFormats.ContainsKey(cell.Style.NumberFormat.ToString())) { sharedNumberFormats.Add(cell.Style.NumberFormat.ToString(), new NumberFormatInfo() { NumberFormatId = numberFormatCount + 164, NumberFormat = cell.Style.NumberFormat }); //cell.Style.NumberFormat = new OPNumberFormat(numberFormatCount); @@ -383,9 +383,9 @@ if (!sharedStyles.ContainsKey(cell.Style.ToString())) { - UInt32 numberFormatId; - if (cell.Style.NumberFormat.NumberFormatId.HasValue) - numberFormatId = cell.Style.NumberFormat.NumberFormatId.Value; + Int32 numberFormatId; + if (cell.Style.NumberFormat.NumberFormatId >= 0) + numberFormatId = cell.Style.NumberFormat.NumberFormatId; else numberFormatId = sharedNumberFormats[cell.Style.NumberFormat.ToString()].NumberFormatId; @@ -405,10 +405,10 @@ Stylesheet stylesheet1 = new Stylesheet(); - NumberingFormats numberingFormats = new NumberingFormats() { Count = (UInt32Value)numberFormatCount }; + NumberingFormats numberingFormats = new NumberingFormats() { Count = (UInt32Value)(UInt32)numberFormatCount }; foreach (var numberFormatInfo in sharedNumberFormats.Values) { - NumberingFormat numberingFormat = new NumberingFormat() { NumberFormatId = (UInt32Value)numberFormatInfo.NumberFormatId, FormatCode = numberFormatInfo.NumberFormat.Format }; + NumberingFormat numberingFormat = new NumberingFormat() { NumberFormatId = (UInt32Value)(UInt32)numberFormatInfo.NumberFormatId, FormatCode = numberFormatInfo.NumberFormat.Format }; numberingFormats.Append(numberingFormat); } @@ -526,18 +526,18 @@ || GetBorderStyleValue(opBorder.LeftBorder) != BorderStyleValues.None || GetBorderStyleValue(opBorder.TopBorder) != BorderStyleValues.None); - CellFormat cellStyleFormat = new CellFormat() { NumberFormatId = (UInt32Value)numberFormatId, FontId = (UInt32Value)fontId, FillId = (UInt32Value)fillId, BorderId = (UInt32Value)borderId, ApplyNumberFormat = false, ApplyFill = applyFill, ApplyBorder = applyBorder, ApplyAlignment = false, ApplyProtection = false }; + CellFormat cellStyleFormat = new CellFormat() { NumberFormatId = (UInt32Value)(UInt32)numberFormatId, FontId = (UInt32Value)fontId, FillId = (UInt32Value)fillId, BorderId = (UInt32Value)borderId, ApplyNumberFormat = false, ApplyFill = applyFill, ApplyBorder = applyBorder, ApplyAlignment = false, ApplyProtection = false }; cellStyleFormats.Append(cellStyleFormat); - CellFormat cellFormat = new CellFormat() { NumberFormatId = (UInt32Value)numberFormatId, FontId = (UInt32Value)fontId, FillId = (UInt32Value)fillId, BorderId = (UInt32Value)borderId, FormatId = (UInt32Value)formatId, ApplyNumberFormat = false, ApplyFill = applyFill, ApplyBorder = applyBorder, ApplyAlignment = false, ApplyProtection = false }; + CellFormat cellFormat = new CellFormat() { NumberFormatId = (UInt32Value)(UInt32)numberFormatId, FontId = (UInt32Value)fontId, FillId = (UInt32Value)fillId, BorderId = (UInt32Value)borderId, FormatId = (UInt32Value)formatId, ApplyNumberFormat = false, ApplyFill = applyFill, ApplyBorder = applyBorder, ApplyAlignment = false, ApplyProtection = false }; Alignment alignment = new Alignment() { Horizontal = GetHorizontalAlignmentValue(styleInfo.Style.Alignment.Horizontal), Vertical = GetVerticalAlignmentValue(styleInfo.Style.Alignment.Vertical), - Indent = styleInfo.Style.Alignment.Indent, + Indent = (UInt32)styleInfo.Style.Alignment.Indent, ReadingOrder = (UInt32)styleInfo.Style.Alignment.ReadingOrder, WrapText = styleInfo.Style.Alignment.WrapText, - TextRotation = styleInfo.Style.Alignment.TextRotation, + TextRotation = (UInt32)styleInfo.Style.Alignment.TextRotation, ShrinkToFit = styleInfo.Style.Alignment.ShrinkToFit, RelativeIndent = styleInfo.Style.Alignment.RelativeIndent, JustifyLastLine = styleInfo.Style.Alignment.JustifyLastLine diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.csproj b/ClosedXML/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.csproj index 4b4e9ba..5cd4bfc 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.csproj +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.csproj @@ -52,9 +52,11 @@ + + diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Program.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Program.cs index 72c7d50..48cdad6 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Examples/Program.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Program.cs @@ -17,7 +17,11 @@ //new StyleFill().Create(@"c:\styleFill.xlsx"); - new StyleBorder().Create(@"c:\styleBorder.xlsx"); + //new StyleBorder().Create(@"c:\styleBorder.xlsx"); + + //new StyleAlignment().Create(@"c:\styleAlignment.xlsx"); + + new StyleNumberFormat().Create(@"c:\styleNumberFormat.xlsx"); //var basicTable = new BasicTable(); //basicTable.Create(@"c:\BasicTable.xlsx"); diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleAlignment.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleAlignment.cs new file mode 100644 index 0000000..6699c5f --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleAlignment.cs @@ -0,0 +1,110 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using ClosedXML.Excel; +using ClosedXML.Excel.Style; + +namespace ClosedXML_Examples.Styles +{ + public class StyleAlignment + { + #region Variables + + // Public + + // Private + + + #endregion + + #region Properties + + // Public + + // Private + + // Override + + + #endregion + + #region Constructors + + // Public + public StyleAlignment() + { + + } + + + // Private + + + #endregion + + #region Events + + // Public + + // Private + + // Override + + + #endregion + + #region Methods + + // Public + public void Create(String filePath) + { + var workbook = new XLWorkbook(); + var ws = workbook.Worksheets.Add("Style Alignment"); + + var co = 2; + var ro = 1; + + ws.Cell(++ro, co).Value = "Horizontal = Right"; + ws.Cell(ro, co).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + + ws.Cell(++ro, co).Value = "Indent = 2"; + ws.Cell(ro, co).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + ws.Cell(ro, co).Style.Alignment.Indent = 2; + + ws.Cell(++ro, co).Value = "JustifyLastLine = true"; + ws.Cell(ro, co).Style.Alignment.JustifyLastLine = true; + + ws.Cell(++ro, co).Value = "ReadingOrder = ContextDependent"; + ws.Cell(ro, co).Style.Alignment.ReadingOrder = XLAlignmentReadingOrderValues.ContextDependent; + + ws.Cell(++ro, co).Value = "RelativeIndent = 2"; + ws.Cell(ro, co).Style.Alignment.RelativeIndent = 2; + + ws.Cell(++ro, co).Value = "ShrinkToFit = true"; + ws.Cell(ro, co).Style.Alignment.ShrinkToFit = true; + + ws.Cell(++ro, co).Value = "TextRotation = 45"; + ws.Cell(ro, co).Style.Alignment.TextRotation = 45; + + ws.Cell(++ro, co).Value = "TopToBottom = true"; + ws.Cell(ro, co).Style.Alignment.TopToBottom = true; + + ws.Cell(++ro, co).Value = "Vertical = Center"; + ws.Cell(ro, co).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + + ws.Cell(++ro, co).Value = "WrapText = true"; + ws.Cell(ro, co).Style.Alignment.WrapText = true; + + + workbook.SaveAs(filePath); + } + + // Private + + // Override + + + #endregion + } +} diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleBorder.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleBorder.cs index 45f05b2..a0c467f 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleBorder.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleBorder.cs @@ -22,30 +22,30 @@ ws.Cell(ro, co).Style.Border.BottomBorder = XLBorderStyleValues.Thick; ws.Cell(ro, co).Style.Border.BottomBorderColor = Color.Red; - ws.Cell(++ro, co).Value = "TopBorder = Thick; TopBorderColor = Red"; - ws.Cell(ro, co).Style.Border.TopBorder = XLBorderStyleValues.Thick; - ws.Cell(ro, co).Style.Border.TopBorderColor = Color.Red; - ws.Cell(++ro, co).Value = "LeftBorder = Thick; LeftBorderColor = Red"; ws.Cell(ro, co).Style.Border.LeftBorder = XLBorderStyleValues.Thick; ws.Cell(ro, co).Style.Border.LeftBorderColor = Color.Red; + ws.Cell(++ro, co).Value = "TopBorder = Thick; TopBorderColor = Red"; + ws.Cell(ro, co).Style.Border.TopBorder = XLBorderStyleValues.Thick; + ws.Cell(ro, co).Style.Border.TopBorderColor = Color.Red; + ws.Cell(++ro, co).Value = "RightBorder = Thick; RightBorderColor = Red"; ws.Cell(ro, co).Style.Border.RightBorder = XLBorderStyleValues.Thick; ws.Cell(ro, co).Style.Border.RightBorderColor = Color.Red; - ws.Cell(++ro, co).Value = "DiagonalBorder = Thick; DiagonalBorderColor = Red; DiagonalUp = true"; - ws.Cell(ro, co).Style.Border.DiagonalBorder = XLBorderStyleValues.Thick; + ws.Cell(++ro, co).Value = "DiagonalBorder = Thin; DiagonalBorderColor = Red; DiagonalUp = true"; + ws.Cell(ro, co).Style.Border.DiagonalBorder = XLBorderStyleValues.Thin; ws.Cell(ro, co).Style.Border.DiagonalBorderColor = Color.Red; ws.Cell(ro, co).Style.Border.DiagonalUp = true; - ws.Cell(++ro, co).Value = "DiagonalBorder = Thick; DiagonalBorderColor = Red; DiagonalDown = true"; - ws.Cell(ro, co).Style.Border.DiagonalBorder = XLBorderStyleValues.Thick; + ws.Cell(++ro, co).Value = "DiagonalBorder = Thin; DiagonalBorderColor = Red; DiagonalDown = true"; + ws.Cell(ro, co).Style.Border.DiagonalBorder = XLBorderStyleValues.Thin; ws.Cell(ro, co).Style.Border.DiagonalBorderColor = Color.Red; ws.Cell(ro, co).Style.Border.DiagonalDown = true; - ws.Cell(++ro, co).Value = "DiagonalBorder = Thick; DiagonalBorderColor = Red; DiagonalUp = true; DiagonalDown = true"; - ws.Cell(ro, co).Style.Border.DiagonalBorder = XLBorderStyleValues.Thick; + ws.Cell(++ro, co).Value = "DiagonalBorder = Thin; DiagonalBorderColor = Red; DiagonalUp = true; DiagonalDown = true"; + ws.Cell(ro, co).Style.Border.DiagonalBorder = XLBorderStyleValues.Thin; ws.Cell(ro, co).Style.Border.DiagonalBorderColor = Color.Red; ws.Cell(ro, co).Style.Border.DiagonalUp = true; ws.Cell(ro, co).Style.Border.DiagonalDown = true; diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleNumberFormat.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleNumberFormat.cs new file mode 100644 index 0000000..bb31c2b --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleNumberFormat.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using ClosedXML.Excel; + +namespace ClosedXML_Examples.Styles +{ + public class StyleNumberFormat + { + #region Variables + + // Public + + // Private + + + #endregion + + #region Properties + + // Public + + // Private + + // Override + + + #endregion + + #region Constructors + + // Public + public StyleNumberFormat() + { + + } + + + // Private + + + #endregion + + #region Events + + // Public + + // Private + + // Override + + + #endregion + + #region Methods + + // Public + public void Create(String filePath) + { + var workbook = new XLWorkbook(); + var ws = workbook.Worksheets.Add("Style NumberFormat"); + + var co = 2; + var ro = 1; + + ws.Cell(++ro, co).Value = "123456.789"; + ws.Cell(ro, co).Style.NumberFormat.Format = "$ #,##0.00"; + + ws.Cell(++ro, co).Value = "12.345"; + ws.Cell(ro, co).Style.NumberFormat.Format = "$ #,##0.00"; + + ws.Cell(++ro, co).Value = "12.345"; + ws.Cell(ro, co).Style.NumberFormat.NumberFormatId = 3; + + workbook.SaveAs(filePath); + } + + // Private + + // Override + + + #endregion + } +}