Python xlsxwriter: How do I write a formula that references a different sheet
<p>I'm trying to add a excel file that includes a formula referencing
a different sheet.</p>

<p>In this example, I try to copy the word "world" from sheet 2 to sheet 1.</p>

<pre><code>import xlsxwriter

workbook = xlsxwriter.Workbook('hello.xlsx')
sheet1 = workbook.add_worksheet(name='Sheet 1')
sheet2 = workbook.add_worksheet(name='Sheet 2')
sheet2.write(2,2,'world')
sheet1.write(2,2,'hello')
sheet1.write_formula('D3', "='Sheet 2'.C3")

workbook.close()
</code></pre>

<p>The resulting xlsx file, when openened, displays the fomula in 
lower case. The formula does not work when I press Ctrl+Shift+F9 
to recalculate all formulas.</p>

<p>If I type the formula manually, it works.</p>

<p>Is is possible to reference others sheets when creating xlsxwriter excel files?</p>

<p>I'm using Open Office 5 to display the file. </p>

<p>The formula needs to be in the US Excel syntax, like the following (note <code>!</code> not <code>.</code>):</p>

<pre><code>sheet1.write_formula('D3', "='Sheet 2'!C3")
</code></pre>

<p>See the <a href="https://xlsxwriter.readthedocs.io/working_with_formulas.html" rel="nofollow">Working with Formulas</a> section of the XlsxWriter docs.</p>

python python-3.x excel-formula openoffice-calc xlsxwriter