Python Learners

Python · Posted by Quanta task

Quanta task

Those who are learning Python can help each other out here. If you already know Python , you can complete our Python Course and move on to completing tasks for companies.

Guest


for Working with Excel Spreadsheets
corretion 1:
>>> import openpyxl

>>> from openpyxl.cell import get_column_letter, column_index_from_string # not working

>>> get_column_letter(1)
'A'

cange to:
>>> import openpyxl
# >>> from openpyxl.cell import get_column_letter, column_index_from_string
from openpyxl.utils import get_column_letter, column_index_from_string # change to this
>>> get_column_letter(1)
'A'

corretion 2: 
>>> import openpyxl
>>> wb = openpyxl.load_workbook('example.xlsx')
>>> sheet = wb.active

>>> sheet.columns[1] # not working 

(<Cell Sheet1.B1>, <Cell Sheet1.B2>, <Cell Sheet1.B3>, <Cell Sheet1.B4>,
<Cell Sheet1.B5>, <Cell Sheet1.B6>, <Cell Sheet1.B7>)

>>> for cellObj in sheet.columns[1]: #not working

        print(cellObj.value)

chang to :

# >>> sheet.columns[1] # not working 

>>> list(sheet.columns)[1] 

(<Cell Sheet1.B1>, <Cell Sheet1.B2>, <Cell Sheet1.B3>, <Cell Sheet1.B4>,
<Cell Sheet1.B5>, <Cell Sheet1.B6>, <Cell Sheet1.B7>)

# >>> for cellObj in sheet.columns[1]: #not working

>>> for cellObj in list(sheet.columns)[1]:

        print(cellObj.value




Ho min bang 1040 points

get testing files for studing python

https://github.com/crystalDf/Automate-the-Boring-Stuff-with-Python-Chapter-13-PDF-and-Word/find/master

Ho min bang 1040 points

error on adding page break for docx like fellowing:

Exception has occurred: AttributeError
module 'docx.text' has no attribute 'WD_BREAK'
  File "C:\Users\Win 7 TV\PycharmProjects\quantatask\python\webScraping\testing.py", line 51, in <module>
    doc.paragraphs[0].runs[0].add_break(docx.text.WD_BREAK.PAGE)

++++
import docx

doc = docx.Document()
doc.add_paragraph('This is on the first page!')
# <docx.text.Paragraph object at 0x0000000003785518>
doc.paragraphs[0].runs[0].add_break(docx.text.WD_BREAK.PAGE)
# doc.paragraphs[0].runs[0].add_break(WD_BREAK.PAGE)


<to Fix> 
import docx

from docx.text.run import * # ++ add ++

doc = docx.Document()
doc.add_paragraph('This is on the first page!')

# doc.paragraphs[0].runs[0].add_break(docx.text.WD_BREAK.PAGE) # and change to blow line
doc.paragraphs[0].runs[0].add_break(WD_BREAK.PAGE)