使用Lotus脚本,需要将多价值导出到不同行

发布于 2025-01-27 05:29:49 字数 391 浏览 5 评论 0原文

我试图导出多价值领域,但无法实现它。我尝试了UBOUND的导出,但是情况是我需要第一行中的第一值,反之亦然。请帮助我解决这个问题。我正在使用Excel应用程序导出数据。

提前致谢。

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

他不在意 2025-02-03 05:29:49

创建一个循环,通过索引遍历每个字段的所有值(我的代码示例中的“ x ”)。再次使用 x 再次抵消行值。

您会遇到一个问题,每个 fieldName 的值都会在电子表格中覆盖,因为 i j 始终是相同的,因此您在 fieldlist 中有多个 fieldname ,您也需要对此做些事情。在我的示例中,我已经为每个 fieldname 增加了 j ,以便它们将在不同的电子表格列中

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

替代版本,以实现您在评论中提出的内容:

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

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
岁吢 2025-02-03 05:29:49

假设以下文档:

字段名称值0值1值2
first fieldvalition toers toerst
二次字段值0秒value1value2秒秒
第三场vality0-third valit

解决方案1:
如果您希望结果看起来像这个

第一场Field FieldThirdfield
value0-fortvaluer0-ecdvalue0-third
value1-secondvalue1-third
value2秒2秒,

则使用以下代码:

cellY = 2
cellX = 1
Forall fieldName in fieldNameList
  For y = 0 to ubound( doc.GetitemValue( fieldName ) )
    worksheet.cells(cellY + y, cellX).value = doc.GetitemValue( fieldName )(y)
  Next
  cellX = cellX + 1
End Forall

solution 2 :如果您想要the result to look like this

FieldnameValue 0Value 1Value 2
FirstFieldValue0-First
SecondFieldValue0-SecondValue1-SecondValue2-Second
ThirdFieldValue0-ThirdValue1-Third

Then you use the following code:

cellY = 1
cellX = 2
Forall fieldName in fieldNameList
  For x = 0 to ubound( doc.GetitemValue( fieldName ) )
    worksheet.cells(cellY, cellX+x).value = doc.GetitemValue( fieldName )(x)
  Next
  cellY = cellY + 1
End Forall

Solution 3:
如果您希望结果看起来像这样的

所有字段
first first
valit valie0 first
个秒
第二
value 1秒value2 value2-second second
virate0-third value1-third
value1
-
third third third third third third third third third third third third third third third third

thirp

cellY = 1
cellX = 1
Forall fieldName in fieldNameList
  worksheet.cells(cellY, cellX).value = fieldName
  For y = 0 to ubound( doc.GetitemValue( fieldName ) )
    cellY = cellY + 1
    worksheet.cells(cellY, cellX).value = doc.GetitemValue( fieldName )(y)
  Next
  cellY = cellY + 1
End Forall

Lets assume the following document:

FieldnameValue 0Value 1Value 2
FirstFieldValue0-First
SecondFieldValue0-SecondValue1-SecondValue2-Second
ThirdFieldValue0-ThirdValue1-Third

Solution 1:
If you want the result to look like this

FirstFieldSecondFieldThirdField
Value0-FirstValue0-SecondValue0-Third
Value1-SecondValue1-Third
Value2-Second

Then you use the following code:

cellY = 2
cellX = 1
Forall fieldName in fieldNameList
  For y = 0 to ubound( doc.GetitemValue( fieldName ) )
    worksheet.cells(cellY + y, cellX).value = doc.GetitemValue( fieldName )(y)
  Next
  cellX = cellX + 1
End Forall

Solution 2: If you want the result to look like this

FieldnameValue 0Value 1Value 2
FirstFieldValue0-First
SecondFieldValue0-SecondValue1-SecondValue2-Second
ThirdFieldValue0-ThirdValue1-Third

Then you use the following code:

cellY = 1
cellX = 2
Forall fieldName in fieldNameList
  For x = 0 to ubound( doc.GetitemValue( fieldName ) )
    worksheet.cells(cellY, cellX+x).value = doc.GetitemValue( fieldName )(x)
  Next
  cellY = cellY + 1
End Forall

Solution 3:
If you want the result to look like this

All fields
FirstField
Value0-First
SecondField
Value0-Second
Value1-Second
Value2-Second
ThirdField
Value0-Third
Value1-Third

Then you use the following code:

cellY = 1
cellX = 1
Forall fieldName in fieldNameList
  worksheet.cells(cellY, cellX).value = fieldName
  For y = 0 to ubound( doc.GetitemValue( fieldName ) )
    cellY = cellY + 1
    worksheet.cells(cellY, cellX).value = doc.GetitemValue( fieldName )(y)
  Next
  cellY = cellY + 1
End Forall
执手闯天涯 2025-02-03 05:29:49

doc.getItemvalue(cstr(b))始终返回变体数组,即使ubound少于一个。

然后,您的中的代码然后条款需要放置数组的0个条目:

worksheet.cells(i,j).value =doc.getitemvalue(CStr(b))(0)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文