0

このマクロを python 2.7 に翻訳したいのですが、

Sheets("Données CENTRE").Select
Columns("A:G").Select
    Application.CutCopyMode = False
    ActiveWorkbook.Worksheets("Données CENTRE").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Données CENTRE").Sort.SortFields.Add Key:=Range("A2:A4644" _
        ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Données CENTRE").Sort.SortFields.Add Key:=Range("B2:B4644" _
        ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Données CENTRE").Sort.SortFields.Add Key:=Range("C2:C4644" _
        ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Données CENTRE").Sort.SortFields.Add Key:=Range("D2:D4644" _
        ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Données CENTRE").Sort
        .SetRange Range("A1:G4644")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With

ただし、Excel のドキュメントによると、SortRange は Sort オブジェクトでのみ呼び出されると想定されています。

しかし、pythonは私に言っています:Sortインスタンスにはcallメソッドがありません

これが私が翻訳した方法です:

ws = wb.Sheets("Données Centre")
ws.Columns("A:G").Select
ws.Sort.SortFields.Clear()
ws.Sort.SortFields.Add(Key=ws.Range("A2:A4644"),
                       SortOn=constants.xlSortOnValues,
                       Order=constants.xlAscending,
                       DataOption=constants.xlSortNormal)

ws.Sort.SortFields.Add(Key=ws.Range("B2:B4644"),
                           SortOn=constants.xlSortOnValues,
                           Order=constants.xlAscending,
                           DataOption=constants.xlSortNormal)

ws.Sort.SortFields.Add(Key=ws.Range("C2:C4644"),
                       SortOn=constants.xlSortOnValues,
                       Order=constants.xlAscending,
                       DataOption=constants.xlSortNormal)

ws.Sort.SortFields.Add(Key=ws.Range("D2:D4644"),
                       SortOn=constants.xlSortOnValues,
                       Order=constants.xlAscending,
                       DataOption=constants.xlSortNormal)

ws.Sort(Header=constants.xlYes,
        MatchCase=False,
        Orientation=constants.xlTopToBottom,
        SortMethod=constants.xlPinYin).SetRange(ws.Range("A1:G4644")).Apply()

私はかなり迷っています

4

1 に答える 1

0

最後に方法を見つけました:

ws.Range("A1:G4644").Sort(Key1=ws.Range("A1:G4644"),
                          Header=constants.xlYes,
                          MatchCase=False,
                          Orientation=constants.xlTopToBottom,
                          SortMethod=constants.xlPinYin)
于 2013-05-07T13:38:35.757 に答える