diff --git a/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj b/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj
index 054c162..788695a 100644
--- a/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj
+++ b/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj
@@ -106,6 +106,7 @@
+
@@ -119,6 +120,7 @@
+
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/IXLCell.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/IXLCell.cs
index 117159d..c7cf602 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/IXLCell.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/IXLCell.cs
@@ -38,6 +38,8 @@
///
XLCellValues DataType { get; set; }
+ IXLCell SetValue(T value);
+
///
/// Gets the cell's value converted to the T type.
/// ClosedXML will try to covert the current value to the T type.
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell.cs
index 0eb27b1..67d4c6b 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell.cs
@@ -6,10 +6,9 @@
using System.Collections;
using System.Data;
-
namespace ClosedXML.Excel
{
- internal class XLCell : IXLCell, IXLStylized
+ internal partial class XLCell : IXLCell, IXLStylized
{
public static readonly DateTime baseDate = new DateTime(1899, 12, 30);
public IXLWorksheet Worksheet { get { return worksheet; } }
@@ -41,6 +40,63 @@
{
return worksheet.Range(Address, Address);
}
+ public IXLCell SetValue(T value)
+ {
+ FormulaA1 = String.Empty;
+ if (value is String)
+ {
+ cellValue = value.ToString();
+ dataType = XLCellValues.Text;
+ }
+ else if (value is TimeSpan)
+ {
+ cellValue = value.ToString();
+ dataType = XLCellValues.TimeSpan;
+ Style.NumberFormat.NumberFormatId = 46;
+ }
+ else if (value is DateTime)
+ {
+ dataType = XLCellValues.DateTime;
+ DateTime dtTest = (DateTime)Convert.ChangeType(value, typeof(DateTime));
+ if (dtTest.Date == dtTest)
+ Style.NumberFormat.NumberFormatId = 14;
+ else
+ Style.NumberFormat.NumberFormatId = 22;
+
+ cellValue = dtTest.ToOADate().ToString();
+ }
+ else if (
+ value is sbyte
+ || value is byte
+ || value is char
+ || value is short
+ || value is ushort
+ || value is int
+ || value is uint
+ || value is long
+ || value is ulong
+ || value is float
+ || value is double
+ || value is decimal
+ )
+ {
+ dataType = XLCellValues.Number;
+ cellValue = value.ToString();
+ }
+ else if (value is Boolean)
+ {
+ dataType = XLCellValues.Boolean;
+ cellValue = (Boolean)Convert.ChangeType(value, typeof(Boolean)) ? "1" : "0";
+ }
+ else
+ {
+ cellValue = value.ToString();
+ dataType = XLCellValues.Text;
+ }
+
+ return this;
+ }
+
public T GetValue()
{
if (!StringExtensions.IsNullOrWhiteSpace(FormulaA1))
@@ -304,7 +360,10 @@
{
if (!hasTitles)
{
- SetValue(m.GetType().Name, fRo, co);
+ String fieldName = GetFieldName(m.GetType().GetCustomAttributes(true));
+ if (StringExtensions.IsNullOrWhiteSpace(fieldName)) fieldName = m.GetType().Name;
+
+ SetValue(fieldName, fRo, co);
hasTitles = true;
co = Address.ColumnNumber;
}
@@ -348,14 +407,25 @@
{
foreach (var info in fieldInfo)
{
- SetValue(info.Name, fRo, co);
+ if ((info as IEnumerable) == null)
+ {
+ String fieldName = GetFieldName(info.GetCustomAttributes(true));
+ if (StringExtensions.IsNullOrWhiteSpace(fieldName)) fieldName = info.Name;
+
+ SetValue(fieldName, fRo, co);
+ }
co++;
}
foreach (var info in propertyInfo)
{
if ((info as IEnumerable) == null)
- SetValue(info.Name, fRo, co);
+ {
+ String fieldName = GetFieldName(info.GetCustomAttributes(true));
+ if (StringExtensions.IsNullOrWhiteSpace(fieldName)) fieldName = info.Name;
+
+ SetValue(fieldName, fRo, co);
+ }
co++;
}
co = Address.ColumnNumber;
@@ -761,6 +831,8 @@
return String.Empty;
else if (formulaA1.Trim()[0] == '=')
return formulaA1.Substring(1);
+ else if (formulaA1.Trim().StartsWith("{="))
+ return "{" + formulaA1.Substring(2);
else
return formulaA1;
}
@@ -892,10 +964,15 @@
else
{
var bIndex = columnPart.IndexOf("[");
+ var mIndex = columnPart.IndexOf("-");
if (bIndex >= 0)
columnToReturn = XLAddress.GetColumnLetterFromNumber(
Address.ColumnNumber + Int32.Parse(columnPart.Substring(bIndex + 1, columnPart.Length - bIndex - 2)) + columnsToShift
);
+ else if (mIndex >= 0)
+ columnToReturn = XLAddress.GetColumnLetterFromNumber(
+ Address.ColumnNumber + Int32.Parse(columnPart.Substring(mIndex)) + columnsToShift
+ );
else
columnToReturn = "$" + XLAddress.GetColumnLetterFromNumber(Int32.Parse(columnPart.Substring(1)) + columnsToShift);
}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell_DotNetSpecific.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell_DotNetSpecific.cs
new file mode 100644
index 0000000..60f1653
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCell_DotNetSpecific.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.ComponentModel.DataAnnotations;
+using System.Reflection;
+
+namespace ClosedXML.Excel
+{
+ internal partial class XLCell
+ {
+ private String GetFieldName(Object[] customAttributes)
+ {
+ var displayAttributes = customAttributes.Where(a => a is DisplayAttribute).Select(a => (a as DisplayAttribute).Name);
+ if (displayAttributes.Any())
+ return displayAttributes.Single();
+ else
+ return null;
+ }
+
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Hyperlinks/XLHyperlink_Internal.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Hyperlinks/XLHyperlink_Internal.cs
index 82468b9..1c80b6b 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/Hyperlinks/XLHyperlink_Internal.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Hyperlinks/XLHyperlink_Internal.cs
@@ -8,7 +8,9 @@
public partial class XLHyperlink
{
internal XLHyperlink()
- { }
+ {
+
+ }
internal void SetValues(String address, String tooltip)
{
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Load.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Load.cs
index 1013d87..aa28c00 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Load.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Load.cs
@@ -230,15 +230,31 @@
if (cell.CellFormula != null && cell.CellFormula.SharedIndex != null && cell.CellFormula.Reference != null)
{
- xlCell.FormulaA1 = cell.CellFormula.Text;
- sharedFormulasR1C1.Add(cell.CellFormula.SharedIndex.Value, xlCell.FormulaR1C1);
+ String formula;
+ if (cell.CellFormula.FormulaType != null && cell.CellFormula.FormulaType == CellFormulaValues.Array)
+ formula = "{" + cell.CellFormula.Text + "}";
+ else
+ formula = cell.CellFormula.Text;
+
+ xlCell.FormulaA1 = formula;
+ sharedFormulasR1C1.Add(cell.CellFormula.SharedIndex.Value, formula);
}
else if (dCell.CellFormula != null)
{
if (dCell.CellFormula.SharedIndex != null)
+ {
xlCell.FormulaR1C1 = sharedFormulasR1C1[dCell.CellFormula.SharedIndex.Value];
+ }
else
- xlCell.FormulaA1 = dCell.CellFormula.Text;
+ {
+ String formula;
+ if (cell.CellFormula.FormulaType != null && cell.CellFormula.FormulaType == CellFormulaValues.Array)
+ formula = "{" + cell.CellFormula.Text + "}";
+ else
+ formula = cell.CellFormula.Text;
+
+ xlCell.FormulaA1 = formula;
+ }
}
else if (dCell.DataType != null)
{
@@ -285,8 +301,22 @@
{
//var styleIndex = Int32.Parse(dCell.StyleIndex.InnerText);
var numberFormatId = ((CellFormat)((CellFormats)s.CellFormats).ElementAt(styleIndex)).NumberFormatId; //. [styleIndex].NumberFormatId;
- ws.Cell(dCell.CellReference).Value = Double.Parse(dCell.CellValue.Text, CultureInfo.InvariantCulture);
- ws.Cell(dCell.CellReference).Style.NumberFormat.NumberFormatId = Int32.Parse(numberFormatId);
+ Double val = Double.Parse(dCell.CellValue.Text, CultureInfo.InvariantCulture);
+ xlCell.Value = val;
+ if (s.NumberingFormats != null && s.NumberingFormats.Where(nf => ((NumberingFormat)nf).NumberFormatId.Value == numberFormatId).Any())
+ xlCell.Style.NumberFormat.Format =
+ ((NumberingFormat)s.NumberingFormats.Where(nf => ((NumberingFormat)nf).NumberFormatId.Value == numberFormatId).Single()).FormatCode.Value;
+ else
+ xlCell.Style.NumberFormat.NumberFormatId = Int32.Parse(numberFormatId);
+
+ if (val >= 0 && val <= DateTimeExtensions.MaxOADate)
+ {
+ String format = xlCell.Style.NumberFormat.Format.EndsWith(";@") ? xlCell.Style.NumberFormat.Format.Substring(0, xlCell.Style.NumberFormat.Format.Length - 2) : xlCell.Style.NumberFormat.Format;
+
+ Double dTest;
+ if (!Double.TryParse(val.ToString(format) , out dTest))
+ xlCell.DataType = XLCellValues.DateTime;
+ }
}
}
#endregion
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs
index 69b6b9e..deff59e 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs
@@ -625,6 +625,9 @@
workbook.WorkbookProperties.DefaultThemeVersion = (UInt32Value)124226U;
#endregion
+ //if (workbook.BookViews == null)
+ // workbook.BookViews = new BookViews();
+
if (workbook.Sheets == null)
workbook.Sheets = new Sheets();
@@ -668,11 +671,30 @@
orderby worksheet.Position
select sheet;
- foreach (var sheet in sheetElements)
- {
- workbook.Sheets.RemoveChild(sheet);
- workbook.Sheets.Append(sheet);
- }
+ //UInt32 firstSheetVisible = 0;
+
+ //foreach (var sheet in sheetElements)
+ //{
+ // workbook.Sheets.RemoveChild(sheet);
+ // workbook.Sheets.Append(sheet);
+ // if (firstSheetVisible == 0 && sheet.State != null && sheet.State != SheetStateValues.Visible)
+ // firstSheetVisible++;
+ //}
+
+ //WorkbookView workbookView = workbook.BookViews.Elements().FirstOrDefault();
+
+
+ //if (workbookView == null)
+ //{
+ // workbookView = new WorkbookView() { ActiveTab = firstSheetVisible, FirstSheet = firstSheetVisible };
+ // workbook.BookViews.Append(workbookView);
+ //}
+ //else
+ //{
+ // workbookView.ActiveTab = firstSheetVisible;
+ // workbookView.FirstSheet = firstSheetVisible;
+ //}
+
DefinedNames definedNames = new DefinedNames();
foreach (var worksheet in Worksheets.Cast())
@@ -850,10 +872,26 @@
//Dictionary sharedAlignments = new Dictionary();
//sharedAlignments.Add(defaultStyle.Alignment.ToString(), new AlignmentInfo() { AlignmentId = 0, Alignment = defaultStyle.Alignment });
+ if (workbookStylesPart.Stylesheet == null)
+ workbookStylesPart.Stylesheet = new Stylesheet();
+
+ // Cell styles = Named styles
+ if (workbookStylesPart.Stylesheet.CellStyles == null)
+ workbookStylesPart.Stylesheet.CellStyles = new CellStyles();
+
+ UInt32 defaultFormatId;
+ if (workbookStylesPart.Stylesheet.CellStyles.Elements().Where(c => c.Name == "Normal").Any())
+ defaultFormatId = workbookStylesPart.Stylesheet.CellStyles.Elements().Where(c => c.Name == "Normal").Single().FormatId.Value;
+ else
+ if (workbookStylesPart.Stylesheet.CellStyles.Elements().Any())
+ defaultFormatId = workbookStylesPart.Stylesheet.CellStyles.Elements().Max(c => c.FormatId.Value) + 1;
+ else
+ defaultFormatId = 0;
+
sharedStyles.Add(defaultStyle,
new StyleInfo()
{
- StyleId = 0,
+ StyleId = defaultFormatId,
Style = defaultStyle,
FontId = 0,
FillId = 0,
@@ -903,8 +941,6 @@
}
}
- if (workbookStylesPart.Stylesheet == null)
- workbookStylesPart.Stylesheet = new Stylesheet();
var allSharedNumberFormats = ResolveNumberFormats(workbookStylesPart, sharedNumberFormats);
var allSharedFonts = ResolveFonts(workbookStylesPart, sharedFonts);
@@ -937,13 +973,10 @@
var allCellStyleFormats = ResolveCellStyleFormats(workbookStylesPart);
ResolveAlignments(workbookStylesPart);
- // Cell styles = Named styles
- if (workbookStylesPart.Stylesheet.CellStyles == null)
- workbookStylesPart.Stylesheet.CellStyles = new CellStyles();
-
+
if (!workbookStylesPart.Stylesheet.CellStyles.Elements().Where(c => c.Name == "Normal").Any())
{
- var defaultFormatId = sharedStyles.Values.Where(s => s.Style.Equals(DefaultStyle)).Single().StyleId;
+ //var defaultFormatId = sharedStyles.Values.Where(s => s.Style.Equals(DefaultStyle)).Single().StyleId;
CellStyle cellStyle1 = new CellStyle() { Name = "Normal", FormatId = (UInt32Value)defaultFormatId, BuiltinId = (UInt32Value)0U };
workbookStylesPart.Stylesheet.CellStyles.Append(cellStyle1);
@@ -1871,7 +1904,18 @@
cell.StyleIndex = styleId;
if (!StringExtensions.IsNullOrWhiteSpace(opCell.FormulaA1))
{
- cell.CellFormula = new CellFormula(opCell.FormulaA1);
+ String formula = opCell.FormulaA1;
+ if (formula.StartsWith("{"))
+ {
+ formula = formula.Substring(1, formula.Length - 2);
+ cell.CellFormula = new CellFormula(formula);
+ cell.CellFormula.FormulaType = CellFormulaValues.Array;
+ cell.CellFormula.Reference = cellReference;
+ }
+ else
+ {
+ cell.CellFormula = new CellFormula(formula);
+ }
cell.CellValue = null;
}
else
@@ -1968,6 +2012,8 @@
#endregion
var phoneticProperties = worksheetPart.Worksheet.Elements().FirstOrDefault();
+
+ var conditionalFormatting = worksheetPart.Worksheet.Elements().LastOrDefault();
#region DataValidations
DataValidations dataValidations = null;
@@ -1982,7 +2028,9 @@
if (worksheetPart.Worksheet.Elements().Count() == 0)
{
OpenXmlElement previousElement;
- if (phoneticProperties != null)
+ if (conditionalFormatting != null)
+ previousElement = conditionalFormatting;
+ else if (phoneticProperties != null)
previousElement = phoneticProperties;
else if (mergeCells != null)
previousElement = mergeCells;
@@ -2053,6 +2101,8 @@
OpenXmlElement previousElement;
if (dataValidations != null)
previousElement = dataValidations;
+ else if (conditionalFormatting != null)
+ previousElement = conditionalFormatting;
else if (phoneticProperties != null)
previousElement = phoneticProperties;
else if (mergeCells != null)
@@ -2107,6 +2157,8 @@
previousElement = hyperlinks;
else if (dataValidations != null)
previousElement = dataValidations;
+ else if (conditionalFormatting != null)
+ previousElement = conditionalFormatting;
else if (phoneticProperties != null)
previousElement = phoneticProperties;
else if (mergeCells != null)
@@ -2143,6 +2195,8 @@
previousElement = hyperlinks;
else if (dataValidations != null)
previousElement = dataValidations;
+ else if (conditionalFormatting != null)
+ previousElement = conditionalFormatting;
else if (phoneticProperties != null)
previousElement = phoneticProperties;
else if (mergeCells != null)
@@ -2519,37 +2573,54 @@
foreach (var c in worksheet.Internals.CellsCollection.Values.Where(c => !StringExtensions.IsNullOrWhiteSpace(c.FormulaA1)))
{
var calculationCells = calculationChain.Elements().Where(
- cc => cc.CellReference != null && cc.CellReference == c.Address.ToString()).Select(cc=>cc);
- Boolean addNew = true;
- if (calculationCells.FirstOrDefault() != null)
+ cc => cc.CellReference != null && cc.CellReference == c.Address.ToString()).Select(cc => cc).ToList();
+
+ calculationCells.ForEach(cc => calculationChain.RemoveChild(cc));
+
+
+ if (c.FormulaA1.StartsWith("{"))
{
- calculationCells.Where(cc=>cc.SheetId == null).Select(cc=>cc).ForEach(cc=>calculationChain.RemoveChild(cc));
- var cCell = calculationCells.FirstOrDefault(cc=>cc.SheetId == worksheet.SheetId);
- if (cCell != null)
- {
- cCell.SheetId = worksheet.SheetId;
- addNew = false;
- }
+ calculationChain.Append(new CalculationCell() { CellReference = c.Address.ToString(), SheetId = worksheet.SheetId, Array = true });
+ calculationChain.Append(new CalculationCell() { CellReference = c.Address.ToString(), InChildChain = true });
+ }
+ else
+ {
+ calculationChain.Append(new CalculationCell() { CellReference = c.Address.ToString(), SheetId = worksheet.SheetId });
}
- if (addNew)
- {
- CalculationCell calculationCell = new CalculationCell() { CellReference = c.Address.ToString(), SheetId = worksheet.SheetId };
- calculationChain.Append(calculationCell);
- }
+
+ //Boolean addNew = true;
+ //if (calculationCells.FirstOrDefault() != null)
+ //{
+ // calculationCells.Where(cc => cc.SheetId == null).Select(cc => cc).ForEach(cc => calculationChain.RemoveChild(cc));
+ // var cCell = calculationCells.Where(cc => cc.SheetId != null).FirstOrDefault(cc => cc.SheetId == worksheet.SheetId);
+ // if (cCell != null)
+ // {
+ // cCell.SheetId = worksheet.SheetId;
+ // cCell.Array = null;
+ // addNew = false;
+ // }
+ //}
+
+ //if (addNew)
+ //{
+ // CalculationCell calculationCell = new CalculationCell() { CellReference = c.Address.ToString(), SheetId = worksheet.SheetId };
+ // calculationChain.Append(calculationCell);
+ //}
+
}
- var cCellsToRemove = new List();
+ //var cCellsToRemove = new List();
var m = from cc in calculationChain.Elements()
- where cc.SheetId == null
+ where !(cc.SheetId != null || cc.InChildChain != null)
&& calculationChain.Elements()
.Where(c1 => c1.SheetId != null)
.Select(c1 => c1.CellReference.Value)
.Contains(cc.CellReference.Value)
|| worksheet.Internals.CellsCollection.Where(kp=>kp.Key.ToString() == cc.CellReference.Value && StringExtensions.IsNullOrWhiteSpace(kp.Value.FormulaA1)).Any()
select cc;
- m.ForEach(cc => cCellsToRemove.Add(cc));
- cCellsToRemove.ForEach(cc=>calculationChain.RemoveChild(cc));
+ //m.ToList().ForEach(cc => cCellsToRemove.Add(cc));
+ m.ToList().ForEach(cc=>calculationChain.RemoveChild(cc));
}
if (calculationChain.Count() == 0)
diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorksheet.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorksheet.cs
index 676c0ae..f8e182d 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorksheet.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorksheet.cs
@@ -534,7 +534,8 @@
public IXLWorksheet CopyTo(XLWorkbook workbook, String newSheetName, Int32 position)
{
var ws = (XLWorksheet)workbook.Worksheets.Add(newSheetName, position);
- this.Internals.CellsCollection.ForEach(kp => ws.Internals.CellsCollection.Add(kp));
+
+ this.Internals.CellsCollection.ForEach(kp => (ws.Cell(kp.Value.Address) as XLCell).CopyValues(kp.Value));
this.Internals.ColumnsCollection.ForEach(kp => ws.Internals.ColumnsCollection.Add(kp));
this.Internals.MergedRanges.ForEach(kp => ws.Internals.MergedRanges.Add(kp));
this.Internals.RowsCollection.ForEach(kp => ws.Internals.RowsCollection.Add(kp));
diff --git a/ClosedXML/ClosedXML/ClosedXML/Extensions.cs b/ClosedXML/ClosedXML/ClosedXML/Extensions.cs
index 9f0de2d..e579d39 100644
--- a/ClosedXML/ClosedXML/ClosedXML/Extensions.cs
+++ b/ClosedXML/ClosedXML/ClosedXML/Extensions.cs
@@ -112,6 +112,17 @@
}
}
+ public static class DateTimeExtensions
+ {
+ public static Double MaxOADate
+ {
+ get
+ {
+ return 2958465.99999999;
+ }
+ }
+ }
+
public static class IntegerExtensions
{
private static NumberFormatInfo nfi = CultureInfo.InvariantCulture.NumberFormat;
diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.csproj b/ClosedXML/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.csproj
index fd152ab..3c96724 100644
--- a/ClosedXML/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.csproj
+++ b/ClosedXML/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.csproj
@@ -70,6 +70,7 @@
+
diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Misc/Formulas.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Misc/Formulas.cs
index d5ddd15..a6948c1 100644
--- a/ClosedXML/ClosedXML/ClosedXML_Examples/Misc/Formulas.cs
+++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Misc/Formulas.cs
@@ -78,6 +78,7 @@
ws.Cell(4, 1).Value = "A";
ws.Cell(4, 2).Value = "B";
var cellWithStringFormula = ws.Cell(4, 3);
+
// Use R1C1 notation
cellWithStringFormula.FormulaR1C1 = "=\"Test\" & RC[-2] & \"R3C2\"";
ws.Cell(4, 4).Value = cellWithStringFormula.FormulaA1;
@@ -86,7 +87,12 @@
// Setting the formula of a range
var rngData = ws.Range(2, 1, 4, 7);
- rngData.LastColumn().Cells().FormulaR1C1 = "=IF(RC[-3]=RC[-1],\"Yes\", \"No\")";
+ rngData.LastColumn().FormulaR1C1 = "=IF(RC[-3]=RC[-1],\"Yes\", \"No\")";
+
+ // Using an array formula:
+ // Just put the formula between curly braces
+ ws.Cell("A6").Value = "Array Formula: ";
+ ws.Cell("B6").FormulaA1 = "{A2+A3}";
ws.Range(1, 1, 1, 7).Style.Fill.BackgroundColor = XLColor.Cyan;
ws.Range(1, 1, 1, 7).Style.Font.Bold = true;
diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Misc/InsertingTables.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Misc/InsertingTables.cs
index d72aa34..63ec472 100644
--- a/ClosedXML/ClosedXML/ClosedXML_Examples/Misc/InsertingTables.cs
+++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Misc/InsertingTables.cs
@@ -3,9 +3,10 @@
using System.Linq;
using System.Text;
using ClosedXML.Excel;
-
using System.Drawing;
using System.Data;
+using System.ComponentModel.DataAnnotations;
+
namespace ClosedXML_Examples.Misc
{
@@ -51,7 +52,13 @@
var people = from p in list
where p.Age >= 21
- select new { p.Name, p.House, p.Age };
+ select p;
+
+ //var person = new Person() { Name = "Henry", Age = 45, House = "On 5th Ave." };
+ //foreach (var p in person.GetType().GetProperties())
+ //{
+ // var ats = p.GetCustomAttributes(true);
+ //}
ws.Cell(7, 6).Value = "From Query";
ws.Range(7, 6, 7, 8).Merge().AddToNamed("Titles");
@@ -70,9 +77,10 @@
wb.SaveAs(filePath);
}
-
+
class Person
{
+ [Display(Name = "House Street")]
public String House { get; set; }
public String Name { get; set; }
public Int32 Age { get; set; }
diff --git a/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj b/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj
index 2b0846c..26ae34c 100644
--- a/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj
+++ b/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj
@@ -457,6 +457,7 @@
Extensions.cs
+
diff --git a/ClosedXML/ClosedXML/ClosedXML_Net3.5/Excel/Cells/XLCell_DotNetSpecific.cs b/ClosedXML/ClosedXML/ClosedXML_Net3.5/Excel/Cells/XLCell_DotNetSpecific.cs
new file mode 100644
index 0000000..436ad8c
--- /dev/null
+++ b/ClosedXML/ClosedXML/ClosedXML_Net3.5/Excel/Cells/XLCell_DotNetSpecific.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Reflection;
+
+
+namespace ClosedXML.Excel
+{
+ internal partial class XLCell
+ {
+ private String GetFieldName(Object[] customAttributes)
+ {
+ return null;
+ }
+ }
+}
diff --git a/ClosedXML/ClosedXML/ClosedXML_Sandbox/Program.cs b/ClosedXML/ClosedXML/ClosedXML_Sandbox/Program.cs
index 427b44a..c3f439f 100644
--- a/ClosedXML/ClosedXML/ClosedXML_Sandbox/Program.cs
+++ b/ClosedXML/ClosedXML/ClosedXML_Sandbox/Program.cs
@@ -15,14 +15,11 @@
static void Main(string[] args)
{
- //var fileName = "Issue_6266";
- //var fileName = "Issue_6257";
- var fileName = "Sandbox";
- //var wb = new XLWorkbook(String.Format(@"c:\Excel Files\ForTesting\{0}.xlsx", fileName));
- var wb = new XLWorkbook();
- var ws = wb.Worksheets.Add("New");
- ws.Range("A1:B1").Value = "X";
- ws.Cell(1, 1).AsRange().InsertRowsAbove(1);
+ var fileName = "Issue_6295";
+ //var fileName = "Blank";
+ //var fileName = "Sandbox";
+ var wb = new XLWorkbook(String.Format(@"c:\Excel Files\ForTesting\{0}.xlsx", fileName));
+ //var wb = new XLWorkbook();
wb.SaveAs(String.Format(@"c:\Excel Files\ForTesting\{0}_Saved.xlsx", fileName));