athrunwang

          紀元
          數(shù)據(jù)加載中……
          快慢機 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 閱讀(220) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 万源市| 华坪县| 玛沁县| 宕昌县| 陇南市| 满洲里市| 中超| 霍山县| 铜鼓县| 皮山县| 天台县| 博罗县| 滨州市| 三门峡市| 岳阳县| 黔西县| 即墨市| 沾化县| 宁波市| 土默特右旗| 马尔康县| 恩施市| 海伦市| 乌鲁木齐市| 曲靖市| 蛟河市| 新晃| 眉山市| 灌南县| 大兴区| 上高县| 岚皋县| 新绛县| 孝昌县| 榕江县| 陵水| 连南| 喀喇| 庄浪县| 元江| 图木舒克市|