【问题标题】:Apache POI with Android -- How to Create ,Read , Write, Delete PowerPoint Presentations? [closed]Apache POI 与 Android - 如何创建、读取、写入、删除 PowerPoint 演示文稿? [关闭]
【发布时间】:2013-09-19 05:59:35
【问题描述】:

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

Provide me some tutorial links about this

请解释一下

【问题讨论】:

标签: java android apache-poi


【解决方案1】:

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

【讨论】:

    【解决方案2】:
    【解决方案3】:

    JPresentation 适用于 Android,没有方法大小问题。

    希望它会有所帮助。

    【讨论】:

      【解决方案4】:
      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();
      }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-05-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-17
        • 2010-10-03
        相关资源
        最近更新 更多