Reading worksheets: Free Reading Comprehension Worksheets — Printable

Posted on

Browse Reading Worksheets & Printables

Skip to content

Our reading worksheets cover a variety of topics including alphabet and letter recognition, phonics, reading comprehension, sight words, vocabulary and emergent reader books. Hands-on activities will support your child and challenge him to solve puzzles, play bingo games, and word search.

Sort by

Alesia Netuk2022-12-23T17:16:47-05:00

Help your kindergartener build a strong reading comprehension skills. With this an word family story, she will read and spot some words.

Short Story. The Cat and the Rat.Alesia Netuk2022-12-23T17:16:47-05:00

Alesia Netuk2022-12-23T17:16:43-05:00

With this worksheet, kids learn to read, trace and build the word SET. Kids practice identifying the short medial vowel in the word and practice ET family words. Kids cut out cards and the bottom of the page and paste the letters to build a word.

Short Story. Dad and his pad.Alesia Netuk2022-12-23T17:16:43-05:00

Alesia Netuk2022-12-23T17:16:44-05:00

With this short ad word family story, children practice reading comprehension skills. Read, answer questions, glue the pictures… and more!

Short Story. Dan and his Van.Alesia Netuk2022-12-23T17:16:44-05:00

Alesia Netuk2022-12-23T16:46:10-05:00

In this non-fiction passage, students learn about the zebra. Where does the zebra live? What does it eat? How does it look like?

Zebra Reading PassageAlesia Netuk2022-12-23T16:46:10-05:00

Alesia Netuk2022-12-23T15:59:32-05:00

This worksheet introduces a child to sight word sentences that correlate with sight words she just learned. Pre-primer Dolch sight words reading practice set 1 includes words: the, to, and, a, I, you, it, in, said, for.

Sight Words Reading Practice | List 10Alesia Netuk2022-12-23T15:59:32-05:00

Alesia Netuk2022-12-23T17:16:52-05:00

Help your kindergartener get more confident with her reading skills. Word families encourage students to see letter-sound patterns.

Short Story. Where is my Ham?Alesia Netuk2022-12-23T17:16:52-05:00

Alesia Netuk2022-12-23T16:56:05-05:00

Students read all about the Life Cycle of a Chicken. They explore each stage in detail and connect it to the picture on aside. Great for your life cycle lesson.

All About Life Cycle of a Chicken for KidsAlesia Netuk2022-12-23T16:56:05-05:00

Alesia Netuk2022-12-23T16:33:26-05:00

This worksheet features pictures of things that begin with the letter A: angel, apple, alien, apron, alligator, acorn, astronaut, axe.

Things That Begin With The Letter AAlesia Netuk2022-12-23T16:33:26-05:00

Alesia Netuk2022-12-23T16:58:47-05:00

Students read the article and learn how turtle undergoes a complete metamorphosis. Students explore each stage of turtle life cycle and look at the pictures.

Turtle Life Cycle ArticleAlesia Netuk2022-12-23T16:58:47-05:00

Alesia Netuk2022-12-23T16:52:07-05:00

This worksheet introduces a child to sight word sentences that correlate with sight words she just learned. Pre-primer Dolch sight words reading practice set 4 includes words: here, help, make, yellow, two, play, run, find, three, funny.

Sight Words Reading Practice | List 5Alesia Netuk2022-12-23T16:52:07-05:00

Alesia Netuk2022-12-23T17:16:53-05:00

A short story for kindergarten kids to practice reading skills. The am word family story is designed to reinforce reading skills.

Short Story. Where is Sam?Alesia Netuk2022-12-23T17:16:53-05:00

Alesia Netuk2022-12-23T16:45:46-05:00

In this non-fiction passage, students learn about the penguin. Where does the penguin live? What does it eat? How does it look like?

Penguin Reading PassageAlesia Netuk2022-12-23T16:45:46-05:00

Alesia Netuk2022-12-23T15:59:35-05:00

With this reading worksheet, your child read sight word sentences that correlate with sight words she just learned. 1st Grade Dolch sight words reading practice set 11 includes words: were, them, ask, an, over, just, from, any, how, know.

Sight Words Reading Practice | List 12Alesia Netuk2022-12-23T15:59:35-05:00

