Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Excel chart. Save charts as images.
#1
Hello there!
I have this excel document with multiple sheets and every sheet has a chart based on some data.
I want to get those charts from every sheet and save them in JPG's.
Can I do that?
I mean, I know I can if I record a macro to do that with the keyboard and mouse, but what I mean is to do that based on functions and not needing to open excel.

I was trying to read about charts on the forum and Quick Macros help but couldn't find anything to help me.

Thanks one more time for your help!

Take care,
Pedro Tairum
#2
Macro excel save charts as images
Code:
Copy      Help
;/exe

;change these
str workbookFile ;;if this variable empty, will use workbook currently open/active in Excel
;str workbookFile="D:\Downloads\ExcelGanttChart.xls"
str folder="$desktop$\charts" ;;will save here, in a subfolder of workbook name. Will create folders.
int openFolder=1 ;;1 or 0

;_____________________________________

;connect to Excel or open workbookFile
ExcelSheet es
if(!workbookFile.len) es.Init; else es.Init("" 8 workbookFile)
;variables
ARRAY(Excel.Chart) a
Excel.Chart c
int i
;get chart sheets
Excel.Workbook b=es._Book
foreach(c b.Charts) a[]=c
;gets chart objects of other sheets
Excel.Worksheet w
foreach w b.Worksheets
,for(i 1 w.ChartObjects.Count+1) a[]=w.ChartObjects(i).Chart
;save
str wbName=b.Name
out F"{a.len} charts found in {wbName}"
if(!a.len) ret
folder.expandpath(F"{folder}\{wbName}")
if(!dir(folder 1)) mkdir folder; else del- F"{folder}\*.jpg"
for i 0 a.len
,c=a[i]
,str name=c.Name
,out name
,str file=F"{folder}\{name}.jpg"; file.UniqueFileName
,c.Export(file)
b.Saved=TRUE
;see what we have
if(openFolder) run folder

;BEGIN PROJECT
;
;END PROJECT
#3
This was it!! This is great!! I hope it helps more people!

Thanks one more time!! Big Grin


Forum Jump:


Users browsing this thread: 1 Guest(s)