Copy Image from Excel and Save it using python












1















I am trying to copy an image from an excel named Inputs_v3 and sheet named Inputs and save. The code is as follows`



import win32com.client as win32       
from PIL import ImageGrab
from xlrd import open_workbook
import os

excel = win32.gencache.EnsureDispatch("Excel.Application")
wb = open_workbook('Inputs_v3.xlsm')
r = wb.sheet_by_name('Inputs')
r.CopyPicture()

im = ImageGrab.grabclipboard()
im.save('somefile.png','PNG')


` The error is as follows



'Attribute error: 'Sheet' object has no attribute 'CopyPicture''


Please suggest where I am doing wrong.Thanks in advance










share|improve this question























  • You're mixing up win32com calls with the xlrd package, which have nothing to do with each other. You've set excel to be a reference to the Excel app but then you don't do anything with it. I'm not fully familiar with either xlrd or the Excel COM model but it looks as if CopyPicture is a method you need to call on the Excel worksheet object, not the xlrd sheet_by_name object. If you can get the picture using xlrd do that and don't use COM, otherwise use COM and you don't need xlrd.

    – nekomatic
    May 12 '16 at 7:54











  • Hi..I have tried to open the work book using win32.com by excel = win32.gencache.EnsureDispatch("Excel.Application") wb = excel.Workbooks.Open("Inputs_v3.xlsm")...but it is showing that we couldn't find the file

    – Goutham Pathuri
    May 12 '16 at 9:29













  • Sounds like it couldn't find the file then ;-) Try giving it a full path name.

    – nekomatic
    May 12 '16 at 9:39
















1















I am trying to copy an image from an excel named Inputs_v3 and sheet named Inputs and save. The code is as follows`



import win32com.client as win32       
from PIL import ImageGrab
from xlrd import open_workbook
import os

excel = win32.gencache.EnsureDispatch("Excel.Application")
wb = open_workbook('Inputs_v3.xlsm')
r = wb.sheet_by_name('Inputs')
r.CopyPicture()

im = ImageGrab.grabclipboard()
im.save('somefile.png','PNG')


` The error is as follows



'Attribute error: 'Sheet' object has no attribute 'CopyPicture''


Please suggest where I am doing wrong.Thanks in advance










share|improve this question























  • You're mixing up win32com calls with the xlrd package, which have nothing to do with each other. You've set excel to be a reference to the Excel app but then you don't do anything with it. I'm not fully familiar with either xlrd or the Excel COM model but it looks as if CopyPicture is a method you need to call on the Excel worksheet object, not the xlrd sheet_by_name object. If you can get the picture using xlrd do that and don't use COM, otherwise use COM and you don't need xlrd.

    – nekomatic
    May 12 '16 at 7:54











  • Hi..I have tried to open the work book using win32.com by excel = win32.gencache.EnsureDispatch("Excel.Application") wb = excel.Workbooks.Open("Inputs_v3.xlsm")...but it is showing that we couldn't find the file

    – Goutham Pathuri
    May 12 '16 at 9:29













  • Sounds like it couldn't find the file then ;-) Try giving it a full path name.

    – nekomatic
    May 12 '16 at 9:39














1












1








1


2






I am trying to copy an image from an excel named Inputs_v3 and sheet named Inputs and save. The code is as follows`



import win32com.client as win32       
from PIL import ImageGrab
from xlrd import open_workbook
import os

excel = win32.gencache.EnsureDispatch("Excel.Application")
wb = open_workbook('Inputs_v3.xlsm')
r = wb.sheet_by_name('Inputs')
r.CopyPicture()

im = ImageGrab.grabclipboard()
im.save('somefile.png','PNG')


` The error is as follows



'Attribute error: 'Sheet' object has no attribute 'CopyPicture''


Please suggest where I am doing wrong.Thanks in advance










share|improve this question














I am trying to copy an image from an excel named Inputs_v3 and sheet named Inputs and save. The code is as follows`



import win32com.client as win32       
from PIL import ImageGrab
from xlrd import open_workbook
import os

excel = win32.gencache.EnsureDispatch("Excel.Application")
wb = open_workbook('Inputs_v3.xlsm')
r = wb.sheet_by_name('Inputs')
r.CopyPicture()

im = ImageGrab.grabclipboard()
im.save('somefile.png','PNG')


` The error is as follows



