Python programming in Excel

【environment】

windows8.1  python2.7

【Overview】

Use Excel like an IDE (Integrated Development Environment).

[Folder structure]

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. exce..png

【program】

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

【Execution result】

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)

【problem】

One line break in Excel becomes two line breaks in the output python file.

[Reference site]

Aim python library master (12) excel

Recommended Posts

Python programming in Excel
Programming in python
GUI programming in Python using Appjar
Functional programming in Python Project Euler 3
Functional programming in Python Project Euler 2
web coder tried excel in Python
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Python programming note
SendKeys in Python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Excel with Python
Flatten in python
flatten in python
Draw Nozomi Sasaki in Excel with python
Scientific Programming Petit Tech Collection in Python
Try a functional programming pipe in Python
Learn dynamic programming in Python (A ~ E)
Sorted list in Python
Daily AtCoder # 36 in Python
Clustering text in Python
Daily AtCoder # 2 in Python
Implement Enigma in python
Daily AtCoder # 32 in Python
Daily AtCoder # 6 in Python
Daily AtCoder # 18 in Python
Edit fonts in Python
Singleton pattern in Python
File operations in Python