Last month, I have written Excel Automation Using VBScript. Today this post is to extract Pictures from Excel. Generally We can not use Export method for pictures. But we can use for Excel charts. I tried to extract our SVG chart image by macro and I succeed on it. I got help from Export pictures from Excel Below I’ve given the VBA Macro code.

pdfimages file.pdf fileimage
And done! All of the images in the .xls are now in separate files in the directory. This could be done very easily on most Linux systems using your language of choice. In python, for example:

Python Excel Mini Cookbook
Posted on October 5, 2009
To get you started, I’ve illustrated a number of common tasks you can do with Python and Excel. Each program below is a self contained example, just copy it, paste it and run it. A few things to note:

These examples were tested in Excel 2007, they should work fine in earlier versions as well after changing the extension of the file within the wb.SaveAs() statement from .xlsx to .xls
If you’re new to this, I recommend typing these examples by hand into IDLE, IPython or the Python interpreter, then watching the effect in Excel as you enter the commands. To make Excel visible add the line excel.Visible = True after the excel =win32.gencache.EnsureDispatch(‘Excel.Application’) line in the script
These are simple examples with no error checking. Make sure the output files doesn’t exist before running the script. If the script crashes, it may leave a copy of Excel running in the background. Open the Windows Task Manager and kill the background Excel process to recover.
These examples contain no optimization. You typically wouldn’t use a for loop to iterate through data in individual cells, it’s provided here for illustration only.
Open Excel, Add a Workbook

The following script simply invokes Excel, adds a workbook and saves the empty workbook.

This script opens an existing workbook and displays it (note the statement excel.Visible =True). The file workbook1.xlsx must already exist in your “My Documents” directory. You can also open spreadsheet files by specifying the full path to the file as shown below. Using r’in the statement r’C:\myfiles\excel\workbook2.xlsx’ automatically escapes the backslash characters and makes the file name a bit more concise.

This script illustrates different techniques for addressing cells by using the Cells() and Range()operators. Individual cells can be addressed using Cells(row,column), where row is the row number, column is the column number, both start from 1. Groups of cells can be addressed using Range(), where the argument in the parenthesis can be a single cell denoted by its textual name (eg “A2″), a group noted by a textual name with a colon (eg “A3:B4″) or a group denoted with two Cells() identifiers (eg ws.Cells(1,1),ws.Cells(2,2)). The Offsetmethod provides a way to address a cell based on a reference to another cell.

This script creates two columns of data, one narrow and one wide, then formats the column width with the ColumnWidth property. You can also use the Columns.AutoFit() function to autofit all columns in the spreadsheet.

#
# Set column widths
#import win32com.client as win32excel = win32.gencache.EnsureDispatch(‘Excel.Application’)wb = excel.Workbooks.Add()ws = wb.Worksheets(“Sheet1″)ws.Range(“A1:A10″).Value = “A"ws.Range(“B1:B10″).Value = “This is a very long line of text"ws.Columns(1).ColumnWidth = 1ws.Range(“B:B").ColumnWidth = 27# Alternately, you can autofit all columns in the worksheet# ws.Columns.AutoFit()wb.SaveAs(‘column_widths.xlsx’)excel.Application.Quit()Copying Data from Worksheet to Worksheet

This script uses the FillAcrossSheets() method to copy data from one location to all other worksheets in the workbook. Specifically, the data in the range A1:J10 is copied from Sheet1 to sheets Sheet2 and Sheet3.

#
# Copy data and formatting from a range of one worksheet
# to all other worksheets in a workbook
#import win32com.client as win32excel = win32.gencache.EnsureDispatch(‘Excel.Application’)wb = excel.Workbooks.Add()ws = wb.Worksheets(“Sheet1″)ws.Range(“A1:J10″).Formula = “=row()*column()"wb.Worksheets.FillAcrossSheets(wb.Worksheets(“Sheet1″).Range(“A1:J10″))wb.SaveAs(‘copy_worksheet_to_worksheet.xlsx’)excel.Application.Quit()Format Worksheet Cells

This script creates two columns of data, then formats the font type and font size used in the worksheet. Five different fonts and sizes are used, the numbers are formatted using a monetary format.