'Attribute error: 'Sheet' object has no attribute 'CopyPicture''


Please suggest where I am doing wrong.Thanks in advance







python excel






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked May 12 '16 at 7:29









Goutham PathuriGoutham Pathuri

2017




2017













  • You're mixing up win32com calls with the xlrd package, which have nothing to do with each other. You've set excel to be a reference to the Excel app but then you don't do anything with it. I'm not fully familiar with either xlrd or the Excel COM model but it looks as if CopyPicture is a method you need to call on the Excel worksheet object, not the xlrd sheet_by_name object. If you can get the picture using xlrd do that and don't use COM, otherwise use COM and you don't need xlrd.

    – nekomatic
    May 12 '16 at 7:54











  • Hi..I have tried to open the work book using win32.com by excel = win32.gencache.EnsureDispatch("Excel.Application") wb = excel.Workbooks.Open("Inputs_v3.xlsm")...but it is showing that we couldn't find the file

    – Goutham Pathuri
    May 12 '16 at 9:29













  • Sounds like it couldn't find the file then ;-) Try giving it a full path name.

    – nekomatic
    May 12 '16 at 9:39



















  • You're mixing up win32com calls with the xlrd package, which have nothing to do with each other. You've set excel to be a reference to the Excel app but then you don't do anything with it. I'm not fully familiar with either xlrd or the Excel COM model but it looks as if CopyPicture is a method you need to call on the Excel worksheet object, not the xlrd sheet_by_name object. If you can get the picture using xlrd do that and don't use COM, otherwise use COM and you don't need xlrd.

    – nekomatic
    May 12 '16 at 7:54











  • Hi..I have tried to open the work book using win32.com by excel = win32.gencache.EnsureDispatch("Excel.Application") wb = excel.Workbooks.Open("Inputs_v3.xlsm")...but it is showing that we couldn't find the file

    – Goutham Pathuri
    May 12 '16 at 9:29













  • Sounds like it couldn't find the file then ;-) Try giving it a full path name.

    – nekomatic
    May 12 '16 at 9:39

















You're mixing up win32com calls with the xlrd package, which have nothing to do with each other. You've set excel to be a reference to the Excel app but then you don't do anything with it. I'm not fully familiar with either xlrd or the Excel COM model but it looks as if CopyPicture is a method you need to call on the Excel worksheet object, not the xlrd sheet_by_name object. If you can get the picture using xlrd do that and don't use COM, otherwise use COM and you don't need xlrd.

– nekomatic
May 12 '16 at 7:54





You're mixing up win32com calls with the xlrd package, which have nothing to do with each other. You've set excel to be a reference to the Excel app but then you don't do anything with it. I'm not fully familiar with either xlrd or the Excel COM model but it looks as if CopyPicture is a method you need to call on the Excel worksheet object, not the xlrd sheet_by_name object. If you can get the picture using xlrd do that and don't use COM, otherwise use COM and you don't need xlrd.

– nekomatic
May 12 '16 at 7:54













Hi..I have tried to open the work book using win32.com by excel = win32.gencache.EnsureDispatch("Excel.Application") wb = excel.Workbooks.Open("Inputs_v3.xlsm")...but it is showing that we couldn't find the file

– Goutham Pathuri
May 12 '16 at 9:29







Hi..I have tried to open the work book using win32.com by excel = win32.gencache.EnsureDispatch("Excel.Application") wb = excel.Workbooks.Open("Inputs_v3.xlsm")...but it is showing that we couldn't find the file

– Goutham Pathuri
May 12 '16 at 9:29















Sounds like it couldn't find the file then ;-) Try giving it a full path name.

– nekomatic
May 12 '16 at 9:39





Sounds like it couldn't find the file then ;-) Try giving it a full path name.

– nekomatic
May 12 '16 at 9:39












3 Answers
3






active

oldest

votes


















2














The following code will get you the win32com reference that you actually need to access the Excel worksheet's objects and methods:



