How to export one cell of a jupyter notebook?
See this stack question

You can use %%capture Jupyter notebook' magic command to catch output of cell and then paste it to your text file with 

with open('output.txt', 'w') as out:
   out.write(cap.stdout)


if you want to cell code to specific file for example code.txt you can use magic function %%writefile

%%writefile example.txt
ab = 'This is code'
a = 5
print(a+ 2)


Also if you want to append to file you must use -a parameter