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

Free Support Forum - aspose.com

Dimensioning Worksheets


I am using Aspose.Cells for .NET

I want to run a routine which will create a new worksheet for each entry in a table - this is variable.

How can I dimension these in a loop eg I would want to create a sheet which would have a primary part of Sht and then add a numeric eg 2 or 3, to give the worksheet an ID of Sht1, Sht2 etc.

In effect Dimensioning the worksheet based on a variable -

dim sht[variable] as Aspose.Cells.Worksheet = wb.Worksheets(variable)
dim sht[variable+1] as Aspose.Cells.Worksheet = wb.Worksheets(variable+1)

Can you please advise

Bob Hamill

Hi Bob,

Thanks for considering Aspose.

Well, I think you may utilize Cells.ImportDataRow() method as one of the many options for your need.

Below is one way to achieve this. May the following sample code help you for your requirement. I used MS Access Northwind database in this example. Attached is the output excel file.

Dim con As OleDbConnection = New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=d:\test\Northwind.mdb")
Dim cmd As OleDbCommand = New OleDbCommand("Select * from employees", con)
Dim da As OleDbDataAdapter = New OleDbDataAdapter
da.SelectCommand = cmd
Dim ds As DataSet = New DataSet
da.Fill(ds, "Employees")
Dim workbook As Workbook = New Workbook
Dim i As Integer
For i = 0 To ds.Tables(0).Rows.Count - 1 Step 1
Dim worksheet As Worksheet = workbook.Worksheets(workbook.Worksheets.Add())
worksheet.Cells.ImportDataRow(ds.Tables(0).Rows(i), 0, 0)
worksheet.Name = "Sht" & i

Thank you.