import win32com.client as win32
excel = win32.gencache.EnsureDispatch('Excel.Application')
wb = excel.Workbooks.Open('myworkbook.xlsx')
ws = wb.Worksheets('worksheet_name') # alternatively Worksheets(1) etc


Now you can do, for example:



ws.Shapes(1).CopyPicture()


I've tested this with Python 3.4, pywin32 219 and Excel 2010 on Windows 7.



Note that this doesn't involve xlrd at all - that's a package that can read Excel files without having Excel installed on the computer, but I don't know if it supports getting images of or from Excel workbooks.






share|improve this answer


























  • Thanks.. I need to get a particular picture on the worksheet. According to your code(range) it is taking image of entire screen in the range and in the code it is giving the error: 'Nonetype object has no attribute save' . I guess the code is not detecting the image on the clipboard.But image is getting copied on the clipboard. Can you suggest any solution for this problem?

    – Goutham Pathuri
    May 12 '16 at 18:23













  • See edited answer to copy picture, rather than image of worksheet. I don't know PIL and can't test it as I don't have Python 2.x installed - I suggest you do some more research and experimentation on that and if you don't get anywhere, ask a new question specifically about that.

    – nekomatic
    May 13 '16 at 13:17











  • stackoverflow.com/questions/17282278/… might be relevant?

    – nekomatic
    May 13 '16 at 13:21



















0














You need to include the cell position for the image in my opinion.
Try(please replace with cell values):



import win32com.client as win32       
from PIL import ImageGrab
from xlrd import open_workbook
import os

excel = win32.gencache.EnsureDispatch("Excel.Application")
wb = open_workbook('Inputs_v3.xlsm')
r = wb.sheet_by_name('Inputs')
r.Range(r.Cells(1,1),r.Cells(8+rows,total_length)).CopyPicture()

im = ImageGrab.grabclipboard()
im.save('somefile.png','PNG')


Alternately, you can also use the chart objects:



import win32com.client as win32
from PIL import ImageGrab
from xlrd import open_workbook
import os

excel = win32.gencache.EnsureDispatch("Excel.Application")
wb = open_workbook('Inputs_v3.xlsm')
r = wb.sheet_by_name('Inputs')
for chart in r.Chartobjects():
//implement your custom logic here
chart.CopyPicture()
im = ImageGrab.grabclipboard()
im.save('somefile.png','PNG')


Additional references:



Python save xlPicture from clipboard



Export Charts from Excel as images using Python



https://msdn.microsoft.com/en-/library/microsoft.office.interop.excel.picture.copypicture(v=office.14).aspx






share|improve this answer


























  • Have you tested any of this? An xlrd Sheet object does not have Cells, Range, or ChartObjects properties or a CopyPicture method.

    – nekomatic
    May 12 '16 at 8:02











  • No, I haven't but seems to be working with different sources; please find the references.

    – PseudoAj
    May 12 '16 at 8:06



















0














Use a library called excel2img, in one line you can take a screenshot from any excel file



import excel2img
excel2img.export_img("Excel File Full Path", "Target Image full Path", "Excel SheetName", None)



and you can identify a specific cells range as well.



import excel2img
excel2img.export_img("test.xlsx", "test.bmp", "", "Sheet2!B2:C15")



I hope this will help.






share|improve this answer



















  • 1





    While this may solve OP's problem, it would help to explain why OP should use this library instead of their current approach

    – MyStackRunnethOver
    Nov 22 '18 at 0:24











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37180097%2fcopy-image-from-excel-and-save-it-using-python%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














The following code will get you the win32com reference that you actually need to access the Excel worksheet's objects and methods:



import win32com.client as win32
excel = win32.gencache.EnsureDispatch('Excel.Application')
wb = excel.Workbooks.Open('myworkbook.xlsx')
ws = wb.Worksheets('worksheet_name') # alternatively Worksheets(1) etc


Now you can do, for example:



ws.Shapes(1).CopyPicture()


I've tested this with Python 3.4, pywin32 219 and Excel 2010 on Windows 7.



