programing

xlwt로 여러 열로 셀을 작성하는 방법은 무엇입니까?

oldcodes 2023. 4. 29. 09:52
반응형

xlwt로 여러 열로 셀을 작성하는 방법은 무엇입니까?

저는 다음과 같은 표를 작성하고 싶습니다.

----------------
| Long Cell    |
----------------
| 1    | 2     |
----------------

셀 작성 방법Long Cell감사합니다.

저는 이렇게 하려고 노력했습니다.

sheet.write(0, 0, 'Long Cell')
sheet.write(1, 0, 1)
sheet.write(1, 1, 2)

하지만 다음과 같이 끝납니다.

--------------------
| Long Cell |      |
--------------------
| 1         | 2    |
--------------------

제가 아는 한, 이것은 문서화되어 있지 않습니다. 당신은 그것을 찾기 위해 소스 코드를 읽어야 합니다.두 가지 방법이 있습니다.Worksheet수업이 이렇게 할 수 있습니다.write_merge그리고.merge.merge기존 셀을 가져와서 병합하는 동안write_merge라벨을 작성합니다(와 동일).write) 그리고 나서 같은 일을 합니다.merge한다.

둘 다 셀을 병합합니다.r1, r2, c1, c2선택 사항을 수락합니다.style매개 변수

예를 들어, 이것은 가장 간단한 호출입니다.

sheet.write_merge(0, 0, 0, 1, 'Long Cell')
sheet.write(1, 0, 1)
sheet.write(1, 1, 2)

통화 방식을 보다 명확하게 설명하기 위해:

top_row = 0
bottom_row = 0
left_column = 0
right_column = 1
sheet.write_merge(top_row, bottom_row, left_column, right_column, 'Long Cell')

또는 사용merge:

sheet.write(top_row, left_column, 'Long Cell')
sheet.merge(top_row, bottom_row, left_column, right_column)

merge에는 잠재적인 문제를 지적하는 몇 가지 의견이 있습니다.

    # Problems: (1) style to be used should be existing style of
    # the top-left cell, not an arg.
    # (2) should ensure that any previous data value in
    # non-top-left cells is nobbled.
    # Note: if a cell is set by a data record then later
    # is referenced by a [MUL]BLANK record, Excel will blank
    # out the cell on the screen, but OOo & Gnu will not
    # blank it out. Need to do something better than writing
    # multiple records. In the meantime, avoid this method and use
    # write_merge() instead.

하지만 이런 간단한 경우에는 괜찮을 것입니다.

언급URL : https://stackoverflow.com/questions/19672760/how-to-write-a-cell-with-multiple-columns-in-xlwt

반응형