Sheet Custom Property – Get Sheet Custom Properties To Datatable
Extracts all custom document properties from the specified Excel worksheet and returns them as a DataTable.
VB
Public Function xlGetSheetCustomPropertiesToDatatable(sheet As Worksheet) As Data.DataTable
If sheet Is Nothing Then Throw New ArgumentNullException(NameOf(sheet))
' Create the output DataTable
Dim dt As New Data.DataTable()
dt.Columns.Add("Property", GetType(String))
dt.Columns.Add("Value", GetType(String))
Try
Dim props As Object = sheet.CustomProperties
If props IsNot Nothing Then
For i As Integer = 1 To props.Count
Dim prop As CustomProperty = CType(props.Item(i), CustomProperty)
dt.Rows.Add(prop.Name, prop.Value)
Next
End If
Catch ex As Exception
' Optionally log the error or rethrow
Throw New Exception("Error reading CustomProperties: " & ex.Message, ex)
End Try
Return dt
End Function