Note that this doesn't involve xlrd at all - that's a package that can read Excel files without having Excel installed on the computer, but I don't know if it supports getting images of or from Excel workbooks.






share|improve this answer


























  • Thanks.. I need to get a particular picture on the worksheet. According to your code(range) it is taking image of entire screen in the range and in the code it is giving the error: 'Nonetype object has no attribute save' . I guess the code is not detecting the image on the clipboard.But image is getting copied on the clipboard. Can you suggest any solution for this problem?

    – Goutham Pathuri
    May 12 '16 at 18:23













  • See edited answer to copy picture, rather than image of worksheet. I don't know PIL and can't test it as I don't have Python 2.x installed - I suggest you do some more research and experimentation on that and if you don't get anywhere, ask a new question specifically about that.

    – nekomatic
    May 13 '16 at 13:17











  • stackoverflow.com/questions/17282278/… might be relevant?

    – nekomatic
    May 13 '16 at 13:21
















2














The following code will get you the win32com reference that you actually need to access the Excel worksheet's objects and methods:



import win32com.client as win32
excel = win32.gencache.EnsureDispatch('Excel.Application')
wb = excel.Workbooks.Open('myworkbook.xlsx')
ws = wb.Worksheets('worksheet_name') # alternatively Worksheets(1) etc


Now you can do, for example:



ws.Shapes(1).CopyPicture()


I've tested this with Python 3.4, pywin32 219 and Excel 2010 on Windows 7.



Note that this doesn't involve xlrd at all - that's a package that can read Excel files without having Excel installed on the computer, but I don't know if it supports getting images of or from Excel workbooks.






share|improve this answer


























  • Thanks.. I need to get a particular picture on the worksheet. According to your code(range) it is taking image of entire screen in the range and in the code it is giving the error: 'Nonetype object has no attribute save' . I guess the code is not detecting the image on the clipboard.But image is getting copied on the clipboard. Can you suggest any solution for this problem?

    – Goutham Pathuri
    May 12 '16 at 18:23













  • See edited answer to copy picture, rather than image of worksheet. I don't know PIL and can't test it as I don't have Python 2.x installed - I suggest you do some more research and experimentation on that and if you don't get anywhere, ask a new question specifically about that.

    – nekomatic
    May 13 '16 at 13:17











  • stackoverflow.com/questions/17282278/… might be relevant?

    – nekomatic
    May 13 '16 at 13:21














2












2








2







The following code will get you the win32com reference that you actually need to access the Excel worksheet's objects and methods:



import win32com.client as win32
excel = win32.gencache.EnsureDispatch('Excel.Application')
wb = excel.Workbooks.Open('myworkbook.xlsx')
ws = wb.Worksheets('worksheet_name') # alternatively Worksheets(1) etc


Now you can do, for example:



ws.Shapes(1).CopyPicture()


I've tested this with Python 3.4, pywin32 219 and Excel 2010 on Windows 7.



Note that this doesn't involve xlrd at all - that's a package that can read Excel files without having Excel installed on the computer, but I don't know if it supports getting images of or from Excel workbooks.






share|improve this answer















The following code will get you the win32com reference that you actually need to access the Excel worksheet's objects and methods:



import win32com.client as win32
excel = win32.gencache.EnsureDispatch('Excel.Application')
wb = excel.Workbooks.Open('myworkbook.xlsx')
ws = wb.Worksheets('worksheet_name') # alternatively Worksheets(1) etc


Now you can do, for example:



ws.Shapes(1).CopyPicture()


I've tested this with Python 3.4, pywin32 219 and Excel 2010 on Windows 7.



Note that this doesn't involve xlrd at all - that's a package that can read Excel files without having Excel installed on the computer, but I don't know if it supports getting images of or from Excel workbooks.







share|improve this answer














share|improve this answer



share|improve this answer








edited May 13 '16 at 13:12

























answered May 12 '16 at 9:38









nekomaticnekomatic

4,17111522




