diff --git a/ClosedXML/ClosedXML/Excel/XLCell.cs b/ClosedXML/ClosedXML/Excel/XLCell.cs deleted file mode 100644 index 64f25f0..0000000 --- a/ClosedXML/ClosedXML/Excel/XLCell.cs +++ /dev/null @@ -1,124 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; -using DocumentFormat.OpenXml.Spreadsheet; - -namespace ClosedXML.Excel -{ - - public class XLCell - { - public XLCellAddress CellAddress { get; private set; } - private XLWorkbook workbook; - public XLCell(XLWorkbook workbook, XLCellAddress cellAddress) - { - this.CellAddress = cellAddress; - this.workbook = workbook; - } - - public XLCell(XLWorkbook workbook, String cellAddressString) - { - this.CellAddress = new XLCellAddress(cellAddressString); - this.workbook = workbook; - } - - public UInt32 Row { get { return CellAddress.Row; } } - public UInt32 Column { get { return CellAddress.Column; } } - public String ColumnLetter { get { return XLWorksheet.ColumnNumberToLetter(this.Column); } } - - public CellValues DataType { get; private set; } - public String InnerValue { get; private set; } - public String Value { - get - { - if (DataType == CellValues.Boolean) - { - return (InnerValue == "1").ToString(); - } - else if (DataType == CellValues.SharedString) - { - return workbook.SharedStrings.GetString(UInt32.Parse(InnerValue)); - } - else if (DataType == CellValues.Date) - { - return GetDateTimeFromSerial(Int32.Parse(InnerValue)).ToString(); - } - else - { - return InnerValue; - } - } - set - { - String val = value; - - Double dTest; - DateTime dtTest; - Boolean bTest; - if (Double.TryParse(val, out dTest)) - { - DataType = CellValues.Number; - } - else if (DateTime.TryParse(val, out dtTest)) - { - DataType = CellValues.Date; - String datePart = GetSerialFromDateTime(dtTest.Day, dtTest.Month, dtTest.Year).ToString(); - val = datePart; - } - else if (Boolean.TryParse(val, out bTest)) - { - DataType = CellValues.Boolean; - val = bTest ? "1" : "0"; - } - else - { - DataType = CellValues.SharedString; - val = workbook.SharedStrings.Add(val).ToString(); - } - InnerValue = val; - HasValue = !value.Equals(String.Empty); - } - } - - public Boolean HasValue { get; private set; } - - private DateTime GetDateTimeFromSerial(Int32 SerialDate) - { - if (SerialDate > 59) SerialDate -= 1; //Excel/Lotus 2/29/1900 bug - return new DateTime(1899, 12, 31).AddDays(SerialDate); - } - - private Int32 GetSerialFromDateTime(Int32 nDay, Int32 nMonth, Int32 nYear) - { - // Excel/Lotus 123 have a bug with 29-02-1900. 1900 is not a - - // leap year, but Excel/Lotus 123 think it is... - - if (nDay == 29 && nMonth == 02 && nYear == 1900) - return 60; - - // DMY to Modified Julian calculatie with an extra substraction of 2415019. - - long nSerialDate = - (int)((1461 * (nYear + 4800 + (int)((nMonth - 14) / 12))) / 4) + - (int)((367 * (nMonth - 2 - 12 * ((nMonth - 14) / 12))) / 12) - - (int)((3 * ((int)((nYear + 4900 + (int)((nMonth - 14) / 12)) / 100))) / 4) + - nDay - 2415019 - 32075; - - if (nSerialDate < 60) - { - // Because of the 29-02-1900 bug, any serial date - - // under 60 is one off... Compensate. - - nSerialDate--; - } - - return (int)nSerialDate; - } - - - } -} diff --git a/ClosedXML/ClosedXML/Excel/XLCellAddress.cs b/ClosedXML/ClosedXML/Excel/XLCellAddress.cs deleted file mode 100644 index 63c7b5c..0000000 --- a/ClosedXML/ClosedXML/Excel/XLCellAddress.cs +++ /dev/null @@ -1,151 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; - -namespace ClosedXML.Excel -{ - public struct XLCellAddress : IEqualityComparer, IEquatable, IComparable - { - - public XLCellAddress(UInt32 row, UInt32 column) - { - this.row = row; - this.column = column; - } - - public XLCellAddress(String cellAddressString) - { - Match m = Regex.Match(cellAddressString, @"^([a-zA-Z]+)(\d+)$"); - String columnLetter = m.Groups[1].Value; - this.row = UInt32.Parse(m.Groups[2].Value); - this.column = XLWorksheet.ColumnLetterToNumber(columnLetter); - } - - private UInt32 row; - public UInt32 Row - { - get { return row; } - private set { row = value; } - } - - private UInt32 column; - public UInt32 Column - { - get { return column; } - private set { column = value; } - } - - public static XLCellAddress operator +(XLCellAddress xlCellAddressLeft, XLCellAddress xlCellAddressRight) - { - return new XLCellAddress() { Row = xlCellAddressLeft.Row + xlCellAddressRight.Row, Column = xlCellAddressLeft.Column + xlCellAddressRight.Column }; - } - - public static XLCellAddress operator -(XLCellAddress xlCellAddressLeft, XLCellAddress xlCellAddressRight) - { - return new XLCellAddress() { Row = xlCellAddressLeft.Row - xlCellAddressRight.Row, Column = xlCellAddressLeft.Column - xlCellAddressRight.Column }; - } - - public static Boolean operator ==(XLCellAddress xlCellAddressLeft, XLCellAddress xlCellAddressRight) - { - return - xlCellAddressLeft.Row == xlCellAddressRight.Row - && xlCellAddressLeft.Column == xlCellAddressRight.Column; - } - - public static Boolean operator !=(XLCellAddress xlCellAddressLeft, XLCellAddress xlCellAddressRight) - { - return !(xlCellAddressLeft == xlCellAddressRight); - } - - public static Boolean operator >(XLCellAddress xlCellAddressLeft, XLCellAddress xlCellAddressRight) - { - return !(xlCellAddressLeft == xlCellAddressRight) - && xlCellAddressLeft.Row >= xlCellAddressRight.Row && xlCellAddressLeft.Column >= xlCellAddressRight.Column; - } - - public static Boolean operator <(XLCellAddress xlCellAddressLeft, XLCellAddress xlCellAddressRight) - { - return !(xlCellAddressLeft == xlCellAddressRight) - && xlCellAddressLeft.Row <= xlCellAddressRight.Row && xlCellAddressLeft.Column <= xlCellAddressRight.Column; - } - - public static Boolean operator >=(XLCellAddress xlCellAddressLeft, XLCellAddress xlCellAddressRight) - { - return - xlCellAddressLeft.Row >= xlCellAddressRight.Row - && xlCellAddressLeft.Column >= xlCellAddressRight.Column; - } - - public static Boolean operator <=(XLCellAddress xlCellAddressLeft, XLCellAddress xlCellAddressRight) - { - return - xlCellAddressLeft.Row <= xlCellAddressRight.Row - && xlCellAddressLeft.Column <= xlCellAddressRight.Column; - } - - public override String ToString() - { - return XLWorksheet.ColumnNumberToLetter(Column) + Row.ToString(); - } - - #region IEqualityComparer Members - - public Boolean Equals(XLCellAddress x, XLCellAddress y) - { - return x == y; - } - - public Int32 GetHashCode(XLCellAddress obj) - { - return obj.GetHashCode(); - } - - new public Boolean Equals(Object x, Object y) - { - return x == y; - } - - public Int32 GetHashCode(Object obj) - { - return obj.GetHashCode(); - } - - public override Int32 GetHashCode() - { - return this.ToString().GetHashCode(); - } - - #endregion - - #region IEquatable Members - - public Boolean Equals(XLCellAddress other) - { - return this == other; - } - - public override Boolean Equals(Object other) - { - return this == (XLCellAddress)other; - } - - #endregion - - #region IComparable Members - - public Int32 CompareTo(object obj) - { - var other = (XLCellAddress)obj; - if (this == other) - return 0; - else if (this > other) - return 1; - else - return -1; - } - - #endregion - } -} diff --git a/ClosedXML/ClosedXML/Excel/XLCells.cs b/ClosedXML/ClosedXML/Excel/XLCells.cs deleted file mode 100644 index 66a4a49..0000000 --- a/ClosedXML/ClosedXML/Excel/XLCells.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace ClosedXML.Excel -{ - public class XLCells: IEnumerable - { - private Dictionary cells = new Dictionary(); - private XLWorkbook workbook; - public XLCells(XLWorkbook workbook) - { - this.workbook = workbook; - } - - public XLCell this[XLCellAddress cellAddress] - { - get - { - Add(cellAddress); - return cells[cellAddress]; - } - } - - public void Add(XLCellAddress cellAddress) - { - if (!cells.ContainsKey(cellAddress)) - cells.Add(cellAddress, new XLCell(workbook, cellAddress)); - } - - #region IEnumerable Members - - public IEnumerator GetEnumerator() - { - return cells.Values.AsEnumerable().GetEnumerator(); - } - - #endregion - - #region IEnumerable Members - - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() - { - return this.GetEnumerator(); - } - - #endregion - } -} diff --git a/ClosedXML/ClosedXML/Excel/XLSharedStrings.cs b/ClosedXML/ClosedXML/Excel/XLSharedStrings.cs deleted file mode 100644 index 57e3cef..0000000 --- a/ClosedXML/ClosedXML/Excel/XLSharedStrings.cs +++ /dev/null @@ -1,64 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace ClosedXML.Excel -{ - public class XLSharedStrings: IEnumerable - { - internal class SharedStringInfo - { - public UInt32 Position { get; set; } - public UInt32 Count { get; set; } - } - - private Dictionary sharedStrings = new Dictionary(); - - private UInt32 lastPosition = 0; - public UInt32 Add(String sharedString) - { - SharedStringInfo stringInfo; - if(sharedStrings.ContainsKey(sharedString)) - { - stringInfo = sharedStrings[sharedString]; - stringInfo.Count++; - } - else - { - stringInfo = new SharedStringInfo() { Position = lastPosition, Count = 1 }; - sharedStrings.Add(sharedString, stringInfo); - lastPosition++; - } - return stringInfo.Position; - } - - public String GetString(UInt32 position) - { - return sharedStrings.Where(s => s.Value.Position == position).Single().Key; - } - - public UInt32 Count - { - get { return (UInt32)sharedStrings.Count; } - } - - #region IEnumerable Members - - public IEnumerator GetEnumerator() - { - return sharedStrings.Keys.GetEnumerator(); - } - - #endregion - - #region IEnumerable Members - - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - - #endregion - } -} diff --git a/ClosedXML/ClosedXML/Excel/XLWorksheet.cs b/ClosedXML/ClosedXML/Excel/XLWorksheet.cs deleted file mode 100644 index 6229ca3..0000000 --- a/ClosedXML/ClosedXML/Excel/XLWorksheet.cs +++ /dev/null @@ -1,91 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace ClosedXML.Excel -{ - public class XLWorksheet: XLRange - { - public const UInt32 MaxNumberOfRows = 1048576; - public const UInt32 MaxNumberOfColumns = 16384; - - public XLWorksheet(XLWorkbook workbook, String sheetName, XLCells cells) - : base( - new XLCell(workbook, new XLCellAddress(1,1)) - , new XLCell(workbook, new XLCellAddress(MaxNumberOfRows, MaxNumberOfColumns)) - , cells, null) - { - this.name = sheetName; - } - - public override List Cells() - { - return Cells(CellContent.All); - } - - public override List Cells(CellContent cellContent) - { - if (cellContent == CellContent.WithValues) - { - return base.Cells(cellContent); - } - else - { - String errorText = "Cannot load entire worksheet into memory. Please use a range (eg. XLWorksheet.Range(\"A1:D5\")) or retrieve cells with values (eg. XLWorksheet.Cells(CellContent.WithValues))."; - throw new InvalidOperationException(errorText); - } - } - - private String name; - public String Name - { - get - { - return name; - } - set - { - name = value; - } - } - - public static String ColumnNumberToLetter(UInt32 column) - { - String s = String.Empty; - for ( - Int32 i = Convert.ToInt32( - Math.Log( - Convert.ToDouble( - 25 * ( - Convert.ToDouble(column) - + 1 - ) - ) - ) / Math.Log(26) - ) - 1 - ; i >= 0 - ; i-- - ) - { - Int32 x = Convert.ToInt32(Math.Pow(26, i + 1) - 1) / 25 - 1; - if (column > x) - { - s += (Char)(((column - x - 1) / Convert.ToInt32(Math.Pow(26, i))) % 26 + 65); - } - } - return s; - } - - public static UInt32 ColumnLetterToNumber(String column) - { - Int32 intColumnLetterLength = column.Length; - Int32 retVal = 0; - for (Int32 intCount = 0; intCount < intColumnLetterLength; intCount++) - { - retVal = retVal * 26 + (column.Substring(intCount, 1).ToUpper().ToCharArray()[0] - 64); - } - return (UInt32)retVal; - } - } -}