안녕하세요.
안드로이드앱에서 엑셀파일에 이미지를 삽입하고자하는데 아래와같이 poi 이용하여 코드 작성했습니다.
코드는 api 거의 그대로 사용한거구요.
라이브러리 제대로 추가해준것같은데 코드 아래와 같은 오류가 발생합니다.
검색해서 이것저것 여러가지 방법 사용해봤는데 여전하네요.....혹시 도움 주실분 있으신가요?ㅠㅠ
public void boardToExcel(String filePath) {
// create a new workbook
Workbook wb = new XSSFWorkbook();
//Workbook wb = new HSSFWorkbook();
// add picture data to this workbook.
InputStream is = null;
try {
is = new FileInputStream(
"/storage/emulated/0/Gallery/test.jpg");
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
byte[] bytes = null;
try {
bytes = IOUtils.toByteArray(is);
} catch (IOException e1) {
e1.printStackTrace();
}
int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);
try {
is.close();
} catch (IOException e1) {
e1.printStackTrace();
}
CreationHelper helper = wb.getCreationHelper();
// create sheet
Sheet sheet = wb.createSheet();
// Create the drawing patriarch. This is the top level container for all
// shapes.
Drawing drawing = sheet.createDrawingPatriarch();
// add a picture shape
ClientAnchor anchor = helper.createClientAnchor();
// set top-left corner of the picture,
// subsequent call of Picture#resize() will operate relative to it
anchor.setCol1(3);
anchor.setRow1(2);
Picture pict = drawing.createPicture(anchor, pictureIdx);
// auto-size picture relative to its top-left corner
pict.resize();
FileOutputStream fileOut = null;
try {
fileOut = new FileOutputStream(filePath);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
wb.write(fileOut);
} catch (IOException e) {
e.printStackTrace();
}
try {
fileOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
=================================================
11-10 15:50:53.320: E/dalvikvm(25321): Could not find class 'org.apache.poi.xssf.usermodel.XSSFWorkbook', referenced from method com.example.boardtoexcelfinal.MainActivity.boardToExcel
11-10 15:50:53.320: W/dalvikvm(25321): VFY: unable to resolve new-instance 41 (Lorg/apache/poi/xssf/usermodel/XSSFWorkbook;) in Lcom/example/boardtoexcelfinal/MainActivity;
11-10 15:50:53.320: D/dalvikvm(25321): VFY: replacing opcode 0x22 at 0x0000
11-10 15:50:53.320: D/dalvikvm(25321): DexOpt: unable to opt direct call 0x0032 at 0x02 in Lcom/example/boardtoexcelfinal/MainActivity;.boardToExcel
11-10 15:50:53.370: D/BubblePopupHelper(25321): isShowingBubblePopup : false
11-10 15:50:53.400: I/Adreno-EGL(25321): <qeglDrvAPI_eglInitialize:385>: EGL 1.4 QUALCOMM build: ()
11-10 15:50:53.400: I/Adreno-EGL(25321): OpenGL ES Shader Compiler Version: E031.24.00.02
11-10 15:50:53.400: I/Adreno-EGL(25321): Build Date: 01/20/14 Mon
11-10 15:50:53.400: I/Adreno-EGL(25321): Local Branch: PMH2-KK_3.5-RB1-AU61-554722-586267-set2
11-10 15:50:53.400: I/Adreno-EGL(25321): Remote Branch:
11-10 15:50:53.400: I/Adreno-EGL(25321): Local Patches:
11-10 15:50:53.400: I/Adreno-EGL(25321): Reconstruct Branch:
11-10 15:50:53.430: D/OpenGLRenderer(25321): Enabling debug mode 0
11-10 15:50:53.440: D/BubblePopupHelper(25321): isShowingBubblePopup : false
11-10 15:50:53.440: D/BubblePopupHelper(25321): isShowingBubblePopup : false
11-10 15:50:53.440: D/cliptray_Editor(25321): setInputTypeforClipTray(): 0
11-10 15:50:53.450: D/BubblePopupHelper(25321): isShowingBubblePopup : false
11-10 15:50:53.450: D/BubblePopupHelper(25321): isShowingBubblePopup : false
11-10 15:50:53.480: D/cliptray_Editor(25321): setInputTypeforClipTray(): 0
11-10 15:50:53.480: I/ActivityManager(25321): Timeline: Activity_idle id: android.os.BinderProxy@4293b390 time:164571647
11-10 15:50:54.480: I/ViewRootImpl(25321): ViewRoot's Touch Event : Touch Down
11-10 15:50:54.500: I/ViewRootImpl(25321): ViewRoot's Touch Event : Touch UP
11-10 15:50:54.510: D/AndroidRuntime(25321): Shutting down VM
11-10 15:50:54.510: W/dalvikvm(25321): threadid=1: thread exiting with uncaught exception (group=0x418d9e48)
11-10 15:50:54.510: E/AndroidRuntime(25321): FATAL EXCEPTION: main
11-10 15:50:54.510: E/AndroidRuntime(25321): Process: com.example.boardtoexcelfinal, PID: 25321
11-10 15:50:54.510: E/AndroidRuntime(25321): java.lang.NoClassDefFoundError: org.apache.poi.xssf.usermodel.XSSFWorkbook
11-10 15:50:54.510: E/AndroidRuntime(25321): at com.example.boardtoexcelfinal.MainActivity.boardToExcel(MainActivity.java:71)
11-10 15:50:54.510: E/AndroidRuntime(25321): at com.example.boardtoexcelfinal.MainActivity.onClick(MainActivity.java:64)
11-10 15:50:54.510: E/AndroidRuntime(25321): at android.view.View.performClick(View.java:4442)
11-10 15:50:54.510: E/AndroidRuntime(25321): at android.view.View$PerformClick.run(View.java:18473)
11-10 15:50:54.510: E/AndroidRuntime(25321): at android.os.Handler.handleCallback(Handler.java:733)
11-10 15:50:54.510: E/AndroidRuntime(25321): at android.os.Handler.dispatchMessage(Handler.java:95)
11-10 15:50:54.510: E/AndroidRuntime(25321): at android.os.Looper.loop(Looper.java:136)
11-10 15:50:54.510: E/AndroidRuntime(25321): at android.app.ActivityThread.main(ActivityThread.java:5120)
11-10 15:50:54.510: E/AndroidRuntime(25321): at java.lang.reflect.Method.invokeNative(Native Method)
11-10 15:50:54.510: E/AndroidRuntime(25321): at java.lang.reflect.Method.invoke(Method.java:515)
11-10 15:50:54.510: E/AndroidRuntime(25321): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
11-10 15:50:54.510: E/AndroidRuntime(25321): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
11-10 15:50:54.510: E/AndroidRuntime(25321): at dalvik.system.NativeStart.main(Native Method)