4,17111522













  • Thanks.. I need to get a particular picture on the worksheet. According to your code(range) it is taking image of entire screen in the range and in the code it is giving the error: 'Nonetype object has no attribute save' . I guess the code is not detecting the image on the clipboard.But image is getting copied on the clipboard. Can you suggest any solution for this problem?

    – Goutham Pathuri
    May 12 '16 at 18:23













  • See edited answer to copy picture, rather than image of worksheet. I don't know PIL and can't test it as I don't have Python 2.x installed - I suggest you do some more research and experimentation on that and if you don't get anywhere, ask a new question specifically about that.

    – nekomatic
    May 13 '16 at 13:17











  • stackoverflow.com/questions/17282278/… might be relevant?

    – nekomatic
    May 13 '16 at 13:21



















  • Thanks.. I need to get a particular picture on the worksheet. According to your code(range) it is taking image of entire screen in the range and in the code it is giving the error: 'Nonetype object has no attribute save' . I guess the code is not detecting the image on the clipboard.But image is getting copied on the clipboard. Can you suggest any solution for this problem?

    – Goutham Pathuri
    May 12 '16 at 18:23













  • See edited answer to copy picture, rather than image of worksheet. I don't know PIL and can't test it as I don't have Python 2.x installed - I suggest you do some more research and experimentation on that and if you don't get anywhere, ask a new question specifically about that.

    – nekomatic
    May 13 '16 at 13:17











  • stackoverflow.com/questions/17282278/… might be relevant?

    – nekomatic
    May 13 '16 at 13:21

















Thanks.. I need to get a particular picture on the worksheet. According to your code(range) it is taking image of entire screen in the range and in the code it is giving the error: 'Nonetype object has no attribute save' . I guess the code is not detecting the image on the clipboard.But image is getting copied on the clipboard. Can you suggest any solution for this problem?

– Goutham Pathuri
May 12 '16 at 18:23







Thanks.. I need to get a particular picture on the worksheet. According to your code(range) it is taking image of entire screen in the range and in the code it is giving the error: 'Nonetype object has no attribute save' . I guess the code is not detecting the image on the clipboard.But image is getting copied on the clipboard. Can you suggest any solution for this problem?

– Goutham Pathuri
May 12 '16 at 18:23















See edited answer to copy picture, rather than image of worksheet. I don't know PIL and can't test it as I don't have Python 2.x installed - I suggest you do some more research and experimentation on that and if you don't get anywhere, ask a new question specifically about that.

– nekomatic
May 13 '16 at 13:17





See edited answer to copy picture, rather than image of worksheet. I don't know PIL and can't test it as I don't have Python 2.x installed - I suggest you do some more research and experimentation on that and if you don't get anywhere, ask a new question specifically about that.

– nekomatic
May 13 '16 at 13:17













stackoverflow.com/questions/17282278/… might be relevant?

– nekomatic
May 13 '16 at 13:21





stackoverflow.com/questions/17282278/… might be relevant?

– nekomatic
May 13 '16 at 13:21













0














You need to include the cell position for the image in my opinion.
Try(please replace with cell values):



import win32com.client as win32       
from PIL import ImageGrab
from xlrd import open_workbook
import os

excel = win32.gencache.EnsureDispatch("Excel.Application")
wb = open_workbook('Inputs_v3.xlsm')
r = wb.sheet_by_name('Inputs')
r.Range(r.Cells(1,1),r.Cells(8+rows,total_length)).CopyPicture()

im = ImageGrab.grabclipboard()
im.save('somefile.png','PNG')


Alternately, you can also use the chart objects:



import win32com.client as win32
from PIL import ImageGrab
from xlrd import open_workbook
import os

excel = win32.gencache.EnsureDispatch("Excel.Application")
wb = open_workbook('Inputs_v3.xlsm')
r = wb.sheet_by_name('Inputs')
for chart in r.Chartobjects():
//implement your custom logic here
chart.CopyPicture()
im = ImageGrab.grabclipboard()
im.save('somefile.png','PNG')


Additional references:



Python save xlPicture from clipboard



Export Charts from Excel as images using Python



https://msdn.microsoft.com/en-/library/microsoft.office.interop.excel.picture.copypicture(v=office.14).aspx






