Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

Exporting Images in Excel in Android

Sun May 13, 2012 2:52 pm

Hi,

I tried the following code to export image in excel on Android but I got an error. Copying logcat... please help!!

Code:
Code:
package com.android.testexcel;

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class MyWorkBook {
   void writeImageToExcel(String filePath, String imageFileName) {
      int col = 1, row = 1;
      HSSFWorkbook wb = new HSSFWorkbook();
      HSSFSheet testsheet = wb.createSheet("test");
      System.out.println("The work book is created");
      try {
         FileOutputStream fos = new FileOutputStream(filePath);
         System.out.println("File sample.xls is created");
         FileInputStream fis = new FileInputStream(imageFileName);
         ByteArrayOutputStream img_bytes = new ByteArrayOutputStream();
         int b;
         while ((b = fis.read()) != -1)
            img_bytes.write(b);
         fis.close();
         HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0,
               (short) col, row, (short) ++col, ++row);
         int index = wb.addPicture(img_bytes.toByteArray(),
               HSSFWorkbook.PICTURE_TYPE_JPEG);
         HSSFSheet sheet = wb.getSheet("test");
         HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
         patriarch.createPicture(anchor, index);
         anchor.setAnchorType(2);
         wb.write(fos);
         System.out.println("Writing data to the xls file");
         fos.close();
         System.out.println("File closed");
      } catch (IOException ioe) {

         System.out
               .println("Hi ! You got an exception. " + ioe.getMessage());
         ioe.printStackTrace();
      }
   }
}// end of class MyWorkBook


------------------------------------------------------------------------------------------------------------
Logcat:

05-13 19:11:47.665: E/AndroidRuntime(7288): FATAL EXCEPTION: main
05-13 19:11:47.665: E/AndroidRuntime(7288): java.lang.NoClassDefFoundError: org.apache.commons.codec.digest.DigestUtils
05-13 19:11:47.665: E/AndroidRuntime(7288): at org.apache.poi.hssf.usermodel.HSSFWorkbook.addPicture(HSSFWorkbook.java:1580)
05-13 19:11:47.665: E/AndroidRuntime(7288): at com.android.testexcel.MyWorkBook.writeImageToExcel(MyWorkBook.java:30)
05-13 19:11:47.665: E/AndroidRuntime(7288): at com.android.testexcel.MainActivity.onClick(MainActivity.java:71)
05-13 19:11:47.665: E/AndroidRuntime(7288): at android.view.View.performClick(View.java:2408)
05-13 19:11:47.665: E/AndroidRuntime(7288): at android.view.View$PerformClick.run(View.java:8816)
05-13 19:11:47.665: E/AndroidRuntime(7288): at android.os.Handler.handleCallback(Handler.java:587)
05-13 19:11:47.665: E/AndroidRuntime(7288): at android.os.Handler.dispatchMessage(Handler.java:92)
05-13 19:11:47.665: E/AndroidRuntime(7288): at android.os.Looper.loop(Looper.java:123)
05-13 19:11:47.665: E/AndroidRuntime(7288): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-13 19:11:47.665: E/AndroidRuntime(7288): at java.lang.reflect.Method.invokeNative(Native Method)
05-13 19:11:47.665: E/AndroidRuntime(7288): at java.lang.reflect.Method.invoke(Method.java:521)
05-13 19:11:47.665: E/AndroidRuntime(7288): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-13 19:11:47.665: E/AndroidRuntime(7288): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-13 19:11:47.665: E/AndroidRuntime(7288): at dalvik.system.NativeStart.main(Native Method)


Thanks in Advance,
Hemant



Re: Exporting Images in Excel in Android

Sun May 13, 2012 8:45 pm

it looks that the class "org.apache.commons.codec.digest.DigestUtils" is not found .

Code:
http://grepcode.com/file/repo1.maven.org/maven2/commons-codec/commons-codec/1.5/org/apache/commons/codec/digest/DigestUtils.java


Post a reply
  Related Posts  to : Exporting Images in Excel in Android
 How to delete/remove images from excel 2007 using POI.     -  
 Need help to hire an android app development company     -  
 Sequence of Images , draw several images in a row     -  
 regarding to excel sheet     -  
 how to connect applet with excel     -  
 VBA / Excel programmer needed     -  
 convert word, Excel to PDF     -  
 Data Export from java To Excel     -  
 Image Insert in Excel File Using POI     -  
 Crystal report export to excel, page header issue asp.net     -