{"id":719,"date":"2022-02-24T13:47:08","date_gmt":"2022-02-24T18:47:08","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=719"},"modified":"2024-02-06T11:32:48","modified_gmt":"2024-02-06T16:32:48","slug":"python-code-to-work-with-excel-files","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/python-code-to-work-with-excel-files\/","title":{"rendered":"Python code to work with Excel files"},"content":{"rendered":"\n<p>Note: The instructions are for python3.x on Ubuntu<\/p>\n\n\n\n<p>There are several different libraries you can use to easily work with Excel. I will be covering&nbsp;<a target=\"_blank\" href=\"https:\/\/pypi.python.org\/pypi\/openpyxl\" rel=\"noreferrer noopener\">openpyxl<\/a>. Other options include xlsxwriter, xlrd, xlwt, and xltuils.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Installing openpyxl<\/h3>\n\n\n\n<p>To install openpyxl, make sure you have pip3 installed:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>which pip3<\/code><\/pre>\n\n\n\n<p>If pip3 is not installed, install it first:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get install python3-pip<\/code><\/pre>\n\n\n\n<p>Once pip3 is installed:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo pip3 install openpyxl<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Reading from Excel<\/h3>\n\n\n\n<p>See the following code<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from openpyxl import load_workbook\nwb = load_workbook(filename = 'Tab-9.xlsx')\nsheet_ranges = wb&#91;'Tb 9']\nprint(sheet_ranges&#91;'C5'].value)<\/code><\/pre>\n\n\n\n<p>This code opens the worksheet &#8220;Tb 9&#8221; in the file &#8220;Tab-9.xlsx&#8221; and prints the value of the cell C5.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Note: The instructions are for python3.x on Ubuntu There are several different libraries you can use to easily work with Excel. I will be covering&nbsp;openpyxl. Other options include xlsxwriter, xlrd, xlwt, and xltuils. Installing openpyxl To install openpyxl, make sure you have pip3 installed: If pip3 is not installed, install it first: Once pip3 is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[207,203],"tags":[209,56,137],"class_list":["post-719","post","type-post","status-publish","format-standard","hentry","category-excel","category-python","tag-file-management","tag-microsoft-excel","tag-python"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/719","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/comments?post=719"}],"version-history":[{"count":1,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/719\/revisions"}],"predecessor-version":[{"id":720,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/719\/revisions\/720"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=719"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=719"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}