Python Openpyxl, copy and paste cell range
<p>I know how to select a cell range in Openpyxl:</p>

<pre><code>cell_range = sheet['A1':'C3']
</code></pre>

<p>How can I paste cell_range above to another range, like <code>sheet['A11':'C13']</code>?</p>

<p>I don't think there is a slicing notation exactly as described in your example, mostly because <code>openpyxl</code> uses lists of <code>Cell</code>s rather than lists of plain values.</p>

<p>Here is the basic flow I would use to grab just a part of a sheet.</p>

<pre><code>&gt;&gt;&gt; wb = openpyxl.load_workbook(file_name)
&gt;&gt;&gt; sheet = wb.worksheets[0]
&gt;&gt;&gt; rows = sheet.rows[1:3]                                      # slice rows
&gt;&gt;&gt; foobar = [cell.value for row in rows for cell in row[3:10]] # slice row
</code></pre>

<p><strong><em>EDIT:</em></strong>  From <a href="http://stackoverflow.com/questions/3680262/how-to-slice-a-2d-python-array-fails-with-typeerror-list-indices-must-be-int">this question</a> it looks like you can do something like this:</p>

<pre><code>foo = [row[start_col:end_col] for row in sheet.rows[start_row:end_row]]
</code></pre>

<p>Which will give you a list of lists <em>of cells</em>.  Remember to use <code>foo[i][j].value</code> to get the contents of a <code>cell</code>.</p>

python excel openpyxl