Java Apache POI with Android——如何创建、阅读、编写、删除 PowerPoint 演示文稿?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18887147/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 11:55:26  来源:igfitidea点击:

Apache POI with Android -- How to Create ,Read , Write, Delete PowerPoint Presentations?

javaandroidapache-poi

提问by Aravindan Srinivasan

I have to Put Apache POI API with android is it possible

我必须将 Apache POI API 与 android 一起使用是否有可能

Provide me some tutorial links about this

Please explain about this

请解释一下

回答by Rahul Chauhan

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.

Apache POI 是一个非常重的库,几乎不可能在 android 中直接使用这个库来处理多种文档类型,如 .doc 、 .docx 、 .xlsx 等,因为方法大小。方法大小大于 65k。但是您可以通过从 jars 中删除您不需要的类来使用它,这需要太多时间和测试。我可以建议您使用 Docx4j 但它不支持 .doc 文件。方法限制也非常接近 docx4j 中的 65k。

If you are beginner you can start by creating simple .doc file using Apache Poi here

如果您是初学者,您可以在此处使用 Apache Poi 创建简单的 .doc 文件

http://apache-poi.1045710.n5.nabble.com/Creating-new-word-doc-with-POI-td2289680.html

http://apache-poi.1045710.n5.nabble.com/Creating-new-word-doc-with-POI-td2289680.html

回答by Gugib

JPresentationworks on Android and does not have method size issue.

JPresentation在 Android 上工作并且没有方法大小问题。

Hope it will help.

希望它会有所帮助。

回答by Suresh Mewara

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();
}
}