diff --git a/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj b/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj index 3f57037..1ee2e88 100644 --- a/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj +++ b/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj @@ -105,6 +105,7 @@ + diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCellsCollection.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCellsCollection.cs index 7256745..52582b9 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCellsCollection.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCellsCollection.cs @@ -5,9 +5,10 @@ { internal class XLCellsCollection { - private const Int32 InitialRowCapacity = 10000; - private const Int32 InitialColumnCapacity = 50; - private XLCell[,] _cells; + private const Int32 InitialRowCapacity = 5; + private const Int32 InitialColumnCapacity = 10; + //private XLCell[,] _cells; + private readonly Dictionary _cellsDictionary = new Dictionary(); private Int32 _columnCapacity = InitialColumnCapacity; private Int32 _rowCapacity = InitialRowCapacity; @@ -23,35 +24,35 @@ Clear(); } - private void ResizeIfNecessary(Int32 row, Int32 column) - { - if (row >= _rowCapacity || column >= _columnCapacity) - { - if (row >= _rowCapacity) - { - _rowCapacity = (Int32)((Double)_rowCapacity * 2); + //private void ResizeIfNecessary(Int32 row, Int32 column) + //{ + // if (row >= _rowCapacity || column >= _columnCapacity) + // { + // if (row >= _rowCapacity) + // { + // _rowCapacity = (Int32)((Double)_rowCapacity * 2); - if (_rowCapacity < row) - _rowCapacity = (Int32)((Double)row * 1.5); + // if (_rowCapacity < row) + // _rowCapacity = (Int32)((Double)row * 1.5); - if (_rowCapacity > ExcelHelper.MaxRowNumber) - _rowCapacity = ExcelHelper.MaxRowNumber; - } + // if (_rowCapacity > ExcelHelper.MaxRowNumber) + // _rowCapacity = ExcelHelper.MaxRowNumber; + // } - if (column >= _columnCapacity) - { - _columnCapacity = (Int32)((Double)_columnCapacity * 2); + // if (column >= _columnCapacity) + // { + // _columnCapacity = (Int32)((Double)_columnCapacity * 2); - if (_columnCapacity < column) - _columnCapacity = (Int32)((Double)column * 1.5); + // if (_columnCapacity < column) + // _columnCapacity = (Int32)((Double)column * 1.5); - if (_columnCapacity > ExcelHelper.MaxColumnNumber) - _columnCapacity = ExcelHelper.MaxColumnNumber; - } - - _cells = ExcelHelper.ResizeArray(_cells, _rowCapacity + 1, _columnCapacity + 1); - } - } + // if (_columnCapacity > ExcelHelper.MaxColumnNumber) + // _columnCapacity = ExcelHelper.MaxColumnNumber; + // } + + // _cells = ExcelHelper.ResizeArray(_cells, _rowCapacity + 1, _columnCapacity + 1); + // } + //} public void Add(XLSheetPoint sheetPoint, XLCell cell) { @@ -64,8 +65,9 @@ IncrementUsage(RowsUsed, row); IncrementUsage(ColumnsUsed, column); - ResizeIfNecessary(row, column); - _cells[row, column] = cell; + //ResizeIfNecessary(row, column); + _cellsDictionary.Add(new XLSheetPoint(row, column),cell ); + //_cells[row, column] = cell; if (row > MaxRowUsed) MaxRowUsed = row; if (column > MaxColumnUsed) MaxColumnUsed = column; var sp = new XLSheetPoint(row, column); @@ -99,23 +101,24 @@ RowsUsed.Clear(); ColumnsUsed.Clear(); - for (int ro = 1; ro <= MaxRowUsed; ro++) - { - for (int co = 1; co <= MaxColumnUsed; co++) - { - if (_cells[ro, co] != null) - { - var sp = new XLSheetPoint(ro, co); - if (!Deleted.Contains(sp)) - Deleted.Add(sp); - } - } - } + //for (int ro = 1; ro <= MaxRowUsed; ro++) + //{ + // for (int co = 1; co <= MaxColumnUsed; co++) + // { + // if (_cells[ro, co] != null) + // { + // var sp = new XLSheetPoint(ro, co); + // if (!Deleted.Contains(sp)) + // Deleted.Add(sp); + // } + // } + //} + _cellsDictionary.Clear(); _rowCapacity = InitialRowCapacity; _columnCapacity = InitialColumnCapacity; MaxRowUsed = 0; MaxColumnUsed = 0; - _cells = new XLCell[_rowCapacity,_columnCapacity]; + //_cells = new XLCell[_rowCapacity,_columnCapacity]; } public void Remove(XLSheetPoint sheetPoint) @@ -129,7 +132,8 @@ DecrementUsage(ColumnsUsed, row); var sp = new XLSheetPoint(row, column); Deleted.Add(sp); - _cells[row, column] = null; + _cellsDictionary.Remove(sp); + //_cells[row, column] = null; } public IEnumerable GetCells(Int32 rowStart, Int32 columnStart, @@ -141,8 +145,8 @@ { for (int co = columnStart; co <= finalColumn; co++) { - var cell = _cells[ro, co]; - if (cell != null) + XLCell cell; + if (_cellsDictionary.TryGetValue(new XLSheetPoint(ro,co), out cell )) { yield return cell; } @@ -159,10 +163,10 @@ { for (int co = columnStart; co <= finalColumn; co++) { - var cell = _cells[ro, co]; - if (cell != null) + var sp = new XLSheetPoint(ro, co); + if (_cellsDictionary.ContainsKey(sp)) { - Remove(ro,co); + Remove(sp); } } } @@ -178,10 +182,10 @@ { for (int co = columnStart; co <= finalColumn; co++) { - var cell = _cells[ro, co]; - if (cell != null) + var sp = new XLSheetPoint(ro, co); + if (_cellsDictionary.ContainsKey(sp)) { - yield return new XLSheetPoint(ro,co); + yield return sp; } } } @@ -191,13 +195,23 @@ { if (row > MaxRowUsed || column > MaxColumnUsed) return null; + var sp = new XLSheetPoint(row, column); + XLCell cell; + if (_cellsDictionary.TryGetValue(sp, out cell)) + return cell; - return _cells[row, column]; + return null; + //return _cells[row, column]; } public XLCell GetCell(XLSheetPoint sheetPoint) { - return _cells[sheetPoint.Row, sheetPoint.Column]; + XLCell cell; + if (_cellsDictionary.TryGetValue(sheetPoint, out cell)) + return cell; + + return null; + //return _cells[sheetPoint.Row, sheetPoint.Column]; } internal void SwapRanges(XLSheetRange sheetRange1, XLSheetRange sheetRange2) @@ -208,16 +222,30 @@ { for (int column = 0; column < columnCount; column++) { - var cell1 = _cells[sheetRange1.FirstPoint.Row + row, sheetRange1.FirstPoint.Column + column]; - var cell2 = _cells[sheetRange2.FirstPoint.Row + row, sheetRange2.FirstPoint.Column + column]; + var sp1 = new XLSheetPoint(sheetRange1.FirstPoint.Row + row, sheetRange1.FirstPoint.Column + column); + var sp2 = new XLSheetPoint(sheetRange2.FirstPoint.Row + row, sheetRange2.FirstPoint.Column + column); + var cell1 = GetCell(sp1); + var cell2 = GetCell(sp2); - var cell1Address = cell1.Address; + if (cell1 != null || cell2 != null) + { + if (cell1 != null) + { + cell1.Address = new XLAddress(cell1.Worksheet, sp2.Row, sp2.Column, false, false); + _cellsDictionary.Remove(sp1); + if (cell2 != null) + Add(sp1, cell2); + } - cell1.Address = cell2.Address; - cell2.Address = cell1Address; + if (cell2 != null) + { + cell2.Address = new XLAddress(cell2.Worksheet, sp1.Row, sp1.Column, false, false); + _cellsDictionary.Remove(sp2); + if (cell1 != null) + Add(sp2, cell1); + } - _cells[sheetRange1.FirstPoint.Row + row, sheetRange1.FirstPoint.Column + column] = cell2; - _cells[sheetRange2.FirstPoint.Row + row, sheetRange2.FirstPoint.Column + column] = cell1; + } } } } @@ -233,7 +261,7 @@ { for (int co = 1; co <= MaxColumnUsed; co++) { - var cell = _cells[ro, co]; + var cell = GetCell(ro, co); if (cell != null && predicate(cell)) { yield return cell; @@ -244,14 +272,14 @@ public Boolean Contains(Int32 row, Int32 column) { - return _cells[row, column] != null; + return _cellsDictionary.ContainsKey(new XLSheetPoint(row, column)); } public Int32 MinRowInColumn(Int32 column) { for (int row = 1; row <= MaxRowUsed; row++) { - if (_cells[row, column] != null) + if (GetCell(row, column) != null) return row; } @@ -262,7 +290,7 @@ { for (int row = MaxRowUsed; row >= 1; row--) { - if (_cells[row, column] != null) + if (GetCell(row, column) != null) return row; } @@ -273,7 +301,7 @@ { for (int column = 1; column <= MaxColumnUsed; column++) { - if (_cells[row, column] != null) + if (GetCell(row, column) != null) return column; } @@ -284,7 +312,7 @@ { for (int column = MaxColumnUsed; column >= 1; column--) { - if (_cells[row, column] != null) + if (GetCell(row, column) != null) return column; } diff --git a/ClosedXML/ClosedXML/ClosedXML/ExcelHelper.cs b/ClosedXML/ClosedXML/ClosedXML/ExcelHelper.cs index 5a5d255..b9118f7 100644 --- a/ClosedXML/ClosedXML/ClosedXML/ExcelHelper.cs +++ b/ClosedXML/ClosedXML/ClosedXML/ExcelHelper.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.Text; using ClosedXML.Excel; +using Microsoft.VisualBasic.CompilerServices; namespace ClosedXML { @@ -183,10 +184,25 @@ return GetColumnNumberFromLetter(cellAddressString.Substring(startPos, rowPos)); } + public static T[,] ResizeArrayX(T[,] original, int rows, int cols) + { + var newArray = new T[rows,cols]; + Array.Copy(original, newArray, original.Length); + return newArray; + } public static T[,] ResizeArray(T[,] original, int rows, int cols) { - var newArray = new T[rows, cols]; - Array.Copy(original, newArray, original.Length); + var newArray = new T[rows,cols]; + Utils.CopyArray(original, newArray); + //int originalSize = original.Length; + //int xLength = original.GetLength(0); + //int yLength = original.GetLength(1); + + //for (int x = 0; x < xLength; x++) + //{ + // Array.Copy(original, x * originalSize, newArray, 0, yLength); + //} + return newArray; } } diff --git a/ClosedXML/ClosedXML/ClosedXML/Properties/AssemblyInfo.cs b/ClosedXML/ClosedXML/ClosedXML/Properties/AssemblyInfo.cs index cd1ffc0..b24f806 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Properties/AssemblyInfo.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.55.0.0")] -[assembly: AssemblyFileVersion("0.55.0.0")] +[assembly: AssemblyVersion("0.56.0.0")] +[assembly: AssemblyFileVersion("0.56.0.0")] diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.csproj b/ClosedXML/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.csproj index e2aa431..8fb3b66 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.csproj +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.csproj @@ -188,6 +188,7 @@ + diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Creating/CreateFiles.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Creating/CreateFiles.cs index 50c486a..60f52e0 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Examples/Creating/CreateFiles.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Creating/CreateFiles.cs @@ -78,6 +78,8 @@ new TabColors().Create(@"C:\Excel Files\Created\TabColors.xlsx"); new ShiftingFormulas().Create(@"C:\Excel Files\Created\ShiftingFormulas.xlsx"); new CopyingRowsAndColumns().Create(@"C:\Excel Files\Created\CopyingRowsAndColumns.xlsx"); + new UsingRichText().Create(@"C:\Excel Files\Created\UsingRichText.xlsx"); + new UsingPhonetics().Create(@"C:\Excel Files\Created\UsingPhonetics.xlsx"); } } } diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Properties/AssemblyInfo.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Properties/AssemblyInfo.cs index a812387..3b0f1c9 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Examples/Properties/AssemblyInfo.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("0.56.0.0")] +[assembly: AssemblyFileVersion("0.56.0.0")] diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/UsingPhonetics.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/UsingPhonetics.cs new file mode 100644 index 0000000..aa727f2 --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/UsingPhonetics.cs @@ -0,0 +1,39 @@ +using System; +using ClosedXML.Excel; + +namespace ClosedXML_Examples.Styles +{ + public class UsingPhonetics : IXLExample + { + + + #region Methods + + // Public + public void Create(String filePath) + { + var wb = new XLWorkbook(); + var ws = wb.Worksheets.Add("Using Phonetics"); + + var cell = ws.Cell(1, 1); + + // Phonetics are implemented as part of the Rich Text functionality. For more information see [Using Rich Text] + // First we add the text. + cell.RichText.AddText("みんなさんはお元気ですか。").SetFontSize(16); + + // And then we add the phonetics + cell.RichText.Phonetics.SetFontSize(8); + cell.RichText.Phonetics.Add("げん", 7, 1); + cell.RichText.Phonetics.Add("き", 8, 1); + + wb.SaveAs(filePath); + } + + // Private + + // Override + + + #endregion + } +} diff --git a/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj b/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj index f876d13..3807aef 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj +++ b/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj @@ -104,6 +104,7 @@ + diff --git a/ClosedXML/ClosedXML/ClosedXML_Net3.5/Properties/AssemblyInfo.cs b/ClosedXML/ClosedXML/ClosedXML_Net3.5/Properties/AssemblyInfo.cs index ea1211b..672ebd6 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Net3.5/Properties/AssemblyInfo.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Net3.5/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.55.0.0")] -[assembly: AssemblyFileVersion("0.55.0.0")] +[assembly: AssemblyVersion("0.56.0.0")] +[assembly: AssemblyFileVersion("0.56.0.0")]