'Multi-values needs to be exported to excel to different rows using lotus script
I was trying to export the Multi-valued field but couldn't able to achieve it. i tried Ubound to export but the scenario is I need the 1st value in 1st row and 2nd value in 2nd row vice versa. Please help me to solve this. I'm using excel application to export the data.
Thanks in advance.
ForAll b In fieldList
If UBound(doc.getitemvalue(b)) <1 Then
worksheet.cells(i,j).value =doc.getitemvalue(CStr(b))
Else
'Join(doc.getitemvalue(CStr(b)),Chr(10))
worksheet.cells(i,j).value =Join(doc.getitemvalue(CStr(b)),Chr(10))
End If
End Forall
Solution 1:[1]
Create a loop that goes through all the values for each field by index ("x" in my code sample). Use x again to offset the row value.
You will have a problem that each fieldName's values will be overwritten in the spreadsheet, because i and j are always the same, so if you have more than one fieldName in your fieldList you will need to do something about that too. In my example, I have incremented j for each fieldName so that they will be in different spreadsheet columns
ForAll fieldName In fieldList
For x = LBound(doc.getitemvalue(fieldName)) to Ubound(doc.getitemvalue(fieldName))
worksheet.cells(i + x, j).value = doc.getitemvalue(fieldName)(x)
Next
j = j + 1
End Forall
Alternative version to achieve what you ask in your comment:
ForAll fieldName In fieldList
For x = LBound(doc.getitemvalue(fieldName)) to Ubound(doc.getitemvalue(fieldName))
worksheet.cells(i, j + x).value = doc.getitemvalue(fieldName)(x)
Next
i = i + 1
End Forall
Solution 2:[2]
doc.getitemvalue(CStr(b)) always returns a variant array, even when the Ubound is less than one.
The code in your Then clause needs to dereference the 0th entry of the array:
worksheet.cells(i,j).value =doc.getitemvalue(CStr(b))(0)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tode |
| Solution 2 |
