I have to Put Apache POI API with android is it possible
Provide me some tutorial links about this
Please explain about this
I have to Put Apache POI API with android is it possible
Provide me some tutorial links about this
Please explain about this
Apache POI is very heavy library and it is almost impossible to directly use this library in android for multiple document types like .doc , .docx , .xlsx etc becuase of Methods size. Methods size is greater then 65k. But you can use it by removing classes from jars which are not required by you and it requires too much time and testing. I can suggest you to use Docx4j but is does not support .doc file. Method limit is also very close to 65k in docx4j also.
If you are beginner you can start by creating simple .doc file using Apache Poi here
http://apache-poi.1045710.n5.nabble.com/Creating-new-word-doc-with-POI-td2289680.html
http://viralpatel.net/blogs/java-read-write-excel-file-apache-poi/comment-page-1/ http://poi.apache.org/poifs/how-to.html
try above link.i hope its useful to you.
JPresentation works on Android and does not have method size issue.
Hope it will help.
public void readExcelData(Context context, String filename){
try {
File file = new File(context.getExternalFilesDir(null), filename);
FileInputStream myInput = new FileInputStream(file);
Vector cellVectorHolder = new Vector();
/** Create a POIFSFileSystem object**/
POIFSFileSystem myFileSystem = new
POIFSFileSystem(myInput);
/** Create a workbook using the File System**/
HSSFWorkbook myWorkBook = new
HSSFWorkbook(myFileSystem);
/** Get the first sheet from workbook**/
HSSFSheet mySheet = myWorkBook.getSheetAt(0);
/** We now need something to
iterate through the cells.**/
Iterator rowIter = mySheet.rowIterator();
while(rowIter.hasNext())
{
HSSFRow myRow = (HSSFRow) rowIter.next();
Iterator cellIter = myRow.cellIterator();
Vector cellStoreVector=new Vector();
while(cellIter.hasNext()){
HSSFCell myCell = (HSSFCell) cellIter.next();
cellStoreVector.addElement(myCell);
}
cellVectorHolder.addElement(cellStoreVector);
}
excelTableLayout.removeAllViews();
android.widget.TableRow.LayoutParams params = new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f);
for(int i=0;i<cellVectorHolder.size();i++){
System.out.println("Nama: "+cellVectorHolder.elementAt(i));
String values = cellVectorHolder.elementAt(i)+"";
String valuesArr[] = values.split(",");
String first = valuesArr[0];
String sec = valuesArr[1];
System.out.println("\n");
TableRow row = new TableRow(ctx);
TextView firstValues = new TextView(ctx);
firstValues.setTypeface(Typeface.SERIF);
firstValues.setTextColor(Color.BLACK);
firstValues.setText(valuesArr[0].substring(1));
firstValues.setTextSize(17);
firstValues.setBackgroundResource(R.drawable.excelformatbackground);
firstValues.setPadding(6, 6, 6, 6);
firstValues.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0.1f));
firstValues.setLayoutParams(params);
TextView secondValues = new TextView(ctx);
secondValues.setTypeface(Typeface.SERIF);
secondValues.setTextColor(Color.BLACK);
secondValues.setText(valuesArr[1]);
secondValues.setTextSize(17);
secondValues.setBackgroundResource(R.drawable.excelformatbackground);
secondValues.setPadding(6, 6, 6, 6);
secondValues.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0.1f));
secondValues.setLayoutParams(params);
TextView thirdValues = new TextView(ctx);
thirdValues.setTypeface(Typeface.SERIF);
thirdValues.setTextColor(Color.BLACK);
thirdValues.setText(valuesArr[2]);
thirdValues.setTextSize(17);
thirdValues.setBackgroundResource(R.drawable.excelformatbackground);
thirdValues.setPadding(6, 6, 6, 6);
thirdValues.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0.1f));
thirdValues.setLayoutParams(params);
TextView fourthValues = new TextView(ctx);
fourthValues.setTypeface(Typeface.SERIF);
fourthValues.setTextColor(Color.BLACK);
fourthValues.setText(valuesArr[3].substring(0,valuesArr[3].length() - 1));
fourthValues.setTextSize(17);
fourthValues.setBackgroundResource(R.drawable.excelformatbackground);
fourthValues.setPadding(6, 6, 6, 6);
fourthValues.setLayoutParams(params);
row.addView(firstValues);
row.addView(secondValues);
row.addView(thirdValues);
row.addView(fourthValues);
excelTableLayout.addView(row,new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
}
System.out.println("Data is "+cellVectorHolder);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}