1

我有一个需要打印在贴纸上的数据列表(想象一下 Avery 那种)。我无法提出将产生所需结果的代码:

到目前为止,我的代码是:

With wsEtiketten
    ' erase old data
    .Cells.Clear
    ' enter new data
    With .Cells(1, 2)
        .Value = "Lettrine"
        .Font.Bold = True
    End With
    .Cells(2, 2).Value = sAuswertungsLettrine
    For i = 0 To MaxRow - 1
        For j = 0 To 4
            r.Copy .Cells(4, 2).Offset(i * 5, j * 5)
            .Cells(4, 2).Offset((i * 5) + 1, (j * 5) + 0) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 1).Value 'Page
            .Cells(4, 2).Offset((i * 5) + 1, (j * 5) + 1) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 2).Value 'Ordernr
            .Cells(4, 2).Offset((i * 5) + 1, (j * 5) + 2) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 8).Value 'Surf
            .Cells(4, 2).Offset((i * 5) + 1, (j * 5) + 3) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 9).Value 'Indice DB
            .Cells(4, 2).Offset((i * 5) + 3, (j * 5) + 0) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 3).Value 'Count
            .Cells(4, 2).Offset((i * 5) + 3, (j * 5) + 1) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 4).Value 'CA Brut
            .Cells(4, 2).Offset((i * 5) + 3, (j * 5) + 3) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 7).Value 'Marge
        Next j
    Next i
End With

与之相关的信息只是在行中重复。每次字段偏移时,我都需要更改。我怎样才能做到这一点?我敢肯定这可能是编程幼儿园的东西,但我不明白。

谢谢!

4

2 回答 2

2

也许是一个出人意料的答案。您也可以将 Excel 表格与 Word 结合使用来获得您想要的结果。这是标准的 Office 功能:

http://support.microsoft.com/kb/318117/en

或德语:

http://support.microsoft.com/kb/318117/de

于 2012-11-07T12:09:02.650 回答
1

好的。我设法在 Excel 中找到答案。一旦我有了它,它就很明显了。开始:

With wsEtiketten
    ' Alte Daten werden gelöscht
    .Cells.Clear
    ' Neue Daten werden eingelesen
    With .Cells(1, 2)
        .Value = "Lettrine"
        .Font.Bold = True
    End With
    .Cells(2, 2).Value = sAuswertungsLettrine
    For i = 0 To MaxRow - 1
            r.Copy .Cells(4, 2).Offset(WorksheetFunction.RoundDown(i / 5, 0) * 5, ((i + 5) Mod 5) * 5)
            .Cells(4, 2).Offset((WorksheetFunction.RoundDown(i / 5, 0)) * 5 + 1, ((i + 5) Mod 5) * 5 + 0) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 1).Value 'Page
            .Cells(4, 2).Offset((WorksheetFunction.RoundDown(i / 5, 0)) * 5 + 1, ((i + 5) Mod 5) * 5 + 1) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 2).Value 'Bestellnummer
            .Cells(4, 2).Offset((WorksheetFunction.RoundDown(i / 5, 0)) * 5 + 1, ((i + 5) Mod 5) * 5 + 2) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 8).Value 'Surf
            .Cells(4, 2).Offset((WorksheetFunction.RoundDown(i / 5, 0)) * 5 + 1, ((i + 5) Mod 5) * 5 + 3) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 9).Value 'Indice DB
            .Cells(4, 2).Offset((WorksheetFunction.RoundDown(i / 5, 0)) * 5 + 3, ((i + 5) Mod 5) * 5 + 0) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 3).Value 'Anzahl
            .Cells(4, 2).Offset((WorksheetFunction.RoundDown(i / 5, 0)) * 5 + 3, ((i + 5) Mod 5) * 5 + 1) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 4).Value 'CA Brut
            .Cells(4, 2).Offset((WorksheetFunction.RoundDown(i / 5, 0)) * 5 + 3, ((i + 5) Mod 5) * 5 + 3) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 7).Value 'Marge
    Next i
End With
于 2012-11-12T09:19:41.473 回答