0

Possible Duplicate:
how to read doc and excel file in android?

I have a .doc file saved on my sdcard. I need to read the content of .doc file and show it in a TextView.

Can anyone please tell me how to do this?

Community
  • 1
  • 1
Prashant Kumar
  • 419
  • 1
  • 5
  • 15
  • i suggest you to use apache poi. you can convert the word into html and render it http://poi.apache.org/ – Pramod J George Oct 10 '12 at 10:12
  • You can use **jOpenDocument**. You can refer these links: http://stackoverflow.com/questions/7790503/how-to-read-write-doc-and-excel-file-in-android http://www.jopendocument.org/ – kittu88 Oct 10 '12 at 10:06
  • Here is a code to display .doc extension files exists in SDCard [code to display .pdf,.text,.DOC,.DOCX,.doc extension files exists in SDCard ](http://pavantilak.blogspot.in/2012/02/code-to-display-pdftextdocdocxdoc.html) Refer this link http://stackoverflow.com/questions/12816281/how-to-read-doc-and-excel-file-in-android hope it will help you... – Priyank Patel Oct 10 '12 at 10:11

3 Answers3

2
public void onCreate(Bundle b){
     super.onCreate(b);
      setContentView(R.layout.main);
      String extPath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.Separator;
    InputStream inputStream = assetManager.open(extPath + "file.doc");
    String text = loadFile(inputStream); 
    TextView tv = (TextView)findViewById(R.id.txtv);
    tv.setText(text);



}



public String loadFile(InputStream inputStream){
 ByteArrayOutputStream b = new ByteArrayOutputStream();
 byte[] bytes = new byte[4096];
int length = 0;
  while(){
     b.write(bytes, 0, length);
  }
return new String(b.toByteArray(), "UTF8");
}
Akash
  • 206
  • 1
  • 4
0

One solution would be using the Apache POI Java library for parsing the .doc file.

To get a File on the SD-card in Android, you could use something like

new File(getExternalFilesDir(null), "word.doc");
P Varga
  • 19,174
  • 12
  • 70
  • 108
0

try this code

 File file=new File("/sdcard/word.doc");
                        if(file.exists())
                        {
                              Uri path=Uri.fromFile(file);
                              Intent intent=new Intent(Intent.ACTION_VIEW);
                              intent.setDataAndType(path, "application/doc");

                              try
                              {

                                    startActivity(intent);
                              }
                              catch(ActivityNotFoundException e)
                              {
                                    Toast.makeText(TestActivity.this, "No software for Doc", Toast.LENGTH_SHORT).show();
                              }
                        }
Naveen Kumar
  • 3,738
  • 4
  • 29
  • 50