Skip to content

Commit

Permalink
Starting to export tables to docx
Browse files Browse the repository at this point in the history
  • Loading branch information
Huyston committed Mar 19, 2017
1 parent 9fdb7c2 commit 6d6720b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Binary file added __pycache__/docxExporter.cpython-35.pyc
Binary file not shown.
24 changes: 24 additions & 0 deletions docxExporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,30 @@ def addFigure(self,img,caption,source='',label='',width='0.5'):
self.figNumber += 1
self.document.add_paragraph() #pula linha

def addTable(self,table,caption,label):
cols = 0
for row in table.split('\n'):
rowCols = 0
if '||' in row:
rowCols = len(row.split('||'))
elif '|' in row:
rowCols = len(row.split('|'))
if rowCols > cols:
cols = rowCols

docxTable = self.document.add_table(rows=1,cols=cols)
for row in table.split('\n'):
if '||' in row:
headings = row.split('||')
hCells = docxTable.add_row().cells
for n,heading in enumerate(headings):
hCells[n].text = heading
elif '|' in row:
colText = row.split('||')
hCells = docxTable.add_row().cells
for n,text in enumerate(colText):
hCells[n].text = text

def close(self):
self.document.save(os.getcwd()+'/Archieves/'+self.filename+'.docx')

Expand Down
13 changes: 13 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,19 @@ def saveAs(self,docID,filename,docFormat,article=True):
exporter.addFigure(img,caption,source=source,label=label,width=width)
else:
raise NotImplemented
elif '!tab' in content:
caption = ''
label = ''
table = ''
for row in content.split('\n'):
if '!tab' in row:
label = row.replace('!tab ','')
elif not '|' in row:
if row:
caption = row
else:
table += row+'\n'
exporter.addTable(table,caption,label)
else:
if show:
exporter.addText(cell['output'])
Expand Down

0 comments on commit 6d6720b

Please sign in to comment.