Total members 11894 |It is currently Mon Nov 25, 2024 2:04 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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




Author:

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


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 2 posts ] 

  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     -  
 convert word, Excel to PDF     -  
 how to connect applet with excel     -  
 VBA / Excel programmer needed     -  
 Data Export from java To Excel     -  
 Image Insert in Excel File Using POI     -  
 Crystal report export to excel, page header issue asp.net     -  









Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com