We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Re-sizing a Range within a Worksheet

We are transitioning from using Microsoft’s Excel libraries in .NET to Aspose. Is there a way I can dynamically modify a range’s size within a worksheet?

Code using Microsoft library:
xlSheet.Range(“A2”).Resize(oDTView.Rows.Count, oDTView.Columns.Count)

I’m trying to do something similar so that when I import a datatable, and refresh my pivot tables, it will pick up all the data.



Well, you may try to use Named Range feature accordingly, see a sample code segment below:
Workbook workbook = new Workbook();
Worksheet sheetRef = workbook.Worksheets[0];
NameCollection names = workbook.Worksheets.Names;
Name name = names[names.Add(“MyRange”)];
name.RefersTo = “=A1:D10”;
//name.R1C1RefersTo 1 = “=Sheet1!R2C10”;

Also, see a topic for reference:


Thank you.

Hi Amjad, thanks for the quick reply.

I looked at the documentation you referenced and couldn’t find what I was trying to do. I ended up using your example somewhat.

Dim oRange As Aspose.Cells.Range = xlSheet.Cells.CreateRange(1, 0, oDTView.Rows.Count, oDTView.Columns.Count)
oRange.Name = “DataSource”
For k As Integer = 0 To oDTView.Rows.Count - 1
For l As Integer = 0 To oDTView.Columns.Count - 1
If l = 0 Then
oRange(k, l).PutValue("’" & IIf(oDTView.Rows(k).Item(l) Is DBNull.Value, “”, oDTView.Rows(k).Item(l)))
oRange(k, l).PutValue(oDTView.Rows(k).Item(l))
End If