athrunwang

纪元
数据加载中……
快慢机 java操作excel插入图片
import com.smartxls.WorkBook;

import java.io.FileOutputStream;

public class ReadImageSample
{

    public static void main(String args[])
    {
        try
        {
            WorkBook workBook = new WorkBook();

            //open the workbook
            workBook.read("..\\template\\book.xls");

            String filename = "img";
            int type = workBook.getPictureType(0);
            if(type == -1)
                filename += ".gif";
            else if(type == 5)
                filename += ".jpg";
            else if(type == 6)
                filename += ".png";
            else if(type == 7)
                filename += ".bmp";

            byte[] imagedata = workBook.getPictureData(0);
            
            FileOutputStream fos = new FileOutputStream(filename);
            fos.write(imagedata);
            fos.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}


















import com.smartxls.PictureShape;
import com.smartxls.ShapeFormat;
import com.smartxls.WorkBook;

public class WriteImagesSample
{

    public static void main(String args[])
    {
        try
        {
            WorkBook workBook = new WorkBook();

            //Inserting image
            PictureShape pictureShape = workBook.addPicture(1, 0, 3, 8, "..\\template\\MS.GIF");
            ShapeFormat shapeFormat = pictureShape.getFormat();
            shapeFormat.setPlacementStyle(ShapeFormat.PlacementFreeFloating);
            pictureShape.setFormat();

            workBook.write(".\\pic.xls");
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

posted on 2011-12-28 19:00 AthrunWang 阅读(218) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: