Search function in worksheet


#1

Hi Laurence,



Just wondering if there is any function in Aspose.excel that allows me
to search worksheet name. Say each worksheet in workbook is named as A,
B, C, D… and if user passes C, the system needs to find the data from
worksheet C. Is it possible?



Thank you





#2

To access worksheet with specified name, please use the following sample code:

Worksheet sheet = excel.Worksheets["C"];


#3

Sorry was not clear with my question.

The main purpose for the function I am looking for is to check if the worksheet exists. For example, a dataset will return all different userName, and it's possible to have duplicates i.e. more than one row return the same userName. I would like to loop through the dataset, and add worksheet named as userName.

for each row in dataset.rows
If NOT exists worksheet.name = row.Item("userName").tostring
Add new worksheet
worksheet.name = row.Item("userName").tostring
make the worksheet
end if
end for

Thank


#4

It's not supported yet. Currently you have to manage it by yourself. Following is the sample code:

Dim nameTable As Hashtable = New Hashtable()
Dim i As Integer
For i = 0 To excel.Worksheets.Count- 1
Dim name As String = excel.Worksheets(i).Name
nameTable(name) = name
Next

For Each row In dataset.Rows
If nameTable(row("UserName").ToString()) Is Nothing Then
'Add new worksheet
.....
nameTable(row("UserName").ToString()) = row("UserName").ToString()
End If
Next