私が知る限り、これは文書化されていません。ソースコードを読んで見つける必要があります。Worksheet
これを行うクラスには 2 つのメソッドがあり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.
しかし、このような単純なケースでは問題ありません。