Alesia Netuk2022-12-23T16:57:32-05:00

Students read the article and learn how ladybug undergoes a complete metamorphosis. Students explore each stage of ladybug life cycle and look at the pictures.

Ladybug Life Cycle ArticleAlesia Netuk2022-12-23T16:57:32-05:00

Alesia Netuk2022-12-23T17:13:59-05:00

This simple CVC word puzzle is excellent for learning to spell and reading in kindergarten. These puzzles are simple and easy for kids to use. They make great literary centers and fantastic for independent practice.

ED Word Family Reading WorksheetAlesia Netuk2022-12-23T17:13:59-05:00

Alesia Netuk2022-12-23T16:56:49-05:00

This butterfly lie cycle prompt encourages students to use the sequencing stages and arrange them into a writing. What was first, then, and after? What is the final transformation of the butterfly?

Frog Cycle | Reading Article for KidsAlesia Netuk2022-12-23T16:56:49-05:00

Alesia Netuk2022-12-23T15:59:33-05:00

With this reading worksheet, your child read sight word sentences that correlate with sight words she just learned. 1st Grade Dolch sight words reading practice set 10 includes words: of, his, had, him, her, some, as, then, could, when.

Sight Words Reading Practice | List 11Alesia Netuk2022-12-23T15:59:33-05:00

Alesia Netuk2022-12-23T16:55:43-05:00

Use the butterfly life cycle anchor chart in science centers, individual work, small group activities, and even more. You can download it in color or black and white versions.

Butterfly Life Cycle Article with PicturesAlesia Netuk2022-12-23T16:55:43-05:00

Alesia Netuk2022-12-23T16:28:59-05:00

Practice letter A or beginning sound A with cute pictures kids will reveal as they spin the wheel. This letter A spinner would be a great addition to your literacy centre.

Letter A Wheel SpinnerAlesia Netuk2022-12-23T16:28:59-05:00

Alesia Netuk2022-12-23T16:52:13-05:00

With this reading worksheet, your child read sight word sentences associated with sight words she just learned. Primer Dolch sight words reading practice set 7 includes words: like, this, will, yes, went, are, now, no, came, ride.

Sight Words Reading Practice | List 8Alesia Netuk2022-12-23T16:52:13-05:00

Alesia Netuk2022-12-23T16:33:27-05:00

This worksheet features pictures of things that begin with the letter B: barn, book, bed, bat, bee, baby, ball, bird.

Things That Begin With The Letter BAlesia Netuk2022-12-23T16:33:27-05:00

Alesia Netuk2022-12-23T17:05:10-05:00

What does an artist do? Free printable artist reading passage will help students practice their comprehension skills.

Artist – Reading PassageAlesia Netuk2022-12-23T17:05:10-05:00

Alesia Netuk2022-12-23T16:58:24-05:00

Students read the article and learn how shark undergoes a complete metamorphosis. Students explore each stage of shark life cycle and look at the pictures.

Shark Life Cycle ArticleAlesia Netuk2022-12-23T16:58:24-05:00

Alesia Netuk2022-12-23T16:45:04-05:00

In this non-fiction passage, students learn about the alligator. Where does the alligator live? What does it eat? How does it look like?

Alligator Reading PassageAlesia Netuk2022-12-23T16:45:04-05:00

Alesia Netuk2022-12-23T15:59:37-05:00

With this reading worksheet, your child read sight word sentences that correlate with sight words she just learned. 1st Grade Dolch sight words reading set 13 includes words: again, may, stop, fly, round, give, once, open, has, live, thank.

Sight Words Reading Practice | List 14Alesia Netuk2022-12-23T15:59:37-05:00

Alesia Netuk2022-12-23T17:14:31-05:00

This EN Word Family puzzle is excellent for learning to spell and reading in kindergarten. These puzzles are simple and easy for kids to use.

EN Word Family Reading WorksheetAlesia Netuk2022-12-23T17:14:31-05:00

Alesia Netuk2022-12-23T16:46:04-05:00

In this non-fiction passage, students learn about the whale. Where does the whale live? What does it eat? How does it look like?

Whale Reading PassageAlesia Netuk2022-12-23T16:46:04-05:00

Alesia Netuk2022-12-23T16:45:10-05:00

