25

次のような表を書きたいと思います。

----------------
| 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    |
--------------------
4

1 に答える 1

66

私が知る限り、これは文書化されていません。ソースコードを読んで見つける必要があります。Worksheetこれを行うクラスには 2 つのメソッドがありwrite_mergeますmergemerge既存のセルを取得してそれらをマージし、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.

しかし、このような単純なケースでは問題ありません。

于 2013-10-30T03:26:34.657 に答える