MoonPoint Support Logo

 


Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals



Advanced Search
July
Sun Mon Tue Wed Thu Fri Sat
22 23 24 25 26 27 28
29 30 31        
2018
Months
JulAug Sep
Oct Nov Dec


Fri, May 18, 2018 10:56 pm

Installing new packages for WinPython

To install a new package/module under WinPython, double-click on WinPython Command Prompt in the directory where you installed WinPython to open a command prompt window.

WinPython installation directory

At the command prompt window type pip install pkgname where pkgname is the name of the package you wish to install. If the package is already present, you will see the message "requirement already satisfied."

[ More Info ]

[/languages/python] permanent link

Sun, May 13, 2018 9:55 pm

WinPython - Python for Microsoft Windows

If you wish to run Python on a Microsoft Windows system, you can use WinPython. The first window you will see when run run the downloaded installation file is one for the license agreement, which notes "WinPython components are distributed as they were received from their copyright holder, under their own copyright and/or license, and without any linking with each other." WinPython itself uses the MIT license. Once you accede to the license, you will be prompted for a destination folder. By default that will be a WinPython directory created beneath the directory where you're running the downloaded file from, but you can change the location. When the installation has been completed, a window will appear where you can click on a Finish button to exit from the installation program.

[ More Info ]

[/languages/python] permanent link

Mon, Feb 19, 2018 11:24 pm

xlrd and hidden worksheets

I use the xlrd module in Python scripts to extract data from Excel workbooks. You can use the Python xlrd module to list the worksheets in a workbook and you can use the xlrd.sheet "visibility" value to determine whether a sheet is hidden and, if it is hidden, whether a user can unhide the sheet. The value should be either 0, 1, or 2 with the numbers having the following meaning:

Visibility of the sheet:

0 = visible
1 = hidden (can be unhidden by user -- Format -> Sheet -> Unhide)
2 = "very hidden" (can be unhidden only by VBA macro)

[ More Info ]

[/languages/python/excel] permanent link

Wed, Feb 14, 2018 9:31 pm

Extracting embedded Microsoft Office files from an Excel spreadsheet

I work with Excel workbooks on my MacBook Pro laptop that have embedded PowerPoint slides on some worksheets. The workbooks, which I need to review, are created by others. When I review them, I extract information from the Excel workbooks to an SQLite database with Python and also have begun extracting information embedded by Object Linking and Embedding (OLE) into files as noted in Extracting the contents of a directory in a zipfile using Python. Some of the embedded files are PowerPoint files, but when they are extracted they have a .bin extension, which I can't open in PowerPoint without changing the filename extension from .bin to .ppt. To automate the renaming process, I created a Python script, extract_embedded.py that will extract the embedded information to files in an "embedded" directory beneath the current working directory and then rename any .bin files that are PowerPoint files to have a .ppt extension. The script is shown below.

[ More Info ]

[/languages/python/excel] permanent link

Sat, Feb 10, 2018 10:55 pm

Extracting the contents of a directory in a zipfile using Python

A Microsoft Excel file with an .xlsx or .xlsm filename extension is an Office Open XML (OpenXML) zipped, XML-based file. The OpenXML format was developed by Microsoft for spreadsheets, charts, presentations and word processing documents. If you change the file extension to .zip by renaming the file, you can extract the contents of the zip file as you would with any other zip file - see Zipping and unzipping Excel xlsx files. Excel workbooks can contain other documents embedded within them using Object Linking and Embedding (OLE) technology - see Using olefile to obtain metadata from an OLE CDF V2 file. I often need to extract an embedded PowerPoint slide or Visio diagram from Excel .xlsm files, so I've been renaming the files to zip files and unzipping them as I would other zip files, but, since I want to automate the process and extract just specific embedded files for further processing within a Python script, I created the script below to extract the embedded files, which are contained within a xl/embeddings subdirectory within the .xlsm zip files. The script uses the zipfile module to deal with the zip files. Python's OS module is used to check for the existence of the destination directory and create it, if it doesn't yet exist.

#!/usr/bin/python

import os, zipfile

dirToExtract = "xl/embeddings/"
destinationDir = "embedded"
infile = raw_input("Enter zipfile: ")
archive = zipfile.ZipFile(infile)

if not os.path.exists(destinationDir):
    os.makedirs(destinationDir)

for file in archive.namelist():
    if file.startswith(dirToExtract):
        archive.extract(file, destinationDir)