In this non-fiction passage, students learn about the cat. Where does the cat live? What does it eat? How does it look like?

Cat Reading PassageAlesia Netuk2022-12-23T16:45:10-05:00

Search Library

Search for:

By Resource

By Grade

By Subject

By Topic

Page load link

Go to Top

Reading Comprehension Worksheets

Filters

297 filtered results

Clear all filters

Hide done

Favorites

With answer key

297 filtered results

Difficulty Level

  • Easy

  • Normal

  • Extra Challenge


Grade

  • Preschool

  • Kindergarten

  • Grade 1

  • Grade 2

  • Grade 3


Subject


Activity


Standards

Reading Comprehension Worksheets

Our Reading Comprehension Worksheets are perfect for young learners from Pre-K to Grade 3. By guiding students through the study of stories and narratives, our worksheets help to reinforce key comprehension skills, such as identifying main ideas, understanding details, inferring and synthesizing. Our worksheets will provide early readers with the practice they need to develop their comprehension skills, allowing them to read for informative pleasure. Our worksheets emphasize the importance of reading, provide activities that foster key reading skills, and can easily be incorporated into existing lesson plans. Get your little learners on the road to reading success today with our Reading Comprehension Worksheets!


By

Popularity

Interactive

Most Recent

Relevance

Highest Rating

Title

Favorites

With answer key

Hide done

  • Reading Comprehension

Prometheus Story Worksheet

To understand a plot in fiction, kids must understand a story each step of the …

Grade 3
Reading Comprehension

Worksheet

The Lion and The Mouse Sequencing Worksheet

Read through The Lion and the Mouse sequencing worksheet and put your child’s reading comprehension …

Kindergarten
Reading Comprehension

Worksheet

What Do You See? Reading Worksheet

New readers will love using the brilliantly colored and engaging pictures on this downloadable worksheet …

Kindergarten
Reading Comprehension

Worksheet

Services Worksheet

In the community, people work at jobs that serve others and are considered services, as …

Grade 2
Reading Comprehension

Worksheet

Cause And Effect Worksheet

With this worksheet, you can help your kids understand better what cause and effects are.

Grade 3
Reading Comprehension

Worksheet

The Ugly Duckling / El Patito Feo Worksheet

Using the familiar and beloved story of The Ugly Duckling, students will find this adorable …

Grade 2
Reading Comprehension

Worksheet

Dinosaur Facts Worksheet

Improve your child’s reading skills with compelling nonfiction informational text that will keep your child …

Grade 3
Reading Comprehension

Worksheet

How the Moon Became Beautiful Worksheet

Fables are an incredible way for children to make real-world connections, and this Chinese fable …

Grade 1
Reading Comprehension

Worksheet

Skunks Worksheet

When we think of reading, we think of books, but there are so many informational …

Grade 1
Reading Comprehension

Worksheet

Author’s Purpose: Erosion Worksheet

By exposing your students to new texts and passages to read, you help them in …

Grade 2
Reading Comprehension

Worksheet

Point of View Worksheet

Point of View is important to readers who are trying to understand context and story …

Grade 1
Reading Comprehension

Worksheet

Sequence Word Eagle Worksheet

Sequence words help sew together our sentences and paragraphs in a way that allows others …

Grade 3
Reading Comprehension

Worksheet

Rhymes in Poems Worksheet

Poems are beautiful pieces of literature that can be in rhyming lines or unrhymed lines.

Grade 2
Reading Comprehension

Worksheet

White House Worksheet

When you read stories to your students, you encourage them to learn new words, as …

Grade 1
Reading Comprehension

Worksheet

The Crow and the Pitcher Worksheet

All stories have a lesson or message to share, and this is usually known as …

Grade 2
Reading Comprehension

Worksheet

Finding the Details and Connections: Assessment 2 Worksheet

How well does your child love animals? If you have pets at home, they will …

Preschool
Reading Comprehension

Worksheet

“The Princess and the Pea” and “Cinderella” Worksheet

Read the story of Cinderella, and then the story of The Princess and the Pea …

Kindergarten
Reading Comprehension

Worksheet

Descriptive Writing Worksheet: Part 1

Writing is an art, and writers often express their emotions through beautifully constructed sentences and …

Grade 2
Reading Comprehension

Worksheet

More About Dinosaurs Worksheet

Your little archaeologist will have a blast stomping into the past to learn more about …

Grade 3
Reading Comprehension

Worksheet

Robin Hood Folktale Worksheet

Put your child’s reading comprehension to the test with this Robin Hood folktale worksheet! Kids …

Grade 3
Reading Comprehension

Worksheet

Baa Baa Black Sheep Printable

Jumpstart your little reader’s budding comprehension skills with this Baa Baa Black Sheep printable worksheet! …

Kindergarten
Reading Comprehension

Worksheet

Volcano Facts Worksheet

Use this volcano facts worksheet for 3rd grade to increase the skills needed for both …

Grade 3
Reading Comprehension

Worksheet

Jamestown Worksheet

You can help your kids build their vocabulary by reading some simple texts and short …

Grade 3
Reading Comprehension

Worksheet

Sequence: Jack and The Beanstalk Worksheet

Before beginning this worksheet, make sure that your little ones are already familiar with the …

Grade 2
Reading Comprehension

Worksheet

1

2

3

. ..

13

Try Kids Academy for FREE! 

See full Learning Program

Yes, I want to add
E‑Blox
— the brick-compatible construction set for building 3D circuits with lights, sounds, motion, and other.

$19.99

Gift card
Enter coupon code

Note: You will not be billed until your free trial has ended and can cancel at any time. No strings attached.

Great app!

This app is wonderful for my 7 years old son! 🙂 It focuses on basic reading, writing, and math skills. The reward system is great and consistent!


Lilbittygarza

Daughter’s favorite

Still a top favorite for our 7 year old. She loves earning her stars as she learns to trace letters and numbers. Coloring and the sounds are engaging and are on target for her age group and being Pre K.


Surviving5Kids

Great app

Wow! This app is really great. For the first time my kids actually enjoy learning math and reading. The games on Kids Academy are educational and really fun.


Kimberlyxo

Such a great app!

This was a really fun way to get my kids to practice their math. I usually struggle to get them into it and Kids Academy makes it easy.


Fernanndas Stoun

So engaging

We love how we can focus on math with this app. It is engaging and we love how we are able to adjust and tailor the levels according to our son’s knowledge and skill levels!


Momma Anna

Great for kids

Our 7 years old daughter loves reading activities and every off-line game Kids Academy offers. This is a very good app, I highly recommend it!


TonyThan

Reading Worksheet Phonetics Textbook, Checked Flag Icon, angle, rectangle, reading png

Reading Worksheet Phonetics Textbook, Checked checkbox icon, angle, rectangle, reading png

Tags

  • angle,
  • rectangle,
  • reading,
  • symmetry,
  • monochrome,
  • black,
  • teacher,
  • experience,
  • phonetics,
  • area,
  • rest,
  • skill,
  • monochrome photography,
  • line,
  • training,
  • information,
  • checkered flag badge,
  • black and white,
  • worksheet,
  • png,
  • transparent,
  • free download

About this PNG

Image size

759x800px

File size

63.57KB

MIME type

Image/png

Download PNG ( 63. 57KB )

resize PNG

width(px)

height(px)

License

Non-Commercial Use, DMCA Contact Us

  • Formula One racing flags Drapeau xe0 damier Auto racing, checkered flag, flag, racing, symmetry png
    1000x750px
    4.84KB

  • Car Auto racing Racing flags, Checkered Border s, white, flag, rectangle png
    900x1200px
    4.13MB

  • Laurel wreath Olive wreath, checkered flag, leaf, monochrome, royalty Free png
    800x613px
    53.55KB

  • black and white frame, white frame, angle, rectangle, symmetry png
    745x1053px
    4.86KB

  • org/ImageObject»>

    black and white checkered racing flag, Flag of the United States Flag of the United States Drawing, checkered flag, miscellaneous, white, flag png
    567x567px
    55.76KB

  • Electronic signature, signature, miscellaneous, angle, white png
    1280x659px
    55.67KB

  • bubble illustration, Water Drop, drops, angle, white, text png
    2000x2000px
    837.81KB

  • Racing flags Drapeau à damier, Flag, miscellaneous, angle, flag png
    700x700px
    78.44KB

  • two black and white checkered flags, Racing flags, Creative black and white checkered flag, miscellaneous, white, flag png
    800x800px
    79.75KB

  • org/ImageObject»>

    black and gray flag illustration, Racing flags Auto racing, FLAG RACE, angle, white, flag png
    754x377px
    155.3KB

  • Flag, checkered flag, template, angle, flag png
    909x647px
    56.88KB

  • Essay Learning English, english, people, reading, toddler png
    978x827px
    704.38KB

  • Line Symmetry Point Geometric abstraction, Abstract geometric lines, angle, white, rectangle png
    7191x9530px
    4.21MB

  • Arrow Drawing, arrow loops, angle, leaf, text png
    670x702px
    16.4KB

  • Spider web Drawing, cobweb, angle, white, leaf png
    1000x1000px
    76. 51KB

  • Clock face Digital clock Time, clock, template, angle, white png
    600x600px
    14.36KB

  • Star Black and white, star, angle, white, leaf png
    980x994px
    12.66KB

  • two black and white checkered flags, Formula One race track Racing flags Auto racing Dirt track racing track, Black Checkered Flag, miscellaneous, flag, black Hair png
    1280x1024px
    203KB

  • Shield Shape, shield, angle, rectangle, triangle png
    980x980px
    11.4KB

  • flying black birds illustration, Bird flock, Birds, angle, white, animals png
    1024x683px
    68.87KB

  • org/ImageObject»>

    square frame symbol, frame Icon, square frame, frame, angle, white png
    658x658px
    8.95KB

  • square black line illustration, Paper .br Page Teacher Educator, dotted frame, border, angle, white png
    736x736px
    21.4KB

  • Black and white Icon, Gradient lines can adjust brushes, texture, angle, ink png
    950x2000px
    91.35KB

  • Computer Icons Racing flags, checkered flag, angle, flag, text png
    800x800px
    47.65KB

  • Banner Ribbon, doodle, angle, flag, rectangle png
    512x512px
    4.4KB

  • rectangular black frame, Black and white Angle Point Line, Cute borders, white, text, rectangle png
    772x1115px
    14. 43KB

  • WhatsApp iPhone, whatsapp, logo, monochrome, black png
    512x512px
    35.34KB

  • Film strip Cinema, cinema film, white, rectangle, monochrome png
    600x550px
    7.88KB

  • Black and white Square, paper shadow projection angle, texture, angle, white png
    1200x700px
    50.09KB

  • Computer Icons Book, book, angle, rectangle, reading png
    540x540px
    6.09KB

  • Water Drop Icon, Summer rain, water drop, texture, angle, white png
    650x1224px
    586.22KB

  • black WhatsApp logo, WhatsApp Computer Icons, whatsapp, logo, monochrome, black png
    512x512px
    24. 25KB

  • White Black Pattern, shadow angle, texture, angle, rectangle png
    1370x634px
    15.89KB

  • black and white illustration, Border Frames and Frames, black frame, angle, white, leaf png
    673x713px
    19KB

  • Black and white Pattern, Geometric abstract perspective blocks, blue mirror illustration, texture, angle, white png
    650x835px
    95.79KB

  • Speech balloon Comic book Template, BICBLE, miscellaneous, angle, text png
    1920x1372px
    103.86KB

  • black polka dots, Polka dot Pattern, Black polka dots, angle, white, rectangle png
    3600x3600px
    228. 94KB

  • four black arrows, Arrow, Arrow Sketch, angle, white, face png
    800x615px
    9.56KB

  • white black pattern, frame silhouette frame cartoon, white paper square, white picture frame, texture, angle, white png
    1122x1212px
    38.3KB

  • Black and white Fog, Grayscale, texture, angle, white png
    1279x737px
    702.29KB

  • White Pattern, paper shadow projection angle, angle, rectangle, monochrome png
    1200x700px
    50.1KB

  • Spider-Man Drawing, spider web, web illustration, angle, leaf, heroes png
    2400x2400px
    597.87KB

  • org/ImageObject»>

    White flag Wait, White flag, raised the white flag, miscellaneous, angle, white png
    2592x2948px
    1.39MB

  • Monochrome Drawing, white line, texture, angle, white png
    2000x1379px
    503.92KB

  • Racing flags, Flag, miscellaneous, flag, racing png
    600x616px
    50.03KB

  • black frame, Borders and Frames, Simple frame, border, white, mammal png
    1143x1600px
    83.76KB

  • checkered pattern illustration, Flag Euclidean, Black and white checkered flag, angle, white, flag png
    2896x7145px
    501.33KB

  • black and white checkered illustration, Formula One racing flags Sport White flag, Black and white checkered flag, miscellaneous, flag, rectangle png
    500x500px
    48. 46KB

  • black stripes, Black and white Monochrome, stripe, angle, text, rectangle png
    8000x4500px
    146.72KB

  • Smoke, smoke smoke, texture, white, smoke png
    1836x1760px
    585.79KB

