Note that there are some explanatory texts on larger screens.

plurals
  1. PORead .docx file from sdcard with out using third party app
    primarykey
    data
    text
    <p>I am new to android. In my app i need to read .doc and .docx and other office suit files. As depends on their presence. I want to read it with out using Intent in my app. I tried many code but they are not working properly. My code is as shown below using various modules. What changes should i do or is there any other method to read this files?</p> <p>My code is :</p> <pre><code>/** * Apache OPI Code. */ if(Environment.getExternalStorageState().equalsIgnoreCase("y")){ TextView tv = (TextView) findViewById(R.id.textview_data_rla); WordExtractor extractor = null; try { File file = new File(getExternalFilesDir(null),"n.doc"); FileInputStream fis=new FileInputStream(file.getAbsolutePath()); Log.d("File", fis.toString()); HWPFDocument document=new HWPFDocument(fis); extractor = new WordExtractor(document); String[] fileData = extractor.getParagraphText(); for(int i=0;i&lt;fileData.length;i++){ if(fileData[i] != null){ tv.setText(fileData[i]); Log.d("file",fileData[i]); } } } catch(Exception exep){ } } /** * Using HWPFDocument. */ try { TextView tv = (TextView) findViewById(R.id.textview_data_rla); File sdcard = Environment.getExternalStorageDirectory(); File file = new File(sdcard,"n.doc"); //InputStream fis = new FileInputStream(file); POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file)); HWPFDocument doc = new HWPFDocument(fs); Range range = doc.getRange(); CharacterRun run = null; for (int i=0; i&lt;range.numCharacterRuns(); i++) { run = range.getCharacterRun(i); Log.d("character run",String.valueOf(i+1)); Log.d("Text",run.text().toString()); } tv.setText(run.text().toString()); OutputStream out = new FileOutputStream(new File("/mnt/sdcard/new.doc")); doc.write(out); out.flush(); out.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } /** * Apache POI using NPOIFSFileSystem. */ File sdcard = Environment.getExternalStorageDirectory(); File file = new File(sdcard,"n.doc"); WordExtractor extractor1 = null; try{ NPOIFSFileSystem fs = new NPOIFSFileSystem(file); extractor1 = new WordExtractor(fs.getRoot(), null); } catch (Exception e){ e.printStackTrace(); } for(String rawText : extractor1.getParagraphText()) { String text = WordExtractor.stripFields(rawText); Log.d("text",text); } /** * Apache Tika code. */ TikaConfig tika = TikaConfig.getDefaultConfig(); TikaInputStream stream = TikaInputStream.get(file); ContentHandler handler = new BodyContentHandler(); Metadata metadata = new Metadata(); tika.getParser().parse(file, handler, metadata, new ParseContext()); String text = handler.toString(); /** * Code using jOpenDocument.jar */ final OpenDocument doc = new OpenDocument(); doc.loadFrom("invoice.ods"); // Show time ! final JFrame f = new JFrame("Invoice Viewer"); ODSViewerPanel viewer = new ODSViewerPanel(doc); f.setContentPane(viewer); f.pack(); f.setVisible(true); } </code></pre> <p>Which is the correct method i have to use.</p> <p>Please reply as soon as possible. Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload