Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to export image to excel in Android
    primarykey
    data
    text
    <p>I tried the following code to export image in excel on Android but I got an error. Copying logcat... please help!!</p> <p>Code:</p> <pre><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 </code></pre> <hr> <p>Logcat:</p> <blockquote> <p>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)</p> </blockquote> <p>Thanks in Advance, Hemant</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload