diff --git a/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj b/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj
index 9fc6cdb..2a68e33 100644
--- a/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj
+++ b/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj
@@ -66,6 +66,7 @@
+
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/IXLCell.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/IXLCell.cs
index e339fb6..9ef9c20 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/IXLCell.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/IXLCell.cs
@@ -8,7 +8,7 @@
{
public enum XLCellValues { Text, Number, Boolean, DateTime, TimeSpan }
- public interface IXLCell: IXLStylized
+ public interface IXLCell
{
///
/// Gets or sets the cell's value. To get a strongly typed object use the method GetValue<T>.
@@ -116,5 +116,7 @@
/// Returns this cell as an IXLRange.
///
IXLRange AsRange();
+
+ IXLStyle Style { get; set; }
}
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/IXLCells.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/IXLCells.cs
index 2c3a0a1..4ee70e2 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/IXLCells.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/IXLCells.cs
@@ -5,7 +5,7 @@
namespace ClosedXML.Excel
{
- public interface IXLCells : IEnumerable, IXLStylized
+ public interface IXLCells : IEnumerable
{
///
/// Sets the cells' value.
@@ -51,5 +51,7 @@
///
/// The formula with R1C1 references.
String FormulaR1C1 { set; }
+
+ IXLStyle Style { get; set; }
}
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell.cs
index 2160735..3c072d2 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell.cs
@@ -9,15 +9,18 @@
namespace ClosedXML.Excel
{
- internal class XLCell : IXLCell
+ internal class XLCell : IXLCell, IXLStylized
{
public static readonly DateTime baseDate = new DateTime(1899, 12, 30);
XLWorksheet worksheet;
public XLCell(IXLAddress address, IXLStyle defaultStyle, XLWorksheet worksheet)
{
this.Address = address;
- Style = defaultStyle;
- if (Style == null) Style = worksheet.Style;
+
+ if (defaultStyle == null)
+ style = new XLStyle(this, worksheet.Style);
+ else
+ style = new XLStyle(this, defaultStyle);
this.worksheet = worksheet;
}
@@ -133,7 +136,7 @@
return format;
}
- private String cellValue = String.Empty;
+ internal String cellValue = String.Empty;
public Object Value
{
get
@@ -201,17 +204,8 @@
{
var sourceCell = (XLCell)asRange.Cell(ro, co);
var targetCell = (XLCell)worksheet.Cell(Address.RowNumber + ro - 1, Address.ColumnNumber + co - 1);
- if (!targetCell.Style.Equals(sourceCell.Style))
- targetCell.Style = sourceCell.Style;
-
- if (targetCell.InnerText != sourceCell.InnerText)
- targetCell.Value = sourceCell.Value;
-
- if (targetCell.DataType != sourceCell.DataType)
- targetCell.DataType = sourceCell.DataType;
-
- if (targetCell.FormulaA1 != sourceCell.FormulaA1)
- targetCell.FormulaA1 = sourceCell.FormulaA1;
+ targetCell.CopyValues(sourceCell);
+ targetCell.Style = sourceCell.style;
}
}
var rangesToMerge = new List();
@@ -400,6 +394,12 @@
public Boolean UpdatingStyle { get; set; }
+ public IXLStyle InnerStyle
+ {
+ get { return style; }
+ set { style = new XLStyle(this, value); }
+ }
+
#endregion
private XLCellValues dataType;
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCells.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCells.cs
index 08f719d..92dd533 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCells.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCells.cs
@@ -5,37 +5,89 @@
namespace ClosedXML.Excel
{
- internal class XLCells: IXLCells
+ internal class XLCells : IXLCells, IXLStylized
{
- private Boolean entireWorksheet;
private XLWorksheet worksheet;
- public XLCells(XLWorksheet worksheet, Boolean entireWorksheet = false)
+ private Boolean usedCellsOnly;
+ private Boolean includeStyles;
+ public XLCells(XLWorksheet worksheet, Boolean entireWorksheet, Boolean usedCellsOnly, Boolean includeStyles)
{
this.worksheet = worksheet;
- this.entireWorksheet = entireWorksheet;
- Style = worksheet.Style;
+ this.style = new XLStyle(this, worksheet.Style);
+ this.usedCellsOnly = usedCellsOnly;
+ this.includeStyles = includeStyles;
}
- private List cells = new List();
+ private List rangeAddresses = new List();
public IEnumerator GetEnumerator()
{
- var retList = new List();
- cells.ForEach(c => retList.Add(c));
- return retList.GetEnumerator();
+ HashSet usedCells;
+ Boolean multipleRanges = rangeAddresses.Count > 1;
+
+ if (multipleRanges)
+ usedCells = new HashSet();
+ else
+ usedCells = null;
+
+
+ if (usedCellsOnly)
+ {
+ var cells = from c in worksheet.Internals.CellsCollection
+ where ( !StringExtensions.IsNullOrWhiteSpace(c.Value.InnerText)
+ || (includeStyles && !c.Value.Style.Equals(worksheet.Style)))
+ && rangeAddresses.Where(r=>
+ r.FirstAddress.RowNumber <= c.Key.RowNumber
+ && r.FirstAddress.ColumnNumber <= c.Key.ColumnNumber
+ && r.LastAddress.RowNumber >= c.Key.RowNumber
+ && r.LastAddress.ColumnNumber >= c.Key.ColumnNumber
+ ).Any()
+ select (IXLCell)c.Value;
+ foreach (var cell in cells)
+ {
+ yield return cell;
+ }
+ }
+ else
+ {
+ foreach (var range in rangeAddresses)
+ {
+ Int32 firstRo = range.FirstAddress.RowNumber;
+ Int32 lastRo = range.LastAddress.RowNumber;
+ Int32 firstCo = range.FirstAddress.ColumnNumber;
+ Int32 lastCo = range.LastAddress.ColumnNumber;
+
+ for (Int32 ro = firstRo; ro <= lastRo; ro++)
+ {
+ for (Int32 co = firstCo; co <= lastCo; co++)
+ {
+ var cell = worksheet.Cell(ro, co);
+ if (multipleRanges)
+ {
+ if (!usedCells.Contains(cell.Address))
+ {
+ usedCells.Add(cell.Address);
+ yield return cell;
+ }
+ }
+ else
+ {
+ yield return cell;
+ }
+ }
+ }
+ }
+ }
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
- public void Add(XLCell cell)
+ public void Add(IXLRangeAddress rangeAddress)
{
- cells.Add(cell);
+ rangeAddresses.Add(rangeAddress);
}
- public void AddRange(IEnumerable cellsToAdd)
- {
- cells.AddRange(cellsToAdd);
- }
+
#region IXLStylized Members
@@ -49,21 +101,7 @@
set
{
style = new XLStyle(this, value);
-
- if (entireWorksheet)
- {
- worksheet.Style = value;
- }
- else
- {
- var maxRow = 0;
- if (worksheet.Internals.RowsCollection.Count > 0)
- maxRow = worksheet.Internals.RowsCollection.Keys.Max();
- foreach (var c in cells)
- {
- c.Style = value;
- }
- }
+ this.ForEach(c => c.Style = style);
}
}
@@ -73,33 +111,27 @@
{
UpdatingStyle = true;
yield return style;
- if (entireWorksheet)
- {
- yield return worksheet.Style;
- }
- else
- {
- var maxRow = 0;
- if (worksheet.Internals.RowsCollection.Count > 0)
- maxRow = worksheet.Internals.RowsCollection.Keys.Max();
- foreach (var c in cells)
- {
- yield return c.Style;
- }
- }
+ foreach (var c in this)
+ yield return c.Style;
UpdatingStyle = false;
}
}
public Boolean UpdatingStyle { get; set; }
+ public IXLStyle InnerStyle
+ {
+ get { return style; }
+ set { style = new XLStyle(this, value); }
+ }
+
#endregion
public Object Value
{
set
{
- cells.ForEach(c => c.Value = value);
+ this.ForEach(c => c.Value = value);
}
}
@@ -107,25 +139,25 @@
{
set
{
- cells.ForEach(c => c.DataType = value);
+ this.ForEach(c => c.DataType = value);
}
}
public void Clear()
{
- cells.ForEach(c => c.Clear());
+ this.ForEach(c => c.Clear());
}
public void ClearStyles()
{
- cells.ForEach(c => c.ClearStyles());
+ this.ForEach(c => c.ClearStyles());
}
public String FormulaA1
{
set
{
- cells.ForEach(c => c.FormulaA1 = value);
+ this.ForEach(c => c.FormulaA1 = value);
}
}
@@ -133,7 +165,7 @@
{
set
{
- cells.ForEach(c => c.FormulaR1C1 = value);
+ this.ForEach(c => c.FormulaR1C1 = value);
}
}
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Columns/IXLColumns.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Columns/IXLColumns.cs
index 08c3c34..6b77717 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Columns/IXLColumns.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Columns/IXLColumns.cs
@@ -5,7 +5,7 @@
namespace ClosedXML.Excel
{
- public interface IXLColumns: IEnumerable, IXLStylized
+ public interface IXLColumns: IEnumerable
{
///
/// Sets the width of all columns.
@@ -102,5 +102,7 @@
///
/// if set to true will return all cells with a value or a style different than the default.
IXLCells CellsUsed(Boolean includeStyles);
+
+ IXLStyle Style { get; set; }
}
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Columns/XLColumn.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Columns/XLColumn.cs
index e439724..f843fd5 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Columns/XLColumn.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Columns/XLColumn.cs
@@ -105,11 +105,11 @@
public IXLCells Cells(String cellsInColumn)
{
- var retVal = new XLCells(Worksheet);
+ var retVal = new XLCells(Worksheet, false, false, false);
var rangePairs = cellsInColumn.Split(',');
foreach (var pair in rangePairs)
{
- retVal.AddRange(Range(pair.Trim()).Cells());
+ retVal.Add(Range(pair.Trim()).RangeAddress);
}
return retVal;
}
@@ -170,7 +170,7 @@
{
UpdatingStyle = true;
- yield return Style;
+ yield return style;
var co = this.ColumnNumber();
@@ -194,6 +194,28 @@
public override Boolean UpdatingStyle { get; set; }
+ public override IXLStyle InnerStyle
+ {
+ get
+ {
+ if (IsReference)
+ return Worksheet.Internals.ColumnsCollection[this.ColumnNumber()].InnerStyle;
+ else
+ return new XLStyle(new XLStylizedContainer(this.style, this), style);
+ }
+ set
+ {
+ if (IsReference)
+ {
+ Worksheet.Internals.ColumnsCollection[this.ColumnNumber()].InnerStyle = value;
+ }
+ else
+ {
+ style = new XLStyle(this, value);
+ }
+ }
+ }
+
#endregion
public new void InsertColumnsAfter(Int32 numberOfColumns)
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Columns/XLColumns.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Columns/XLColumns.cs
index 5761f7d..08b45cc 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Columns/XLColumns.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Columns/XLColumns.cs
@@ -5,7 +5,7 @@
namespace ClosedXML.Excel
{
- internal class XLColumns: IXLColumns
+ internal class XLColumns : IXLColumns, IXLStylized
{
private Boolean entireWorksheet;
private XLWorksheet worksheet;
@@ -13,7 +13,7 @@
{
this.worksheet = worksheet;
this.entireWorksheet = entireWorksheet;
- Style = worksheet.Style;
+ style = new XLStyle(this, worksheet.Style);
}
List columns = new List();
@@ -104,6 +104,12 @@
public Boolean UpdatingStyle { get; set; }
+ public IXLStyle InnerStyle
+ {
+ get { return style; }
+ set { style = new XLStyle(this, value); }
+ }
+
#endregion
public Double Width
@@ -199,55 +205,31 @@
public IXLCells Cells()
{
- var cellHash = new HashSet();
+ var cells = new XLCells(worksheet, false, false, false);
foreach (var container in columns)
{
- foreach (var cell in container.Cells())
- {
- if (!cellHash.Contains(cell))
- {
- cellHash.Add(cell);
- }
- }
+ cells.Add(container.RangeAddress);
}
- var cells = new XLCells(worksheet, entireWorksheet);
- cells.AddRange(cellHash);
return (IXLCells)cells;
}
public IXLCells CellsUsed()
{
- var cellHash = new HashSet();
+ var cells = new XLCells(worksheet, false, true, false);
foreach (var container in columns)
{
- foreach (var cell in container.CellsUsed())
- {
- if (!cellHash.Contains(cell))
- {
- cellHash.Add(cell);
- }
- }
+ cells.Add(container.RangeAddress);
}
- var cells = new XLCells(worksheet, entireWorksheet);
- cells.AddRange(cellHash);
return (IXLCells)cells;
}
public IXLCells CellsUsed(Boolean includeStyles)
{
- var cellHash = new HashSet();
+ var cells = new XLCells(worksheet, false, true, includeStyles);
foreach (var container in columns)
{
- foreach (var cell in container.CellsUsed(includeStyles))
- {
- if (!cellHash.Contains(cell))
- {
- cellHash.Add(cell);
- }
- }
+ cells.Add(container.RangeAddress);
}
- var cells = new XLCells(worksheet, entireWorksheet);
- cells.AddRange(cellHash);
return (IXLCells)cells;
}
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/IXLRangeBase.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/IXLRangeBase.cs
index be60613..752a7ae 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/IXLRangeBase.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/IXLRangeBase.cs
@@ -7,7 +7,7 @@
{
public enum XLScope { Workbook, Worksheet };
- public interface IXLRangeBase: IXLStylized
+ public interface IXLRangeBase
{
///
/// Returns the collection of cells.
@@ -144,5 +144,7 @@
/// Converts this object to a range.
///
IXLRange AsRange();
+
+ IXLStyle Style { get; set; }
}
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/IXLRangeColumns.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/IXLRangeColumns.cs
index 80babb1..5f36c2c 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/IXLRangeColumns.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/IXLRangeColumns.cs
@@ -5,7 +5,7 @@
namespace ClosedXML.Excel
{
- public interface IXLRangeColumns: IEnumerable, IXLStylized
+ public interface IXLRangeColumns: IEnumerable
{
///
/// Clears the contents of the columns (including styles).
@@ -38,5 +38,7 @@
/// Deletes all columns and shifts the columns at the right of them accordingly.
///
void Delete();
+
+ IXLStyle Style { get; set; }
}
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/IXLRangeRows.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/IXLRangeRows.cs
index 33ebcb1..8095e0a 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/IXLRangeRows.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/IXLRangeRows.cs
@@ -5,7 +5,7 @@
namespace ClosedXML.Excel
{
- public interface IXLRangeRows: IEnumerable, IXLStylized
+ public interface IXLRangeRows: IEnumerable
{
///
/// Adds a row range to this group.
@@ -37,5 +37,7 @@
/// Deletes all rows and shifts the rows below them accordingly.
///
void Delete();
+
+ IXLStyle Style { get; set; }
}
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/IXLRanges.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/IXLRanges.cs
index 18cb224..262b6cb 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/IXLRanges.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/IXLRanges.cs
@@ -5,7 +5,7 @@
namespace ClosedXML.Excel
{
- public interface IXLRanges: IEnumerable, IXLStylized
+ public interface IXLRanges: IEnumerable
{
///
/// Clears the contents of the ranges (including styles).
@@ -22,6 +22,6 @@
/// The range to remove from this group.
void Remove(IXLRange range);
-
+ IXLStyle Style { get; set; }
}
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeBase.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeBase.cs
index bc1c648..1f7c42f 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeBase.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeBase.cs
@@ -5,7 +5,7 @@
namespace ClosedXML.Excel
{
- internal abstract class XLRangeBase : IXLRangeBase
+ internal abstract class XLRangeBase : IXLRangeBase, IXLStylized
{
public XLRangeBase(IXLRangeAddress rangeAddress)
{
@@ -222,40 +222,20 @@
}
public IXLCells Cells()
{
- var cellHash = new HashSet();
- foreach (var row in Enumerable.Range(1, this.RowCount()))
- {
- foreach (var column in Enumerable.Range(1, this.ColumnCount()))
- {
- cellHash.Add(this.Cell(row, column));
- }
- }
- var cells = new XLCells(Worksheet);
- cells.AddRange(cellHash);
+ var cells = new XLCells(Worksheet, false, false, false);
+ cells.Add(this.RangeAddress);
return (IXLCells)cells;
}
public IXLCells CellsUsed()
{
- var list = this.Worksheet.Internals.CellsCollection.Where(c => !StringExtensions.IsNullOrWhiteSpace(c.Value.InnerText) && this.Contains(c.Key.ToString())).Select(c => (IXLCell)c.Value);
- var cells = new XLCells(Worksheet);
- cells.AddRange(list.AsEnumerable());
+ var cells = new XLCells(Worksheet, false, true, false);
+ cells.Add(this.RangeAddress);
return (IXLCells)cells;
}
public IXLCells CellsUsed(Boolean includeStyles)
{
- IEnumerable list;
- if (includeStyles)
- list = this.Worksheet.Internals.CellsCollection.Where(c =>
- (!StringExtensions.IsNullOrWhiteSpace(c.Value.InnerText) || !c.Value.Style.Equals(Worksheet.Style))
- && this.Contains(c.Key.ToString())
- ).Select(c => (IXLCell)c.Value);
- else
- list = this.Worksheet.Internals.CellsCollection.Where(c =>
- !StringExtensions.IsNullOrWhiteSpace(c.Value.InnerText)
- && this.Contains(c.Key.ToString())
- ).Select(c => (IXLCell)c.Value);
- var cells = new XLCells(Worksheet);
- cells.AddRange(list);
+ var cells = new XLCells(Worksheet, false, true, includeStyles);
+ cells.Add(this.RangeAddress);
return (IXLCells)cells;
}
@@ -552,7 +532,7 @@
{
foreach (var cell in CellsUsed(true))
{
- var newStyle = new XLStyle(cell, Worksheet.Style);
+ var newStyle = new XLStyle((XLCell)cell, Worksheet.Style);
newStyle.NumberFormat = cell.Style.NumberFormat;
cell.Style = newStyle;
}
@@ -710,6 +690,12 @@
public virtual Boolean UpdatingStyle { get; set; }
+ public virtual IXLStyle InnerStyle
+ {
+ get { return this.defaultStyle; }
+ set { defaultStyle = new XLStyle(this, value); }
+ }
+
#endregion
public virtual IXLRange AsRange()
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeColumn.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeColumn.cs
index 451a9be..cb3c023 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeColumn.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeColumn.cs
@@ -33,11 +33,11 @@
public IXLCells Cells(String cellsInColumn)
{
- var retVal = new XLCells(Worksheet);
+ var retVal = new XLCells(Worksheet, false, false, false);
var rangePairs = cellsInColumn.Split(',');
foreach (var pair in rangePairs)
{
- retVal.AddRange(Range(pair.Trim()).Cells());
+ retVal.Add(Range(pair.Trim()).RangeAddress);
}
return retVal;
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeColumns.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeColumns.cs
index 1886aca..75bad0c 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeColumns.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeColumns.cs
@@ -5,12 +5,12 @@
namespace ClosedXML.Excel
{
- internal class XLRangeColumns : IXLRangeColumns
+ internal class XLRangeColumns : IXLRangeColumns, IXLStylized
{
XLWorksheet worksheet;
public XLRangeColumns(XLWorksheet worksheet)
{
- Style = worksheet.Style;
+ style = new XLStyle(this, worksheet.Style);
this.worksheet = worksheet;
}
@@ -85,60 +85,42 @@
public Boolean UpdatingStyle { get; set; }
+ public IXLStyle InnerStyle
+ {
+ get { return style; }
+ set { style = new XLStyle(this, value); }
+ }
+
#endregion
public IXLCells Cells()
{
- var cellHash = new HashSet();
+ var cells = new XLCells(worksheet, false, false, false);
foreach (var container in ranges)
{
- foreach (var cell in container.Cells())
- {
- if (!cellHash.Contains(cell))
- {
- cellHash.Add(cell);
- }
- }
+ cells.Add(container.RangeAddress);
}
- var cells = new XLCells(worksheet);
- cells.AddRange(cellHash);
return (IXLCells)cells;
}
public IXLCells CellsUsed()
{
- var cellHash = new HashSet();
+ var cells = new XLCells(worksheet, false, true, false);
foreach (var container in ranges)
{
- foreach (var cell in container.CellsUsed())
- {
- if (!cellHash.Contains(cell))
- {
- cellHash.Add(cell);
- }
- }
+ cells.Add(container.RangeAddress);
}
- var cells = new XLCells(worksheet);
- cells.AddRange(cellHash);
return (IXLCells)cells;
}
public IXLCells CellsUsed(Boolean includeStyles)
{
- var cellHash = new HashSet();
+ var cells = new XLCells(worksheet, false, true, includeStyles);
foreach (var container in ranges)
{
- foreach (var cell in container.CellsUsed(includeStyles))
- {
- if (!cellHash.Contains(cell))
- {
- cellHash.Add(cell);
- }
- }
+ cells.Add(container.RangeAddress);
}
- var cells = new XLCells(worksheet);
- cells.AddRange(cellHash);
return (IXLCells)cells;
}
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeRow.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeRow.cs
index 965e90f..ab4a559 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeRow.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeRow.cs
@@ -66,11 +66,11 @@
public IXLCells Cells(String cellsInRow)
{
- var retVal = new XLCells(Worksheet);
+ var retVal = new XLCells(Worksheet, false, false, false);
var rangePairs = cellsInRow.Split(',');
foreach (var pair in rangePairs)
{
- retVal.AddRange(Range(pair.Trim()).Cells());
+ retVal.Add(Range(pair.Trim()).RangeAddress);
}
return retVal;
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeRows.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeRows.cs
index 2149332..245a1a5 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeRows.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRangeRows.cs
@@ -5,12 +5,12 @@
namespace ClosedXML.Excel
{
- internal class XLRangeRows : IXLRangeRows
+ internal class XLRangeRows : IXLRangeRows, IXLStylized
{
XLWorksheet worksheet;
public XLRangeRows(XLWorksheet worksheet)
{
- Style = worksheet.Style;
+ style = new XLStyle(this, worksheet.Style);
this.worksheet = worksheet;
}
@@ -85,59 +85,41 @@
public Boolean UpdatingStyle { get; set; }
+ public IXLStyle InnerStyle
+ {
+ get { return style; }
+ set { style = new XLStyle(this, value); }
+ }
+
#endregion
public IXLCells Cells()
{
- var cellHash = new HashSet();
+ var cells = new XLCells(worksheet, false, false, false);
foreach (var container in ranges)
{
- foreach (var cell in container.Cells())
- {
- if (!cellHash.Contains(cell))
- {
- cellHash.Add(cell);
- }
- }
+ cells.Add(container.RangeAddress);
}
- var cells = new XLCells(worksheet);
- cells.AddRange(cellHash);
return (IXLCells)cells;
}
public IXLCells CellsUsed()
{
- var cellHash = new HashSet();
+ var cells = new XLCells(worksheet, false, true, false);
foreach (var container in ranges)
{
- foreach (var cell in container.CellsUsed())
- {
- if (!cellHash.Contains(cell))
- {
- cellHash.Add(cell);
- }
- }
+ cells.Add(container.RangeAddress);
}
- var cells = new XLCells(worksheet);
- cells.AddRange(cellHash);
return (IXLCells)cells;
}
public IXLCells CellsUsed(Boolean includeStyles)
{
- var cellHash = new HashSet();
+ var cells = new XLCells(worksheet, false, true, includeStyles);
foreach (var container in ranges)
{
- foreach (var cell in container.CellsUsed(includeStyles))
- {
- if (!cellHash.Contains(cell))
- {
- cellHash.Add(cell);
- }
- }
+ cells.Add(container.RangeAddress);
}
- var cells = new XLCells(worksheet);
- cells.AddRange(cellHash);
return (IXLCells)cells;
}
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRanges.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRanges.cs
index d24fd7c..2c85a9f 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRanges.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Ranges/XLRanges.cs
@@ -5,7 +5,7 @@
namespace ClosedXML.Excel
{
- internal class XLRanges : IXLRanges
+ internal class XLRanges : IXLRanges, IXLStylized
{
private XLWorkbook workbook;
public XLRanges(XLWorkbook workbook, IXLStyle defaultStyle)
@@ -94,6 +94,12 @@
public Boolean UpdatingStyle { get; set; }
+ public IXLStyle InnerStyle
+ {
+ get { return style; }
+ set { style = new XLStyle(this, value); }
+ }
+
#endregion
public override string ToString()
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Rows/IXLRows.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Rows/IXLRows.cs
index 55445dc..a8d3233 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Rows/IXLRows.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Rows/IXLRows.cs
@@ -5,7 +5,7 @@
namespace ClosedXML.Excel
{
- public interface IXLRows: IEnumerable, IXLStylized
+ public interface IXLRows: IEnumerable
{
///
/// Sets the height of all rows.
@@ -102,5 +102,7 @@
///
/// if set to true will return all cells with a value or a style different than the default.
IXLCells CellsUsed(Boolean includeStyles);
+
+ IXLStyle Style { get; set; }
}
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Rows/XLRow.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Rows/XLRow.cs
index 1befc4d..cd7eabc 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Rows/XLRow.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Rows/XLRow.cs
@@ -133,11 +133,11 @@
public IXLCells Cells(String cellsInRow)
{
- var retVal = new XLCells(Worksheet);
+ var retVal = new XLCells(Worksheet, false, false, false);
var rangePairs = cellsInRow.Split(',');
foreach (var pair in rangePairs)
{
- retVal.AddRange(Range(pair.Trim()).Cells());
+ retVal.Add(Range(pair.Trim()).RangeAddress);
}
return retVal;
}
@@ -317,7 +317,7 @@
{
UpdatingStyle = true;
- yield return Style;
+ yield return style;
var row = this.RowNumber();
@@ -341,6 +341,28 @@
public override Boolean UpdatingStyle { get; set; }
+ public override IXLStyle InnerStyle
+ {
+ get
+ {
+ if (IsReference)
+ return Worksheet.Internals.RowsCollection[this.RowNumber()].InnerStyle;
+ else
+ return new XLStyle(new XLStylizedContainer(this.style, this), style);
+ }
+ set
+ {
+ if (IsReference)
+ {
+ Worksheet.Internals.RowsCollection[this.RowNumber()].InnerStyle = value;
+ }
+ else
+ {
+ style = new XLStyle(this, value);
+ }
+ }
+ }
+
public override IXLRange AsRange()
{
return Range(1, 1, 1, XLWorksheet.MaxNumberOfColumns);
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Rows/XLRows.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Rows/XLRows.cs
index 482bb91..df5d39a 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Rows/XLRows.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Rows/XLRows.cs
@@ -5,7 +5,7 @@
namespace ClosedXML.Excel
{
- internal class XLRows: IXLRows
+ internal class XLRows : IXLRows, IXLStylized
{
private Boolean entireWorksheet;
private XLWorksheet worksheet;
@@ -13,7 +13,7 @@
{
this.worksheet = worksheet;
this.entireWorksheet = entireWorksheet;
- Style = worksheet.Style;
+ style = new XLStyle(this, worksheet.Style);
}
List rows = new List();
@@ -107,6 +107,12 @@
public Boolean UpdatingStyle { get; set; }
+ public IXLStyle InnerStyle
+ {
+ get { return style; }
+ set { style = new XLStyle(this, value); }
+ }
+
#endregion
public double Height
@@ -201,55 +207,31 @@
public IXLCells Cells()
{
- var cellHash = new HashSet();
+ var cells = new XLCells(worksheet, false, false, false);
foreach (var container in rows)
{
- foreach (var cell in container.Cells())
- {
- if (!cellHash.Contains(cell))
- {
- cellHash.Add(cell);
- }
- }
+ cells.Add(container.RangeAddress);
}
- var cells = new XLCells(worksheet, entireWorksheet);
- cells.AddRange(cellHash);
return (IXLCells)cells;
}
public IXLCells CellsUsed()
{
- var cellHash = new HashSet();
+ var cells = new XLCells(worksheet, false, true, false);
foreach (var container in rows)
{
- foreach (var cell in container.CellsUsed())
- {
- if (!cellHash.Contains(cell))
- {
- cellHash.Add(cell);
- }
- }
+ cells.Add(container.RangeAddress);
}
- var cells = new XLCells(worksheet, entireWorksheet);
- cells.AddRange(cellHash);
return (IXLCells)cells;
}
public IXLCells CellsUsed(Boolean includeStyles)
{
- var cellHash = new HashSet();
+ var cells = new XLCells(worksheet, false, true, includeStyles);
foreach (var container in rows)
{
- foreach (var cell in container.CellsUsed(includeStyles))
- {
- if (!cellHash.Contains(cell))
- {
- cellHash.Add(cell);
- }
- }
+ cells.Add(container.RangeAddress);
}
- var cells = new XLCells(worksheet, entireWorksheet);
- cells.AddRange(cellHash);
return (IXLCells)cells;
}
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLStylized.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLStylized.cs
index 2fdeb4f..c0b0642 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLStylized.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLStylized.cs
@@ -5,10 +5,11 @@
namespace ClosedXML.Excel
{
- public interface IXLStylized
+ internal interface IXLStylized
{
IXLStyle Style { get; set; }
IEnumerable Styles { get; }
Boolean UpdatingStyle { get; set; }
+ IXLStyle InnerStyle { get; set; }
}
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLStylizedContainer.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLStylizedContainer.cs
new file mode 100644
index 0000000..3b758f5
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLStylizedContainer.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ClosedXML.Excel
+{
+ internal class XLStylizedContainer: IXLStylized
+ {
+ IXLStylized container;
+ public XLStylizedContainer(IXLStyle style, IXLStylized container)
+ {
+ this.Style = style;
+ this.container = container;
+ }
+
+ public IXLStyle Style { get; set; }
+
+ public IEnumerable Styles
+ {
+ get
+ {
+ container.UpdatingStyle = true;
+ yield return Style;
+ container.UpdatingStyle = false;
+ }
+ }
+
+ public bool UpdatingStyle { get; set; }
+
+ public IXLStyle InnerStyle { get; set; }
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Tables/IXLTableRows.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Tables/IXLTableRows.cs
index 678574b..da52ae3 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Tables/IXLTableRows.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Tables/IXLTableRows.cs
@@ -5,7 +5,7 @@
namespace ClosedXML.Excel
{
- public interface IXLTableRows: IEnumerable, IXLStylized
+ public interface IXLTableRows: IEnumerable
{
///
/// Adds a table row to this group.
@@ -33,5 +33,7 @@
///
/// if set to true will return all cells with a value or a style different than the default.
IXLCells CellsUsed(Boolean includeStyles);
+
+ IXLStyle Style { get; set; }
}
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Tables/XLTableRows.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Tables/XLTableRows.cs
index 067ac83..bbc63d7 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Tables/XLTableRows.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Tables/XLTableRows.cs
@@ -5,12 +5,12 @@
namespace ClosedXML.Excel
{
- internal class XLTableRows: IXLTableRows
+ internal class XLTableRows : IXLTableRows, IXLStylized
{
XLWorksheet worksheet;
public XLTableRows(XLWorksheet worksheet)
{
- Style = worksheet.Style;
+ style = new XLStyle(this, worksheet.Style);
this.worksheet = worksheet;
}
@@ -79,59 +79,41 @@
public Boolean UpdatingStyle { get; set; }
+ public IXLStyle InnerStyle
+ {
+ get { return style; }
+ set { style = new XLStyle(this, value); }
+ }
+
#endregion
public IXLCells Cells()
{
- var cellHash = new HashSet();
+ var cells = new XLCells(worksheet, false, false, false);
foreach (var container in ranges)
{
- foreach (var cell in container.Cells())
- {
- if (!cellHash.Contains(cell))
- {
- cellHash.Add(cell);
- }
- }
+ cells.Add(container.RangeAddress);
}
- var cells = new XLCells(worksheet);
- cells.AddRange(cellHash);
return (IXLCells)cells;
}
public IXLCells CellsUsed()
{
- var cellHash = new HashSet();
+ var cells = new XLCells(worksheet, false, true, false);
foreach (var container in ranges)
{
- foreach (var cell in container.CellsUsed())
- {
- if (!cellHash.Contains(cell))
- {
- cellHash.Add(cell);
- }
- }
+ cells.Add(container.RangeAddress);
}
- var cells = new XLCells(worksheet);
- cells.AddRange(cellHash);
return (IXLCells)cells;
}
public IXLCells CellsUsed(Boolean includeStyles)
{
- var cellHash = new HashSet();
+ var cells = new XLCells(worksheet, false, false, includeStyles);
foreach (var container in ranges)
{
- foreach (var cell in container.CellsUsed(includeStyles))
- {
- if (!cellHash.Contains(cell))
- {
- cellHash.Add(cell);
- }
- }
+ cells.Add(container.RangeAddress);
}
- var cells = new XLCells(worksheet);
- cells.AddRange(cellHash);
return (IXLCells)cells;
}
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Load.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Load.cs
index c75d095..1e3838c 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Load.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Load.cs
@@ -137,8 +137,7 @@
//IXLStylized toApply;
if (col.Max != XLWorksheet.MaxNumberOfColumns)
{
- var toApply = ws.Columns(col.Min, col.Max);
- var xlColumns = (XLColumns)toApply;
+ var xlColumns = (XLColumns)ws.Columns(col.Min, col.Max);
if (col.Width != null)
xlColumns.Width = col.Width;
else
@@ -156,7 +155,7 @@
Int32 styleIndex = col.Style != null ? Int32.Parse(col.Style.InnerText) : -1;
if (styleIndex > 0)
{
- ApplyStyle(toApply, styleIndex, s, fills, borders, fonts, numberingFormats);
+ ApplyStyle(xlColumns, styleIndex, s, fills, borders, fonts, numberingFormats);
}
else
{
@@ -167,7 +166,7 @@
foreach (var row in worksheetPart.Worksheet.Descendants()) //.Where(r => r.CustomFormat != null && r.CustomFormat).Select(r => r))
{
- var xlRow = ws.Row((Int32)row.RowIndex.Value, false);
+ var xlRow = (XLRow)ws.Row((Int32)row.RowIndex.Value, false);
if (row.Height != null)
xlRow.Height = row.Height;
else
@@ -206,7 +205,7 @@
var dCell = (Cell)cell;
Int32 styleIndex = dCell.StyleIndex != null ? Int32.Parse(dCell.StyleIndex.InnerText) : 0;
- var xlCell = ws.CellFast(dCell.CellReference);
+ var xlCell = (XLCell)ws.CellFast(dCell.CellReference);
if (styleIndex > 0)
{
@@ -232,13 +231,13 @@
if (dCell.CellValue != null)
{
if (!StringExtensions.IsNullOrWhiteSpace(dCell.CellValue.Text))
- xlCell.Value = sharedStrings[Int32.Parse(dCell.CellValue.Text)].InnerText;
+ xlCell.cellValue = sharedStrings[Int32.Parse(dCell.CellValue.Text)].InnerText;
else
- xlCell.Value = dCell.CellValue.Text;
+ xlCell.cellValue = dCell.CellValue.Text;
}
else
{
- xlCell.Value = String.Empty;
+ xlCell.cellValue = String.Empty;
}
xlCell.DataType = XLCellValues.Text;
}
@@ -561,13 +560,14 @@
if (fill.PatternFill != null)
{
if (fill.PatternFill.PatternType != null)
- xlStylized.Style.Fill.PatternType = fillPatternValues.Single(p => p.Value == fill.PatternFill.PatternType).Key;
+ xlStylized.InnerStyle.Fill.PatternType = fillPatternValues.Single(p => p.Value == fill.PatternFill.PatternType).Key;
var fgColor = GetColor(fill.PatternFill.ForegroundColor);
- if (fgColor.HasValue) xlStylized.Style.Fill.PatternColor = fgColor;
+ if (fgColor.HasValue) xlStylized.InnerStyle.Fill.PatternColor = fgColor;
var bgColor = GetColor(fill.PatternFill.BackgroundColor);
- if (bgColor.HasValue) xlStylized.Style.Fill.PatternBackgroundColor = bgColor;
+ if (bgColor.HasValue)
+ xlStylized.InnerStyle.Fill.PatternBackgroundColor = bgColor;
}
}
@@ -580,23 +580,23 @@
if (alignment != null)
{
if (alignment.Horizontal != null)
- xlStylized.Style.Alignment.Horizontal = alignmentHorizontalValues.Single(a => a.Value == alignment.Horizontal).Key;
+ xlStylized.InnerStyle.Alignment.Horizontal = alignmentHorizontalValues.Single(a => a.Value == alignment.Horizontal).Key;
if (alignment.Indent != null)
- xlStylized.Style.Alignment.Indent = Int32.Parse(alignment.Indent.ToString());
+ xlStylized.InnerStyle.Alignment.Indent = Int32.Parse(alignment.Indent.ToString());
if (alignment.JustifyLastLine != null)
- xlStylized.Style.Alignment.JustifyLastLine = alignment.JustifyLastLine;
+ xlStylized.InnerStyle.Alignment.JustifyLastLine = alignment.JustifyLastLine;
if (alignment.ReadingOrder != null)
- xlStylized.Style.Alignment.ReadingOrder = (XLAlignmentReadingOrderValues)Int32.Parse(alignment.ReadingOrder.ToString());
+ xlStylized.InnerStyle.Alignment.ReadingOrder = (XLAlignmentReadingOrderValues)Int32.Parse(alignment.ReadingOrder.ToString());
if (alignment.RelativeIndent != null)
- xlStylized.Style.Alignment.RelativeIndent = alignment.RelativeIndent;
+ xlStylized.InnerStyle.Alignment.RelativeIndent = alignment.RelativeIndent;
if (alignment.ShrinkToFit != null)
- xlStylized.Style.Alignment.ShrinkToFit = alignment.ShrinkToFit;
+ xlStylized.InnerStyle.Alignment.ShrinkToFit = alignment.ShrinkToFit;
if (alignment.TextRotation != null)
- xlStylized.Style.Alignment.TextRotation = (Int32)alignment.TextRotation.Value;
+ xlStylized.InnerStyle.Alignment.TextRotation = (Int32)alignment.TextRotation.Value;
if (alignment.Vertical != null)
- xlStylized.Style.Alignment.Vertical = alignmentVerticalValues.Single(a => a.Value == alignment.Vertical).Key;
+ xlStylized.InnerStyle.Alignment.Vertical = alignmentVerticalValues.Single(a => a.Value == alignment.Vertical).Key;
if (alignment.WrapText !=null)
- xlStylized.Style.Alignment.WrapText = alignment.WrapText;
+ xlStylized.InnerStyle.Alignment.WrapText = alignment.WrapText;
}
@@ -611,51 +611,51 @@
if (bottomBorder != null)
{
if (bottomBorder.Style != null)
- xlStylized.Style.Border.BottomBorder = borderStyleValues.Single(b => b.Value == bottomBorder.Style.Value).Key;
+ xlStylized.InnerStyle.Border.BottomBorder = borderStyleValues.Single(b => b.Value == bottomBorder.Style.Value).Key;
var bottomBorderColor = GetColor(bottomBorder.Color);
if (bottomBorderColor.HasValue)
- xlStylized.Style.Border.BottomBorderColor = bottomBorderColor;
+ xlStylized.InnerStyle.Border.BottomBorderColor = bottomBorderColor;
}
var topBorder = (TopBorder)border.TopBorder;
if (topBorder != null)
{
if (topBorder.Style != null)
- xlStylized.Style.Border.TopBorder = borderStyleValues.Single(b => b.Value == topBorder.Style.Value).Key;
+ xlStylized.InnerStyle.Border.TopBorder = borderStyleValues.Single(b => b.Value == topBorder.Style.Value).Key;
var topBorderColor = GetColor(topBorder.Color);
if (topBorderColor.HasValue)
- xlStylized.Style.Border.TopBorderColor = topBorderColor;
+ xlStylized.InnerStyle.Border.TopBorderColor = topBorderColor;
}
var leftBorder = (LeftBorder)border.LeftBorder;
if (leftBorder != null)
{
if (leftBorder.Style != null)
- xlStylized.Style.Border.LeftBorder = borderStyleValues.Single(b => b.Value == leftBorder.Style.Value).Key;
+ xlStylized.InnerStyle.Border.LeftBorder = borderStyleValues.Single(b => b.Value == leftBorder.Style.Value).Key;
var leftBorderColor = GetColor(leftBorder.Color);
if (leftBorderColor.HasValue)
- xlStylized.Style.Border.LeftBorderColor = leftBorderColor;
+ xlStylized.InnerStyle.Border.LeftBorderColor = leftBorderColor;
}
var rightBorder = (RightBorder)border.RightBorder;
if (rightBorder != null)
{
if (rightBorder.Style != null)
- xlStylized.Style.Border.RightBorder = borderStyleValues.Single(b => b.Value == rightBorder.Style.Value).Key;
+ xlStylized.InnerStyle.Border.RightBorder = borderStyleValues.Single(b => b.Value == rightBorder.Style.Value).Key;
var rightBorderColor = GetColor(rightBorder.Color);
if (rightBorderColor.HasValue)
- xlStylized.Style.Border.RightBorderColor = rightBorderColor;
+ xlStylized.InnerStyle.Border.RightBorderColor = rightBorderColor;
}
var diagonalBorder = (DiagonalBorder)border.DiagonalBorder;
if (diagonalBorder != null)
{
if (diagonalBorder.Style != null)
- xlStylized.Style.Border.DiagonalBorder = borderStyleValues.Single(b => b.Value == diagonalBorder.Style.Value).Key;
+ xlStylized.InnerStyle.Border.DiagonalBorder = borderStyleValues.Single(b => b.Value == diagonalBorder.Style.Value).Key;
var diagonalBorderColor = GetColor(diagonalBorder.Color);
if (diagonalBorderColor.HasValue)
- xlStylized.Style.Border.DiagonalBorderColor = diagonalBorderColor;
+ xlStylized.InnerStyle.Border.DiagonalBorderColor = diagonalBorderColor;
if (border.DiagonalDown != null)
- xlStylized.Style.Border.DiagonalDown = border.DiagonalDown;
+ xlStylized.InnerStyle.Border.DiagonalDown = border.DiagonalDown;
if (border.DiagonalUp != null)
- xlStylized.Style.Border.DiagonalUp = border.DiagonalUp;
+ xlStylized.InnerStyle.Border.DiagonalUp = border.DiagonalUp;
}
}
@@ -666,41 +666,41 @@
var font = (Font)fonts.ElementAt((Int32)fontId.Value);
if (font != null)
{
- xlStylized.Style.Font.Bold = GetBoolean(font.Bold);
+ xlStylized.InnerStyle.Font.Bold = GetBoolean(font.Bold);
var fontColor = GetColor(font.Color);
if (fontColor.HasValue)
- xlStylized.Style.Font.FontColor = fontColor;
+ xlStylized.InnerStyle.Font.FontColor = fontColor;
if (font.FontFamilyNumbering != null && ((FontFamilyNumbering)font.FontFamilyNumbering).Val != null)
- xlStylized.Style.Font.FontFamilyNumbering = (XLFontFamilyNumberingValues)Int32.Parse(((FontFamilyNumbering)font.FontFamilyNumbering).Val.ToString());
+ xlStylized.InnerStyle.Font.FontFamilyNumbering = (XLFontFamilyNumberingValues)Int32.Parse(((FontFamilyNumbering)font.FontFamilyNumbering).Val.ToString());
if (font.FontName != null)
{
if (((FontName)font.FontName).Val != null)
- xlStylized.Style.Font.FontName = ((FontName)font.FontName).Val;
+ xlStylized.InnerStyle.Font.FontName = ((FontName)font.FontName).Val;
}
if (font.FontSize != null)
{
if (((FontSize)font.FontSize).Val != null)
- xlStylized.Style.Font.FontSize = ((FontSize)font.FontSize).Val;
+ xlStylized.InnerStyle.Font.FontSize = ((FontSize)font.FontSize).Val;
}
- xlStylized.Style.Font.Italic = GetBoolean(font.Italic);
- xlStylized.Style.Font.Shadow = GetBoolean(font.Shadow);
- xlStylized.Style.Font.Strikethrough = GetBoolean(font.Strike);
+ xlStylized.InnerStyle.Font.Italic = GetBoolean(font.Italic);
+ xlStylized.InnerStyle.Font.Shadow = GetBoolean(font.Shadow);
+ xlStylized.InnerStyle.Font.Strikethrough = GetBoolean(font.Strike);
if (font.Underline != null)
if (font.Underline.Val != null)
- xlStylized.Style.Font.Underline = underlineValuesList.Single(u => u.Value == ((Underline)font.Underline).Val).Key;
+ xlStylized.InnerStyle.Font.Underline = underlineValuesList.Single(u => u.Value == ((Underline)font.Underline).Val).Key;
else
- xlStylized.Style.Font.Underline = XLFontUnderlineValues.Single;
+ xlStylized.InnerStyle.Font.Underline = XLFontUnderlineValues.Single;
if (font.VerticalTextAlignment != null)
if (font.VerticalTextAlignment.Val != null)
- xlStylized.Style.Font.VerticalAlignment = fontVerticalTextAlignmentValues.Single(f => f.Value == ((VerticalTextAlignment)font.VerticalTextAlignment).Val).Key;
+ xlStylized.InnerStyle.Font.VerticalAlignment = fontVerticalTextAlignmentValues.Single(f => f.Value == ((VerticalTextAlignment)font.VerticalTextAlignment).Val).Key;
else
- xlStylized.Style.Font.VerticalAlignment = XLFontVerticalTextAlignmentValues.Baseline;
+ xlStylized.InnerStyle.Font.VerticalAlignment = XLFontVerticalTextAlignmentValues.Baseline;
}
if (s.CellFormats != null)
{
@@ -720,9 +720,9 @@
}
}
if (formatCode.Length > 0)
- xlStylized.Style.NumberFormat.Format = formatCode;
+ xlStylized.InnerStyle.NumberFormat.Format = formatCode;
else
- xlStylized.Style.NumberFormat.NumberFormatId = (Int32)numberFormatId.Value;
+ xlStylized.InnerStyle.NumberFormat.NumberFormatId = (Int32)numberFormatId.Value;
}
}
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs
index 07c9da1..9ae3941 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs
@@ -2119,11 +2119,17 @@
OleObjects oleObjects = worksheetPart.Worksheet.Elements().FirstOrDefault();
#endregion
+ #region Controls
+ Controls controls = worksheetPart.Worksheet.Elements().FirstOrDefault();
+ #endregion
+
#region Tables
worksheetPart.Worksheet.RemoveAllChildren();
{
OpenXmlElement previousElement;
- if (oleObjects != null)
+ if (controls != null)
+ previousElement = controls;
+ else if (oleObjects != null)
previousElement = oleObjects;
else if (legacyDrawingHF != null)
previousElement = legacyDrawingHF;
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorksheet.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorksheet.cs
index dfd5cd1..98dcd9d 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorksheet.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorksheet.cs
@@ -30,7 +30,7 @@
SheetView = new XLSheetView();
Tables = new XLTables();
this.workbook = workbook;
- Style = workbook.Style;
+ style = new XLStyle(this, workbook.Style);
Internals = new XLWorksheetInternals(new XLCellCollection(), new XLColumnsCollection(), new XLRowsCollection(), new XLRanges(workbook, workbook.Style) , workbook);
PageSetup = new XLPageSetup(workbook.PageOptions, this);
Outline = new XLOutline(workbook.Outline);
@@ -118,6 +118,8 @@
set
{
style = new XLStyle(this, value);
+ foreach(var cell in Internals.CellsCollection.Values)
+ cell.Style = style;
}
}
@@ -137,6 +139,12 @@
public override Boolean UpdatingStyle { get; set; }
+ public override IXLStyle InnerStyle
+ {
+ get { return new XLStyle(new XLStylizedContainer(this.style, this), style); }
+ set { style = new XLStyle(this, value); }
+ }
+
#endregion
public Double ColumnWidth { get; set; }
diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Loading/LoadFiles.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Loading/LoadFiles.cs
index d3aab18..2b3ef6e 100644
--- a/ClosedXML/ClosedXML/ClosedXML_Examples/Loading/LoadFiles.cs
+++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Loading/LoadFiles.cs
@@ -21,7 +21,7 @@
LoadAndSaveFile(forLoadingFolder + @"\" + fileName, forSavingFolder + @"\" + fileName);
}
- //LoadAndSaveFile(forLoadingFolder + @"\StyleWorksheet.xlsx", forSavingFolder + @"\StyleWorksheet.xlsx");
+ //LoadAndSaveFile(forLoadingFolder + @"\StyleRowsColumns.xlsx", forSavingFolder + @"\StyleRowsColumns.xlsx");
}
private static void LoadAndSaveFile(String input, String output)
diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Program.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Program.cs
index 2076ad6..81dbd93 100644
--- a/ClosedXML/ClosedXML/ClosedXML_Examples/Program.cs
+++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Program.cs
@@ -11,12 +11,18 @@
namespace ClosedXML_Examples
{
- class Program
+ public class Program
{
static void Main(string[] args)
{
CreateFiles.CreateAllFiles();
LoadFiles.LoadAllFiles();
}
+
+ public static void ExecuteMain()
+ {
+ CreateFiles.CreateAllFiles();
+ LoadFiles.LoadAllFiles();
+ }
}
}
\ No newline at end of file
diff --git a/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj b/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj
index 3fc374a..d6f6410 100644
--- a/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj
+++ b/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj
@@ -265,6 +265,9 @@
Excel\Style\XLStyle.cs
+
+ Excel\Style\XLStylizedContainer.cs
+
Excel\Tables\IXLTable.cs
diff --git a/ClosedXML/ClosedXML/ClosedXML_Sandbox/ClosedXML_Sandbox.csproj b/ClosedXML/ClosedXML/ClosedXML_Sandbox/ClosedXML_Sandbox.csproj
index db1a722..858a71f 100644
--- a/ClosedXML/ClosedXML/ClosedXML_Sandbox/ClosedXML_Sandbox.csproj
+++ b/ClosedXML/ClosedXML/ClosedXML_Sandbox/ClosedXML_Sandbox.csproj
@@ -38,6 +38,10 @@
4
+
+ False
+ C:\Temp\DocumentFormat.OpenXml.dll
+
@@ -46,16 +50,22 @@
+
+
{BD5E6BFE-E837-4A35-BCA9-39667D873A20}
ClosedXML
+
+ {03A518D0-1CB7-488E-861C-C4E782B27A46}
+ ClosedXML_Examples
+