windows8.1 python2.7
Use Excel like an IDE (Integrated Development Environment).
excel_python |---code_gene.py |---code_gene.xlsx
【Excel】 I wrote a program that outputs a Fibonacci sequence. One cell in Excel becomes one indent in python.
code_gene.py
# -*- coding: utf-8 -*-
from excel import OpenExcel
#File reading
f = OpenExcel('code_generation.xlsx')
# cell_Add cell value to value for each row
cell_value = []
for row in xrange(1, len(f.read('A')) + 1):
cell_value.append(f.read(row))
#Substitute line feed code for line break only line
for row in xrange(len(cell_value)):
kaigyo = ""
for col in xrange(len(cell_value[0])):
kaigyo += kaigyo + cell_value[row][col]
if kaigyo == "":
cell_value[row][0] = "\n"
#Code generation
for row in xrange(len(cell_value)):
for col in xrange(len(cell_value[0])):
if not len(cell_value[row][col]) == 0:
print cell_value[row][col]
break
else:
print " ",
Run this program.
How to execute
python code_gene.py > code.py & python code.py
1 1 2 3 5 8 13 21 34 55
code.py
# -*- coding: utf-8 -*-
def fib(n):
if n < 2:
return 1
else:
return fib(n-1) + fib(n-2)
for i in xrange(10):
print fib(i)
One line break in Excel becomes two line breaks in the output python file.
Aim python library master (12) excel
Recommended Posts