diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCellsCollection.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCellsCollection.cs index 5c96905..f7910cb 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCellsCollection.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Cells/XLCellsCollection.cs @@ -11,6 +11,10 @@ public readonly Dictionary ColumnsUsed = new Dictionary(); public readonly Dictionary> deleted = new Dictionary>(); + internal Dictionary> RowsCollection + { + get { return rowsCollection; } + } public Int32 MaxColumnUsed; public Int32 MaxRowUsed; diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs index c8fe786..a2420fa 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs @@ -3936,16 +3936,6 @@ var sheetData = worksheetPart.Worksheet.Elements().First(); cm.SetElement(XLWSContentManager.XLWSContents.SheetData, sheetData); - var cellsByRow = new Dictionary>(); - foreach (var c in xlWorksheet.Internals.CellsCollection.GetCells()) - { - var rowNum = c.Address.RowNumber; - if (!cellsByRow.ContainsKey(rowNum)) - cellsByRow.Add(rowNum, new List()); - - cellsByRow[rowNum].Add(c); - } - var lastRow = 0; var sheetDataRows = sheetData.Elements().ToDictionary(r => r.RowIndex == null ? ++lastRow : (Int32)r.RowIndex.Value, @@ -3959,7 +3949,7 @@ xlWorksheet.Internals.CellsCollection.deleted.Remove(r.Key); } - var distinctRows = cellsByRow.Keys.Union(xlWorksheet.Internals.RowsCollection.Keys); + var distinctRows = xlWorksheet.Internals.CellsCollection.RowsCollection.Keys.Union(xlWorksheet.Internals.RowsCollection.Keys); var noRows = (sheetData.Elements().FirstOrDefault() == null); foreach (var distinctRow in distinctRows.OrderBy(r => r)) { @@ -4040,13 +4030,13 @@ } - if (!cellsByRow.ContainsKey(distinctRow)) continue; + if (!xlWorksheet.Internals.CellsCollection.RowsCollection.ContainsKey(distinctRow)) continue; var isNewRow = !row.Elements().Any(); var mRows = row.Elements().ToDictionary(c => XLHelper.GetColumnNumberFromAddress(c.CellReference.Value), c => c); - foreach (var opCell in cellsByRow[distinctRow] + foreach (var opCell in xlWorksheet.Internals.CellsCollection.RowsCollection[distinctRow].Values .OrderBy(c => c.Address.ColumnNumber) - .Select(c => (XLCell)c)) + .Select(c => c)) { var styleId = context.SharedStyles[opCell.GetStyleId()].StyleId; diff --git a/ClosedXML/ClosedXML/ClosedXML/Properties/AssemblyInfo.cs b/ClosedXML/ClosedXML/ClosedXML/Properties/AssemblyInfo.cs index 5765c10..bc7f151 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Properties/AssemblyInfo.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Properties/AssemblyInfo.cs @@ -31,6 +31,6 @@ // 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.71.1.0")] -[assembly: AssemblyFileVersion("0.71.1.0")] +[assembly: AssemblyVersion("0.71.2.0")] +[assembly: AssemblyFileVersion("0.71.2.0")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ClosedXML_Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100a1fb8ba59167fe734d64128ca73d32c45cb8a117246d09c95c8769db88fe332b0a3396bedd0ea48ee42b0e5796fec0798ca5cb628a9a6de80d35d6c67b936ca1670347b3d4f2b769c8ce2ddcf959dbac6bcd88e6c08751ea1fffa0522de3507193e7035305a8aa008d6c88cca1341b3120fa9c347ab3f97e2d772e2709277da5")] \ No newline at end of file diff --git a/ClosedXML/ClosedXML/ClosedXML_Net3.5/Properties/AssemblyInfo.cs b/ClosedXML/ClosedXML/ClosedXML_Net3.5/Properties/AssemblyInfo.cs index fb5cf8a..59f21f5 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.71.1.0")] -[assembly: AssemblyFileVersion("0.71.1.0")] +[assembly: AssemblyVersion("0.71.2.0")] +[assembly: AssemblyFileVersion("0.71.2.0")] diff --git a/ClosedXML/ClosedXML/ClosedXML_Sandbox/Program.cs b/ClosedXML/ClosedXML/ClosedXML_Sandbox/Program.cs index ab4081b..bcb5bbc 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Sandbox/Program.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Sandbox/Program.cs @@ -12,50 +12,7 @@ { class Program { - private static void Main(string[] args) - { - var dt = new System.Data.DataTable(); - - dt.Columns.Add("col1", typeof(string)); - dt.Columns.Add("col2", typeof(string)); - dt.Columns.Add("col3", typeof(double)); - - var col1 = new string[] { "col1_val1", "col1_val2", "col1_val3" }; - var col2 = new string[] { "col2_val1", "col2_val2", "col2_val3" }; - - var rnd = new Random(); - for (int i = 0; i < 10; i++) - { - var row = dt.NewRow(); - row["col1"] = col1[rnd.Next(0, 3)]; - row["col2"] = col2[rnd.Next(0, 3)]; - row["col3"] = rnd.NextDouble() * rnd.Next(10, 100); - dt.Rows.Add(row); - } - - var workbook = new XLWorkbook(); - var sheet = workbook.Worksheets.Add("Sheet1"); - - var table = sheet.Cell(1, 1).InsertTable(dt, "Table1", true); - - var range = table.DataRange; - var header = sheet.Range(1, 1, 1, dt.Columns.Count); - var dataRange = sheet.Range(header.FirstCell(), range.LastCell()); - - var ptSheet = workbook.Worksheets.Add("Sheet2"); - - var pt = ptSheet.PivotTables.AddNew("TablePivot", ptSheet.Cell(1, 1), dataRange); - - // COL2 then COL1 - pt.RowLabels.Add("col2"); - pt.RowLabels.Add("col1"); - - pt.Values.Add("col3"); - - workbook.SaveAs(@"c:\temp\saved.xlsx"); - } - - static void MainX(string[] args) + static void Main(string[] args) { DateTime start, end; var times = new List(); @@ -73,7 +30,7 @@ //} Console.WriteLine("Average: " + times.Average()); Console.WriteLine("Done"); - Console.ReadKey(); + //Console.ReadKey(); } }