The script prompts for the file to be unzipped and then extracts just the "xl/embeddings" folder and the files contained within it to a new directory it will create within the current working directory. The new directory will be named "embedded". After extracting the contents of the "xl/embeddings" directory to the newly created "embedded" folder, I had the the files below in the case of the particular .xlsm file I used for this example.

[ More Info ]

[/languages/python/excel] permanent link

Fri, Feb 09, 2018 10:04 pm

Using the Python xlrd module to list the worksheets in a workbook

To view the list of sheets in an Excel spreadsheet, I can use the xlrd module within the Python script below to obtain the list of worksheets within the workbook.

#!/usr/bin/python

import xlrd as xl

file_name = raw_input("File: ")
workbook = xl.open_workbook(file_name)
print workbook.sheet_names()

If I use the script to display the list of worksheets in a workbook named report.xlsx that has three sheets named alpha, beta, and gamma, I would see the following output:

$ ./sheetlist.py
File: report.xlsx
[u'alpha', u'beta', u'gamma']
$

[ More Info ]

[/languages/python/excel] permanent link

Sat, Feb 03, 2018 10:34 pm

Using PyInstaller to create an executable file from a Python script

If you wish to convert Python scripts to executable files that you can run on systems where Python or all of the needed dependencies for the script are not installed, one program that is available for Linux, Mac OS X, Solaris, AIX, or Microsoft Windows systems is PyInstaller. If you have the pip package manager installed, you can install PyInstaller by running the command below from the root account.

pip install pyinstaller

To then create an executable file that will run on other sytems with that same operating system, e.g., you can create an executable file on one Linux system that will run on another Linux system or create an .exe file on a Microsoft Windows system that can be ported to another Windos system, you can issue the command pyinstaller yourprogram.py.

[ More Info ]

[/languages/python] permanent link

Fri, Feb 02, 2018 11:16 pm

Extracting information from a .msg file with Python

I received a .msg file attachment to an email message I received with Microsoft Outlook for Mac, which is part of Microsoft Office 2016 on my MacBook Pro laptop. When I double-clicked on the attachment in Outlook to view the contents of the file, I saw "There is no application specified to open the document Re_ Netbond.msg."

Msg - Open 
Attachment

And also a window giving me an option to "Search App Store" with the message "Search the App Store for an application that can open this document, or choose an existing application on your computer."

[ More Info ]

[/languages/python] permanent link

Wed, Jan 31, 2018 11:48 pm

Using olefile to obtain metadata from an OLE CDF V2 file

Microsoft's Object Linking and Embedding (OLE) technology allows embedding and linking to documents and other objects. OLE allows the addition of different kinds of data to a document from different applications, such as a text editor and an image editor. This creates a Compound File Binary Format (CFBF), aka a Compound File, Compound Document format, or Composite Document File V2 (CDF V2) document.

While using my MacBook Pro laptop, which is currently running the OS X El Capitan (10.11.6) operating system, I often need to extract embedded documents from an Excel .xlsm file. I do that by renaming the file to have a .zip rather than a .xlsm file extension. I can then extract the files contained within the .zip file just as I would any zip file. Within the directory structure created by unzipping the zip file there is an xl/embeddings subdirectory with .bin files within it.

$ ls xl/embeddings
Microsoft_Visio_Drawing1.vsdx	oleObject2.bin
Microsoft_Visio_Drawing2.vsdx	oleObject3.bin
oleObject1.bin
$

[ More Info ]

[/languages/python] permanent link

Tue, Jan 30, 2018 11:22 pm

Using Python to extract data from a spreadsheet and put it in a database

I need to review spreadsheets related to work requests on a daily basis. The Excel workbooks have multiple worksheets within them. I have been manually copying data from specific cells in one of the worksheets and pasting it into a SQLite database. I use DB Browser for SQLite to paste the information into the database. I wanted to automate the process of extracting the data from the .xlsm or .xlsx workbook files and inserting it into the SQLite database using a Python script. So I initially created a script that I could run from a Teminal window on my MacBook Pro laptop, as noted in Extracting data from cells in an Excel workbook with Python, that would just print the information to the Terminal window's command-line interface. I had another script to import data from a text file into an SQLite database with Python, so I combined code from that script with the one to read data from the spreadsheets to add the data to a table in the database.

[ More Info ]

[/languages/python/excel] permanent link

Once You Know, You Newegg AliExpress by Alibaba.com

Shop Amazon Local - Subscribe to Deals in Your Neighborhood

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo