2013-10-30 6 views
18

मैं इस तरह एक मेज लिखने के लिए करना चाहते हैं: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 | 
-------------------- 
+0

@ShivanRaptor मैंने अपना प्रश्न अपडेट किया है। धन्यवाद। –

उत्तर

42

- आप करने के लिए है इसे खोजने के लिए स्रोत कोड पढ़ें। ऐसा करने के लिए Worksheet कक्षा पर दो विधियां हैं, 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 में पॉइंट इंगित करने वाले स्रोत में कुछ टिप्पणियां हैं ntial समस्याओं:

# 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. 

लेकिन यह इस तरह एक साधारण मामले के लिए ठीक होगा।

+1

यह बढ़िया है! धन्यवाद। –

संबंधित मुद्दे