share|improve this answer


























  • Have you tested any of this? An xlrd Sheet object does not have Cells, Range, or ChartObjects properties or a CopyPicture method.

    – nekomatic
    May 12 '16 at 8:02











  • No, I haven't but seems to be working with different sources; please find the references.

    – PseudoAj
    May 12 '16 at 8:06
















0














You need to include the cell position for the image in my opinion.
Try(please replace with cell values):



import win32com.client as win32       
from PIL import ImageGrab
from xlrd import open_workbook
import os

excel = win32.gencache.EnsureDispatch("Excel.Application")
wb = open_workbook('Inputs_v3.xlsm')
r = wb.sheet_by_name('Inputs')
r.Range(r.Cells(1,1),r.Cells(8+rows,total_length)).CopyPicture()

im = ImageGrab.grabclipboard()
im.save('somefile.png','PNG')


Alternately, you can also use the chart objects:



import win32com.client as win32
from PIL import ImageGrab
from xlrd import open_workbook
import os

excel = win32.gencache.EnsureDispatch("Excel.Application")
wb = open_workbook('Inputs_v3.xlsm')
r = wb.sheet_by_name('Inputs')
for chart in r.Chartobjects():
//implement your custom logic here
chart.CopyPicture()
im = ImageGrab.grabclipboard()
im.save('somefile.png','PNG')


Additional references:



Python save xlPicture from clipboard



Export Charts from Excel as images using Python



https://msdn.microsoft.com/en-/library/microsoft.office.interop.excel.picture.copypicture(v=office.14).aspx






share|improve this answer


























  • Have you tested any of this? An xlrd Sheet object does not have Cells, Range, or ChartObjects properties or a CopyPicture method.

    – nekomatic
    May 12 '16 at 8:02











  • No, I haven't but seems to be working with different sources; please find the references.

    – PseudoAj
    May 12 '16 at 8:06














0












0








0







You need to include the cell position for the image in my opinion.
Try(please replace with cell values):



import win32com.client as win32       
from PIL import ImageGrab
from xlrd import open_workbook
import os

excel = win32.gencache.EnsureDispatch("Excel.Application")
wb = open_workbook('Inputs_v3.xlsm')
r = wb.sheet_by_name('Inputs')
r.Range(r.Cells(1,1),r.Cells(8+rows,total_length)).CopyPicture()

im = ImageGrab.grabclipboard()
im.save('somefile.png','PNG')


Alternately, you can also use the chart objects:



import win32com.client as win32
from PIL import ImageGrab
from xlrd import open_workbook
import os

excel = win32.gencache.EnsureDispatch("Excel.Application")
wb = open_workbook('Inputs_v3.xlsm')
r = wb.sheet_by_name('Inputs')
for chart in r.Chartobjects():
//implement your custom logic here
chart.CopyPicture()
im = ImageGrab.grabclipboard()
im.save('somefile.png','PNG')


Additional references:



Python save xlPicture from clipboard



Export Charts from Excel as images using Python



https://msdn.microsoft.com/en-/library/microsoft.office.interop.excel.picture.copypicture(v=office.14).aspx






share|improve this answer















You need to include the cell position for the image in my opinion.
Try(please replace with cell values):



import win32com.client as win32       
from PIL import ImageGrab
from xlrd import open_workbook
import os

excel = win32.gencache.EnsureDispatch("Excel.Application")
wb = open_workbook('Inputs_v3.xlsm')
r = wb.sheet_by_name('Inputs')
r.Range(r.Cells(1,1),r.Cells(8+rows,total_length)).CopyPicture()

im = ImageGrab.grabclipboard()
im.save('somefile.png','PNG')


Alternately, you can also use the chart objects:



import win32com.client as win32
from PIL import ImageGrab
from xlrd import open_workbook
import os

excel = win32.gencache.EnsureDispatch("Excel.Application")
wb = open_workbook('Inputs_v3.xlsm')
r = wb.sheet_by_name('Inputs')
for chart in r.Chartobjects():
//implement your custom logic here
chart.CopyPicture()
im = ImageGrab.grabclipboard()
im.save('somefile.png','PNG')


Additional references:



Python save xlPicture from clipboard



Export Charts from Excel as images using Python



https://msdn.microsoft.com/en-/library/microsoft.office.interop.excel.picture.copypicture(v=office.14).aspx