Python openpyxl module, working with XLSX files

Excel spreadsheets are an intuitive and convenient way to manipulate large datasets without any technical background. Therefore, this is one of the formats that, at some point in time, you will have to deal with. Often there will be tasks to extract some data from a database or log file into an Excel spreadsheet, or vice versa, convert an Excel spreadsheet into some more convenient program form, there are a lot of examples of this.

openpyxl module is a Python library for reading/writing Office Open XML formats (Excel 2010 files) with extensions xlsx / xlsm / xltx / xltm .

Installing the

openpyxl module in the virtual environment.

The openpyxl module is hosted on PyPI, so installation is relatively easy.

 # create a virtual environment if not
$ python3 -m venv .venv --prompt VirtualEnv
# activate the virtual environment
$ source .venv/bin/activate
# install the openpyxl module
(VirtualEnv):~$ python3 -m pip install -U openpyxl
 

Basics of working with Microsoft Excel files in Python.

  • Create an Excel workbook.
    • New Excel worksheet.
    • Copy an Excel worksheet.
    • Deleting an Excel worksheet.
  • Access to a spreadsheet cell and its value.
  • Access to a range of cells in a spreadsheet sheet.
  • Get only sheet cell values.
  • Adding data to cells in a list.
  • Save the created workbook to an Excel file.
    • Save book data as a stream.
  • Loading an XLSX document from a file.

Create an Excel workbook.

To get started with the openpyxl module , there is no need to create a spreadsheet file in the file system. You just need to import the class Workbook and instantiate it. A workbook is always created with at least one worksheet, it can be retrieved using property Workbook.active :

 >>> from openpyxl import Workbook
# create a book
>>> wb = Workbook()
# make the only sheet active
>>> ws=wb.active
 
A new Excel worksheet.

New worksheets can be created using the Workbook.create_sheet() method :

 # insert worksheet at the end (default)
>>> ws1 = wb.create_sheet("Mysheet")
# insert worksheet at first position
>>> ws2 = wb.create_sheet("Mysheet", 0)
# insert the worksheet at penultimate position
>>> ws3 = wb.create_sheet("Mysheet", -1)
 

Sheets are automatically named when they are created. They are numbered sequentially (Sheet, Sheet1, Sheet2, . ..). These names can be changed at any time using the property Worksheet.title :

 >>> ws.title = "NewPage"
 

The background color of the tab with this title is white by default. You can change this color by specifying color code RRGGBB for sheet attribute Worksheet.sheet_properties.tabColor :

 >>> ws.sheet_properties.tabColor = "1072BA"
 

The worksheet can be retrieved by using its name as the instance key of the created Excel workbook:

 >>> ws3 = wb["NewPage"]
 

To view the names of all worksheets in a workbook, use the attribute Workbook.sheetname . You can also iterate through the worksheets of an Excel workbook.

 >>> wb.sheetnames
# ['Mysheet1', 'NewPage', 'Mysheet2', 'Mysheet']
>>> for sheet in wb:
...print(sheet.title)
#mysheet1
#NewPage
#mysheet2
#mysheet
 
Copying an Excel worksheet.

To create a copy of worksheets in one workbook, you must use the method Workbook. copy_worksheet() :

 >>> source_page = wb.active
>>> target_page = wb.copy_worksheet(source_page)
 

Note . Only cells (values, styles, hyperlinks, and comments) and certain worksheet attributes (sizes, format, and properties) are copied. All other book/sheet attributes are not copied, such as images or charts.

Ability to copy worksheets between workbooks is supported. You cannot copy a worksheet if the workbook is open in read-only or write-only mode.

