我必须将 Apache POI API 与 android 一起使用是否可能
Provide me some tutorial links about this
请解释一下
我必须将 Apache POI API 与 android 一起使用是否可能
Provide me some tutorial links about this
请解释一下
Apache POI 是一个非常重的库,由于方法的大小,几乎不可能在 android 中直接将此库用于多种文档类型,如 .doc 、 .docx 、 .xlsx 等。方法大小大于 65k。但是您可以通过从 jar 中删除您不需要的类来使用它,这需要太多时间和测试。我可以建议您使用 Docx4j,但不支持 .doc 文件。docx4j 中的方法限制也非常接近 65k。
如果您是初学者,您可以先在此处使用 Apache Poi 创建简单的 .doc 文件
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
试试上面的链接。我希望它对你有用。
JPresentation适用于 Android 并且没有方法大小问题。
希望它会有所帮助。
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();
}
}