VBA 巨集取出 Excel 中的圖檔

出至:VBA – Extract Pictures from Excel

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.

Sub GetFirstPicture()

Dim sCurrPath As String
Dim aWorkSheet As Excel.Worksheet
Dim aShape As Excel.Shape
Dim aShapeChart As Excel.Shape
Dim aPicture As Variant
Dim aChart As Excel.Chart
Dim sCurrentSheet As String

Dim aImage As Variant
Dim iIndex As Integer
Dim iShapeCount As Integer

Dim MyChart As String, MyPicture As String
Dim PicWidth As Long, PicHeight As Long
Dim sChartJpg As String
Dim sChartGif As String
Dim sChartBmp As String

‘On Error GoTo ErrHandler
On Error Resume Next

Application.ScreenUpdating = False

sCurrPath = “D:\VB\MyTrials\ChartExpFromXL"
sChartJpg = “D:\VB\MyTrials\ChartExpFromXL.jpg"
sChartGif = “D:\VB\MyTrials\ChartExpFromXL.gif"
sChartBmp = “D:\VB\MyTrials\ChartExpFromXL.bmp"

Set aWorkSheet = ActiveWorkbook.ActiveSheet
sCurrentSheet = aWorkSheet.Name

‘MsgBox CStr(msoTrue) + " value for MsoTrue"
‘ MsoTrue equals to -1
MsgBox “Shapes count " + CStr(aWorkSheet.Shapes.Count)
For iIndex = 1 To aWorkSheet.Shapes.Count

Set aShape = aWorkSheet.Shapes(iIndex)
MyPicture = aShape.Name
MsgBox aShape.Name + " Name, " + Str(aShape.Type)
‘Picture 1 Name, 13
If Left(aShape.Name, 7) = “Picture" Then
With aShape
PicHeight = .Height
PicWidth = .Width
End With
‘Set aChart = aWorkSheet.ChartObjects(1)
Set aChart = ActiveWorkbook.Charts.Add
ActiveWorkbook.ActiveChart.Location Where:=xlLocationAsObject, Name:=sCurrentSheet
iShapeCount = aWorkSheet.Shapes.Count
Set aShapeChart = aWorkSheet.Shapes(iShapeCount)
MyChart = aShapeChart.Name ‘"Chart " & Str(aWorkSheet.Shapes.Count)

aShapeChart.Width = PicWidth
aShapeChart.Height = PicHeight

With aWorkSheet

With ActiveChart ‘aChart
End With

.ChartObjects(1).Chart.Export Filename:=sChartJpg, FilterName:="jpg", Interactive:=True
.ChartObjects(1).Chart.Export Filename:=sChartGif
.ChartObjects(1).Chart.Export Filename:=sCurrPath & “.png"
‘Not working .ChartObjects(1).Chart.Export Filename:=sChartBmp, FilterName:="bmp"
End With

Application.ScreenUpdating = True

MsgBox “Completed."
Exit Sub

End If


MsgBox “Completed."
Exit Sub

MsgBox “Error # " & CStr(Err.Number) & " " & Err.Description & " " & Err.Source
Err.Clear ‘ Clear the error.
End Sub

Extract Images from an Excel Document


First, use unoconv to convert the .xls to .pdf:


On Ubuntu 10.10 command line:

sudo apt-get install unoconv
unoconv -f pdf file.xls
Then extract the images from the pdf using pdfimages (which seems to come bundled with Ubuntu):


Back on the command line:

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:

import subprocess

I would love to hear a simpler solution if somebody has one.

If a excel file is a compressed file.(xlsx)

$ unzip file.xlsx

in xl/media/ are all pictures

使用 FileReader 讓網頁圖片上傳前預覽

From: http://stackoverflow.com/questions/4459379/preview-an-image-before-it-is-uploaded

Please take a look at the sample JS code below:

JS code with jQuery:

<script type="text/javascript">
        function readURL(input) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();

                reader.onload = function (e) {
                    $('#blah').attr('src', e.target.result);


and the associated HTML:

    <form id="form1" runat="server">
        <input type='file' onchange="readURL(this);" />
        <img id="blah" src="#" alt="your image" />



Linux 光碟映像檔 轉檔工具

mdf2iso converts an Alcohol 120% .mdf image to other CD image formats. It is able to write out plain .iso, .cue &
.bin and .toc & .dat. If you do not specifiy –cue or –toc, an .iso file gets generated. If you do not specifiy a
destination image name, BASENAME.ext is automatically used.

iat (Iso9660 Analyzer Tool) is a tool for detecting the structure of many types of CD-ROM image file formats,
such as BIN, MDF, PDI, CDI, NRG, and B5I, and converting them into ISO-9660.

If output file name is not defined, then STDOUT will be used instead.