Deleting an Excel worksheet.

Obviously, there is a need to delete a spreadsheet sheet that already exists. Module openpyxl makes it possible to delete a sheet by its name. Therefore, you first need to find out which sheets are present in the book, and then delete the unnecessary one. Method 9 is responsible for deleting the sheets of the book0183 Workbook.remove() .

Look at the example:

 # find out if the sheet names are present in the book
>>> name_list = wb. sheetnames
>>> name_list
# ['Mysheet1', 'NewPage', 'Mysheet2', 'Mysheet', 'Mysheet1 Copy']
# let's say we don't need the first and last
# delete the first sheet by its name with a check
# the existence of such a name in the book
>>> if 'Mysheet1' in wb.sheetnames:
        # If a sheet named `Mysheet1` is present
        # in the list of sheets of the book instance, then delete
...wb.remove(wb['Mysheet1'])
...
>>> wb.sheetnames
# ['NewPage', 'Mysheet2', 'Mysheet', 'Mysheet1 Copy']
# delete the last sheet through the operator
# `del`, extract the sheet name by index
# of the resulting list `name_list`
>>> del wb[name_list[-1]]
>>> wb.sheetnames
# ['NewPage', 'Mysheet2', 'Mysheet']
 

Access to a cell and its value.

Once the worksheet is selected, you can start modifying the contents of the cells. Cells can be accessed directly as worksheet keys, for example ws['A4'] . This will return the cell at A4 or create it if it doesn’t already exist. Values ​​can be assigned directly:

 >>> ws['A4'] = 5
>>>ws['A4']
# 
>>> ws['A4'].value
# 5
>>> ws['A4'].column
# 1
>>> ws['A4'].row
# 4
 

If the cell object is assigned to a variable, then this variable can also be assigned a value:

 >>> c = ws['A4']
>>> c.value = c.value * 2
>>> c.value
# 10
 

There is also a method Worksheet.cell() . It provides access to cells by directly specifying row and column values:

 >>> d = ws.cell(row=4, column=2, value=10)
>>> d
# 
>>> d.value = 3.14
>>> print(d. value)
# 3.14
 

Note . When you create a worksheet in memory, it does not contain cells. Cells are created the first time they are accessed.

Important ! Because of this behavior, simply iterating over cells in a loop will create objects of those cells in memory even if no value is assigned to them.

Don’t run this example, take my word for it:

 # will create 100x100=10000 empty objects in memory
# cells, just using up RAM. 
>>> for x in range(1,101):
... for y in range(1,101):
...ws.cell(row=x, column=y)
 

Access to a range of cells in a spreadsheet sheet.

A range with cells in the active sheet of a spreadsheet can be obtained using simple slicing. These slices will return iterators of cell objects.

 >>> cell_range = ws['A1':'C2']
>>> cell_range
# ((, , ),
# (, , ))
 

Similarly, you can get the ranges of existing rows or columns on a sheet:

 # All available cells in column `C`
>>> colC = ws['C']
# All available cells in column range `C:D`
>>> col_range = ws['C:D']
# All available cells in row 10
>>> row10 = ws[10]
# All available cells in row range `5:10`
>>> row_range = ws[5:10]
 

You can also use the Worksheet.iter_rows() method:

 >>> for row in ws.iter_rows(min_row=1, max_col=3, max_row=2):
... for cell in row:
. ..print(cell)
# 
# 
# 
# 
# 
# 
 

Similarly, the Worksheet.iter_cols() method will return columns:
… for cell in col:
…print(cell)
#
#
#
#
#
#

Note . For performance reasons, the Worksheet.iter_cols() method is not available in read-only mode.

If you want to loop through all the rows or columns of a file, you can use the property Worksheet.rows :

 >>> ws = wb.active
>>> ws['C9'] = 'hello world'
>>> tuple(ws.rows)
# ((, , ),
# (, , ),
# (, , ),
# ...
# (, , ),
# (, , ),
# ( A9>, , ))
 

or property Worksheet.columns :

 >>> tuple(ws.columns)
# ((,
# ,
# ...
# ,
# ),
# (,
# ,
# ...
# ,
# ))
 

Note . For performance reasons, property Worksheet.columns is not available in read-only mode.

Get only cell values ​​of the active sheet.

If you just need the values ​​from the worksheet, you can use the active worksheet property Worksheet.values ​​ . This property loops through all the rows in the sheet, but only returns cell values:

 for row in ws.values:
   for value in row:
     print(value)
 

To return only the value of a cell, the Worksheet.iter_rows() and Worksheet.iter_cols() methods above can take an argument of values_only :

 >>> for row in ws. iter_rows(min_row=1, max_col=3, max_row=2, values_only=True):
...print(row)
# (None, None, None)
# (None, None, None)
 

Adding data to worksheet cells as a list.

The openpyxl module makes it super easy and convenient to add data to the end of a spreadsheet sheet. This convenience is provided by the worksheet object method Worksheet.append(iterable) , where the argument iterable is any iterable object (list, tuple, etc.). This behavior allows, without crutches, to transfer data from other sources into a spreadsheet, such as CSV files, database tables, data frames from Pandas, etc.

Method Worksheet.append() adds a group of values ​​to the last row that does not contain data.

  • If it is a list: all values ​​are added in order, starting from the first column.
  • If this is a dictionary: values ​​are assigned to columns designated by keys (numbers or letters).

Use Cases0005 append dictionary:

  • option 1: . append({'A' : 'cell A1', 'C' : 'cell C1'}) , using column letters as keys.
  • option 2: .append({1 : 'cell A1', 3 : 'cell C1'}) , using column numbers as keys.

Example of adding data from the list:

 # existing workbook sheets
>>> wb.sheetnames
# ['NewPage', 'Mysheet2', 'Mysheet']
# add data to a sheet named `Mysheet2`
>>> ws = wb["Mysheet2"]
# create arbitrary data using
# nested list generator
>>> data = [[row*col for col in range(1, 10)] for row in range(1, 31)]
>>> data
#[
# [1, 2, 3, 4, 5, 6, 7, 8, 9],
# [2, 4, 6, 8, 10, 12, 14, 16, 18],
# ...
# ...
# [30, 60, 90, 120, 150, 180, 210, 240, 270]
#]
# add data to the selected sheet
>>> for row in data:
... ws.append(row)
...
 

That's it, data added... Simple? Not easy, super easy!

Save the created workbook to an Excel file.

The easiest and safest way to save a workbook is to use the Workbook.save() method of the Workbook object :

 >>> wb = Workbook()
>>> wb. save('test.xlsx')
 

Attention . This operation will overwrite the existing file without warning!!!

After saving, you can open the resulting file in Excel and view the data by selecting the sheet named NewPage .

Note . The filename extension does not have to be xlsx or xlsm , although you may have problems opening it directly in another application. Since OOXML files are mostly ZIP files, you can also open them with your favorite ZIP archive manager.

Save book data as a stream.

If you need to save a file to a stream, for example when using a web application such as Flask or Django, you can simply provide tempfile.NamedTemporaryFile()
from openpyxl import Workbook
wb = workbook()
with NamedTemporaryFile() as tmp:
wb.save(tmp.name)
tmp.seek(0)
stream = tmp.read()

Attribute can be specified template=True to save the workbook as a template:

 >>> from openpyxl import load_workbook
>>> wb = load_workbook('test. xlsx')
>>> wb.template = True
>>> wb.save('test_template.xltx')
 

Note . Attribute wb.template defaults to False , which means save as a document.

Attention . The following will fail:

 >>> from openpyxl import load_workbook
>>> wb = load_workbook('test.xlsx')
# Must be saved with *.xlsx extension
>>> wb.save('new_test.xlsm') # MS Excel cannot open document
# You need to specify the attribute `keep_vba=True`
>>> wb = load_workbook('test.xlsm')
>>> wb.save('new_test.xlsm')
>>> wb = load_workbook('test.xltm', keep_vba=True)
# If you need a document template, you must specify the *.xltm extension.
>>> wb.save('new_test.xlsm') # MS Excel cannot open document
 

Loading an XLSX document from a file.

To open an existing Excel workbook, you must use the openpyxl.load_workbook() function :

 >>> from openpyxl import load_workbook
>>> wb2 = load_workbook('test.xlsx')
>>> print(wb2.

By alexxlab

Similar Posts