10-13-2021
12:19 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
10-13-2021
12:19 PM
That rule was only to show how you can read csv files not to set them as parameters. The following rule will read the csv and also set the parameters.
Sub Main() Dim doc As PartDocument = ThisDoc.Document Dim userParameters As UserParameters = doc. ComponentDefinition.Parameters.UserParameters Dim csvData As Dictionary(Of String, String) = ReadCSV("c:\temp\test.csv") For Each item As KeyValuePair(Of String, String) In csvData SetParameter(userParameters, item.Key, item.Value) Next End Sub Public Function ReadCSV(fileName As String) Dim splitChar As String = "," Dim csvData As Dictionary(Of String, String) = New Dictionary(Of String, String)() Using reader As New IO.StreamReader("c:\temp\test.csv", Text.Encoding.Default) Dim line As String = reader.ReadLine Do While (Not line Is Nothing) Try Dim splittedLine As String() = line.Split(splitChar) csvData.Add(splittedLine(0), splittedLine(1)) Catch ex As Exception MsgBox("Could not add data from line: " & line) End Try line = reader.ReadLine Loop End Using Return csvData End Function Public Sub SetParameter(userParameters As UserParameters, name As String, expresion As String) Dim foundPara As UserParameter = userParameters.Cast(Of UserParameter). Where(Function(p) Return p.Name.Equals(name) End Function).FirstOrDefault() If (foundPara Is Nothing) Then userParameters.AddByExpression(name, expresion, "mm") Else foundPara.Expression = expresion End If End Sub
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com