Excel图表转成图片

关于excel 图表转成图片

知识点:excel 生成的图表不是图片

尝试.    通过Java调用POI接口挺难把excel生成的图表转成图片导出来

ps.      其它生成图表的工具,如jfreechart,参考链接:http://www.open-open.com/lib/view/open1365997415828.html

       但是生成的图表会和Excel生成的有差异

办法一:excel中创建宏,将图表生成图片到指定目录,

           只需要几行代码:

           Sub SaveChartAsGIF ()
    Fname = ThisWorkbook.Path & "" & ActiveChart.Name & ".gif"
    ActiveChart.Export FileName:=Fname, FilterName:="GIF"
    End Sub

    参考链接: http://soft.yesky.com/office/122/2296622.shtml 

办法二:VBA编程:

    用VBA先转成图片,并为有规律的图片名,插入PPT如果也用VBA实现,那只要按2次快捷键(包括转换图片)。

    当然也可一次在PPT中实现,只要在PPT的VBA中CreateObject("Excel.application")。

办法三:perl编程:

    用PERL则只要写个脚本运行一次,就可以把excel中的图表生成图片,并转到ppt中(PERL中使用Win32-OLE和Win32-PowerPoint模块)。

    用PERL还能很简单地实现图片缩放和排版,一句代码搞定:

    $pp->add_picture($picture, { left => $left, top => $top ,width=>650,height=>300})。

    方法二、三的思路 参考:http://club.excelhome.net/thread-250076-1-1.html  中aef25uuu 的回复

      

    代码实现:

    一、      save a chart from Microsoft Excel as GIF/JPEG/PNG

           参考:http://www.uni-hildesheim.de/rz/DOC/perl/html/faq/Windows/ActivePerl-Winfaq12.html  

    中的“How do I save a chart from Microsoft Excel as GIF/JPEG/PNG?”部分

           代码:

    
use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const;
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3;        # die on errors...

my $filename = 'E:\visual box\share\perl\DataTemplate1.xlsx';
my $filter = 'JPG';           # can be GIF, JPG, JPEG or PNG
my $count = 0;

my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
    || Win32::OLE->new('Excel.Application', 'Quit');  # use the Excel application if it's open, otherwise open new
my $Book = $Excel->Workbooks->Open( $filename );      # open the file
foreach my $Sheet (in $Book->Sheets) {                # loop through all sheets
    foreach my $ChartObj (in $Sheet->ChartObjects) {  # loop through all chartobjects in the sheet
        my $savename = "$filename." . $count++ . ".$filter";
        $ChartObj->Chart->Export({
            FileName    => $savename,
            FilterName  => $filter,
            Interactive => 0});
    }
}
$Book->Close;
ExcelChartToImage

    二、      perl 把excel转成html

    参考:http://zyj4538.blog.163.com/blog/static/2765753220112285537776/

    

    遇到问题:

    一、  

        描述:Perl lib version <v5.8.3> doesn't match executable version <v5.8.8>

           at E:oracleproduct10.2.0db_1perl5.8.3lib....

        原因:之前安装过oracle,其中默认安装了perl;现在安装的perl与其冲突了,

        解决办法:将现在perl安装目录下lib目录中的Config.pm、Config.pod拷贝到oracle中对应的perl下:

        E:oracleproduct10.2.0db_1perl5.8.3libMSWin32-x86-multi-thread

    二、  

        描述:运行上述写好的pl代码时,出现这个错误

        原因:本机上安装的Excel的问题,在别的电脑上运行时成功地生成了图片,可能是由于本机Excel是精简版的,W32-OLE获取不到Excel的com object

        解决办法:安装原装版的Excel,而不是精简版的

原文地址:https://www.cnblogs.com/-wangjiannan/p/3671171.html