Sheet Custom Property – Get Sheet Custom Properties To CSV String
Converts the custom properties of an Excel worksheet into a CSV-formatted string.
VB
Public Function xlGetSheetCustomPropertiesToCSVstring(sheet As Worksheet,
Optional Separator As String = ";") As String
If sheet Is Nothing Then Throw New ArgumentNullException(NameOf(sheet))
Dim sb As New System.Text.StringBuilder()
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)
sb.AppendLine($"{prop.Name}{Separator}{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 sb.ToString()
End Function