Skip to content

Commit

Permalink
implement SXSSFSheet.GetCells
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyqus committed Dec 12, 2024
1 parent ae54bf2 commit 94cbe69
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
16 changes: 7 additions & 9 deletions main/HSSF/UserModel/HSSFSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3398,28 +3398,26 @@ public ICellRange<ICell> GetCells(string range)
{
if(string.IsNullOrWhiteSpace(range))
{
throw new ArgumentException("range cannot be null or empty");
throw new ArgumentException("cell range cannot be null or empty");
}

var cells = new List<ICell>();

var rangeAddress = new RangeAddress(range);
var startCellAddress = new CellAddress(rangeAddress.FromCell);
var firstColumn = startCellAddress.Column;
var firstRow = startCellAddress.Row;
var height = rangeAddress.Height;
var width = rangeAddress.Width;
for(int i = firstRow; i < height; i++)

for(int i = startCellAddress.Row; i < rangeAddress.Height; i++)
{
for(int j = firstColumn; j < width; j++)
for(int j = startCellAddress.Column; j < rangeAddress.Width; j++)
{
var row = this.GetRow(i) ?? CreateRow(i);
var cell = row.GetCell(j) ?? row.CreateCell(j);
cells.Add(cell);
}
}

return SSCellRange<ICell>.Create(firstRow, firstColumn, height, width, cells, typeof(ICell));
return SSCellRange<ICell>.Create(
startCellAddress.Row, startCellAddress.Column,
rangeAddress.Height, rangeAddress.Width, cells, typeof(ICell));
}
}
}
26 changes: 25 additions & 1 deletion ooxml/XSSF/Streaming/SXSSFSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ the License. You may obtain a copy of the License at
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */

using NPOI.HSSF.Util;
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -1481,7 +1483,29 @@ IEnumerator<IRow> IEnumerable<IRow>.GetEnumerator()
}
public ICellRange<ICell> GetCells(string range)
{
throw new NotImplementedException();
if(string.IsNullOrWhiteSpace(range))
{
throw new ArgumentException("cell range cannot be null or empty");
}

var cells = new List<ICell>();

var rangeAddress = new RangeAddress(range);
var startCellAddress = new CellAddress(rangeAddress.FromCell);

for(int i = startCellAddress.Row; i < rangeAddress.Height; i++)
{
for(int j = startCellAddress.Column; j < rangeAddress.Width; j++)
{
var row = this.GetRow(i) ?? CreateRow(i);
var cell = row.GetCell(j) ?? row.CreateCell(j);
cells.Add(cell);
}
}

return SSCellRange<ICell>.Create(
startCellAddress.Row, startCellAddress.Column,
rangeAddress.Height, rangeAddress.Width, cells, typeof(ICell));
}
}
}
16 changes: 7 additions & 9 deletions ooxml/XSSF/UserModel/XSSFSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6470,28 +6470,26 @@ public ICellRange<ICell> GetCells(string range)
{
if(string.IsNullOrWhiteSpace(range))
{
throw new ArgumentException("range cannot be null or empty");
throw new ArgumentException("cell range cannot be null or empty");
}

var cells = new List<ICell>();

var rangeAddress = new RangeAddress(range);
var startCellAddress = new CellAddress(rangeAddress.FromCell);
var firstColumn = startCellAddress.Column;
var firstRow = startCellAddress.Row;
var height = rangeAddress.Height;
var width = rangeAddress.Width;
for(int i = firstRow; i < height; i++)

for(int i = startCellAddress.Row; i < rangeAddress.Height; i++)
{
for(int j = firstColumn; j < width; j++)
for(int j = startCellAddress.Column; j < rangeAddress.Width; j++)
{
var row = this.GetRow(i) ?? CreateRow(i);
var cell = row.GetCell(j) ?? row.CreateCell(j);
cells.Add(cell);
}
}

return SSCellRange<ICell>.Create(firstRow, firstColumn, height, width, cells, typeof(ICell));
return SSCellRange<ICell>.Create(
startCellAddress.Row, startCellAddress.Column,
rangeAddress.Height, rangeAddress.Width, cells, typeof(ICell));
}
}
}

0 comments on commit 94cbe69

Please sign in to comment.