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 閱讀(220) 評論(0)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 稷山县| 延津县| 呼和浩特市| 汽车| 木兰县| 铜陵市| 土默特左旗| 奈曼旗| 汉川市| 开远市| 阳城县| 弋阳县| 建水县| 夹江县| 美姑县| 资兴市| 汝州市| 彭泽县| 沂源县| 宁德市| 怀宁县| 宜兰市| 剑川县| 鹤峰县| 和龙市| 博湖县| 平昌县| 磐安县| 拉孜县| 宁城县| 九龙坡区| 大港区| 湖南省| 海伦市| 越西县| 娱乐| 宣化县| 淮北市| 绥芬河市| 揭西县| 古蔺县|