0

我正在尝试使用 wp all import pro 插件创建一个 Woocommerce 食品店。我需要上传产品列表及其变体。

首先,我在 excel 中有一个产品列表,我将在其中放置所有信息。该列表包含价格、盘子大小、每个盘子可能有多少配菜以及配菜的可能变化等变量。这是示例:

产品列表

要创建导入文件,让我在将其导入 woocomerce 时一次完成所有变体,我需要生成一个带有显示值的 spreedshet,如下所示:

变化图

我知道VBA可以做到这一点,但我不知道该怎么做,所以我问是否有人可以帮助我?

[解决了]

大家好。感谢您的支持,但我设法做我不会在 excel 中使用这个 vba 代码的事情,我在 woo commercer 中必须做的唯一想法是导入具有相同 ID 的产品,在我的情况下是 skuparent。我把代码留在这里,所以如果有人需要使用它,只需在需要时添加它。再次感谢。问候马可

这是代码:



Sub ProductVariations()

Dim productRow As Long, variationRow As Long
Dim tamanho As String
Dim prim_acomp As String
Dim seg_acomp As String
Dim ter_acomp As String
Dim quar_acomp As String
Dim tamanhoArray() As String
Dim prim_acompArray() As String
Dim seg_acompArray() As String
Dim ter_acompArray() As String
Dim quar_acompArray() As String
Dim tamanhoElement As Variant
Dim prim_acompElement As Variant
Dim seg_acompElement As Variant
Dim ter_acompElement As Variant
Dim quar_acompElement As Variant
Dim productsSheet As Worksheet
Dim variationsSheet As Worksheet

productRow = 2
variationRow = 2

Set productsSheet = ActiveWorkbook.Sheets(1)
Set variationSheet = ActiveWorkbook.Sheets(2)

'loop through each row until a blank row is found
While productsSheet.Cells(productRow, 1).Value <> ""

   'get the size and color values for the current row
   tamanho = productsSheet.Cells(productRow, 5)
   prim_acomp = productsSheet.Cells(productRow, 7)
   seg_acomp = productsSheet.Cells(productRow, 8)
   ter_acomp = productsSheet.Cells(productRow, 9)
   quar_acomp = productsSheet.Cells(productRow, 9)

   'make sure a size and color exists then process
   If Len(tamanho) > 0 And Len(prim_acomp) > 0 And Len(seg_acomp) > 0 And Len(ter_acomp) > 0 And Len(quar_acomp) > 0 Then



       'split the size and color into arrays
       tamanhoArray = Split(tamanho, "|")
       prim_acompArray = Split(prim_acomp, "|")
       seg_acompArray = Split(seg_acomp, "|")
       ter_acompArray = Split(ter_acomp, "|")
       quar_acompArray = Split(quar_acomp, "|")

       'loop through each size
       For Each tamanhoElement In tamanhoArray

           'loop through each color
           For Each prim_acompElement In prim_acompArray

                'loop through each seg_acomp
           For Each seg_acompElement In seg_acompArray

                    'loop through each ter_acomp
           For Each ter_acompElement In ter_acompArray

                        'loop through each quar_acomp
           For Each quar_acompElement In quar_acompArray


               'set the appropriate cells in the variations sheet (you have some more work to do here (é aqui que diz quais as colunas a mostrar)


               variationSheet.Cells(variationRow, 1).Value = productsSheet.Cells(productRow, 1)
               variationSheet.Cells(variationRow, 2).Value = productsSheet.Cells(productRow, 2)
               variationSheet.Cells(variationRow, 3).Value = productsSheet.Cells(productRow, 3)
               variationSheet.Cells(variationRow, 4).Value = productsSheet.Cells(productRow, 4)

                variationSheet.Cells(variationRow, 6).Value = productsSheet.Cells(productRow, 6)

                variationSheet.Cells(variationRow, 11).Value = productsSheet.Cells(productRow, 11)
                variationSheet.Cells(variationRow, 12).Value = productsSheet.Cells(productRow, 12)
                variationSheet.Cells(variationRow, 13).Value = productsSheet.Cells(productRow, 13)


                variationSheet.Cells(variationRow, 5).Value = tamanhoElement
                variationSheet.Cells(variationRow, 7).Value = prim_acompElement
                variationSheet.Cells(variationRow, 8).Value = seg_acompElement
                variationSheet.Cells(variationRow, 9).Value = ter_acompElement
                variationSheet.Cells(variationRow, 10).Value = quar_acompElement





               'increment the variation row so the next variation goes in the next row
               variationRow = variationRow + 1

                        Next quar_acompElement

                    Next ter_acompElement

                Next seg_acompElement

           Next prim_acompElement

       Next tamanhoElement

   End If

   'very important increment the next row or only the first row will ever get processed
   productRow = productRow + 1
Wend
End Sub

4

0 回答 0