share|improve this answer














share|improve this answer



share|improve this answer








edited May 23 '17 at 12:07









Community

11




11










answered May 12 '16 at 7:42









PseudoAjPseudoAj

2,07711225




2,07711225













  • Have you tested any of this? An xlrd Sheet object does not have Cells, Range, or ChartObjects properties or a CopyPicture method.

    – nekomatic
    May 12 '16 at 8:02











  • No, I haven't but seems to be working with different sources; please find the references.

    – PseudoAj
    May 12 '16 at 8:06



















  • Have you tested any of this? An xlrd Sheet object does not have Cells, Range, or ChartObjects properties or a CopyPicture method.

    – nekomatic
    May 12 '16 at 8:02











  • No, I haven't but seems to be working with different sources; please find the references.

    – PseudoAj
    May 12 '16 at 8:06

















Have you tested any of this? An xlrd Sheet object does not have Cells, Range, or ChartObjects properties or a CopyPicture method.

– nekomatic
May 12 '16 at 8:02





Have you tested any of this? An xlrd Sheet object does not have Cells, Range, or ChartObjects properties or a CopyPicture method.

– nekomatic
May 12 '16 at 8:02













No, I haven't but seems to be working with different sources; please find the references.

– PseudoAj
May 12 '16 at 8:06





No, I haven't but seems to be working with different sources; please find the references.

– PseudoAj
May 12 '16 at 8:06











0














Use a library called excel2img, in one line you can take a screenshot from any excel file



import excel2img
excel2img.export_img("Excel File Full Path", "Target Image full Path", "Excel SheetName", None)



and you can identify a specific cells range as well.



import excel2img
excel2img.export_img("test.xlsx", "test.bmp", "", "Sheet2!B2:C15")



I hope this will help.






share|improve this answer



















  • 1





    While this may solve OP's problem, it would help to explain why OP should use this library instead of their current approach

    – MyStackRunnethOver
    Nov 22 '18 at 0:24
















0














Use a library called excel2img, in one line you can take a screenshot from any excel file



import excel2img
excel2img.export_img("Excel File Full Path", "Target Image full Path", "Excel SheetName", None)



and you can identify a specific cells range as well.



import excel2img
excel2img.export_img("test.xlsx", "test.bmp", "", "Sheet2!B2:C15")



I hope this will help.






share|improve this answer



















  • 1





    While this may solve OP's problem, it would help to explain why OP should use this library instead of their current approach

    – MyStackRunnethOver
    Nov 22 '18 at 0:24














0












0








0







Use a library called excel2img, in one line you can take a screenshot from any excel file



import excel2img
excel2img.export_img("Excel File Full Path", "Target Image full Path", "Excel SheetName", None)



and you can identify a specific cells range as well.



import excel2img
excel2img.export_img("test.xlsx", "test.bmp", "", "Sheet2!B2:C15")



I hope this will help.






share|improve this answer













Use a library called excel2img, in one line you can take a screenshot from any excel file



import excel2img
excel2img.export_img("Excel File Full Path", "Target Image full Path", "Excel SheetName", None)



and you can identify a specific cells range as well.



import excel2img
excel2img.export_img("test.xlsx", "test.bmp", "", "Sheet2!B2:C15")



I hope this will help.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 23:06









user2301624user2301624

1




1








  • 1





    While this may solve OP's problem, it would help to explain why OP should use this library instead of their current approach

    – MyStackRunnethOver
    Nov 22 '18 at 0:24














  • 1





    While this may solve OP's problem, it would help to explain why OP should use this library instead of their current approach

    – MyStackRunnethOver
    Nov 22 '18 at 0:24








1




1





While this may solve OP's problem, it would help to explain why OP should use this library instead of their current approach

– MyStackRunnethOver
Nov 22 '18 at 0:24





While this may solve OP's problem, it would help to explain why OP should use this library instead of their current approach

– MyStackRunnethOver
Nov 22 '18 at 0:24


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37180097%2fcopy-image-from-excel-and-save-it-using-python%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

Npm cannot find a required file even through it is in the searched directory

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith