-1

I have saved a file with .docx extension in my app.the file is saved in the sdcard. The file appears as a word file in my sdcard but I am unable to open it (using polaris or any other default software) and message"unsupported file" appears.

When I save the file with .txt extension, I can open it.

    public void Savedoc(View v)
    {
        String filename = "file" + sn + ".docx";
         String filepath = "MyFileStorage";

         myExternalFile = new File(getExternalFilesDir(filepath), filename);


         try {
                FileOutputStream fos = new FileOutputStream(myExternalFile);
                fos.write(ly.getBytes());
                fos.close();
               } catch (IOException e) {
                e.printStackTrace();
               }


    }

thank you alexandru ...but now i get an error message on running the app stating "The Javadoc for this element could neither be found in the attached source nor the attached Javadoc".pls help...

user
  • 11
  • 4
  • a .txt is literally that, text in a file. Docx is proprietary and has styling in it. I am guessing you need a specific library and fileoutputstream to get the text out of it properly? I once had a similar problem with reading xlsx files when the format was just released, it was painful to work with. Good luck! – G_V Nov 06 '14 at 15:06

1 Answers1

0

You'll need to use Apache POI in order to correctly create a .docx file.

I've found this answer with a code snippet:

XWPFDocument document = new XWPFDocument();
XWPFParagraph tmpParagraph = document.createParagraph();
XWPFRun tmpRun = tmpParagraph.createRun();
tmpRun.setText("LALALALAALALAAAA");
tmpRun.setFontSize(18);
document.write(new FileOutputStream(new File("yourpathhere")));

You may find more information about how to use XWPF here.

Community
  • 1
  • 1
aluxian
  • 986
  • 10
  • 27
  • thank you ...but now i get an error message on running the app stating "The Javadoc for this element could neither be found in the attached source nor the attached Javadoc".pls help... – user Nov 10 '14 at 09:07
  • thank you alexandru...but error appears "The Javadoc for this element could neither be found in the attached source nor the attached Javadoc" and app crashes??? – user Nov 10 '14 at 09:15
  • @user Could you give me more information about the error? And please post the entire stacktrace. – aluxian Nov 10 '14 at 14:07
  • this is the logcat message: E/AndroidRuntime(890): Caused by: java.lang.VerifyError: org/apache/poi/xwpf/usermodel/XWPFDocument E/AndroidRuntime(890): at com.example.voiceofgospel.SaveSong.Savedoc(SaveSong.java:199) when i place the cursor on the new code(which you have provided),message appears Note: "The Javadoc for this element could neither be found in the attached source nor the attached Javadoc". – user Nov 11 '14 at 05:13
  • is this enough Alexandru Rosianu as i do not know how to copy entire stack trace???thanks in advance... – user Nov 11 '14 at 09:12
  • Yeah, can you tell me that code you have on line 199 in SaveSong.java? That's where it seems to be crashing. – aluxian Nov 11 '14 at 12:58
  • the code where error occurs is XWPFDocument document = new XWPFDocument(); when i hover the mouse cursor on this piece of code,i get a message "Note: This element neither has attached source nor attached Javadoc and hence no Javadoc could be found". – user Nov 11 '14 at 13:48
  • i had added an external jar file named "poi-ooxml-3.5-FINAL" to facilitate ms word handling... – user Nov 11 '14 at 14:04
  • Ok, that message only appears to tell you that it can't tell you more information about the class. But this shouldn't affect the compilation. I'm still searching for a solution... – aluxian Nov 11 '14 at 14:06
  • Have you tried adding all the dependencies listed in this post? http://stackoverflow.com/a/16680099/1133344 – aluxian Nov 11 '14 at 14:07
  • @user I've just found another library, which seems to be easier to use and requires less dependencies. Can you try this too? https://github.com/leonardoanalista/java2word – aluxian Nov 11 '14 at 14:09
  • in the link you have provided,which is the jar file i have to add using add external jars??? (using project->properties->java build path->libraries->add external jars) – user Nov 11 '14 at 14:31
  • iam a beginner to android with not much java knowledge (c,c++ only) so could u please simplify??? – user Nov 11 '14 at 14:33
  • https://github.com/leonardoanalista/java2word/wiki/Set-up-your-Development-Environment – aluxian Nov 11 '14 at 15:35
  • the new jar file is not working...could you help me with the old jar file ive mentioned because its being installed but "This element neither has attached source nor attached Javadoc and hence no Javadoc could be found" message appears... – user Nov 11 '14 at 16:25
  • Ignore that message, it's not because of it. You have a problem with the dependencies (VerifyError). You've only given me one line of the stack trace (E/AndroidRuntime(890): Caused by ... ), please post the other lines too so I can get more info. – aluxian Nov 12 '14 at 05:37
  • these are the errors on logcat: 11-12 14:08:58.596: E/AndroidRuntime(1336): at android.view.View$1.onClick(View.java:3039) 11-12 14:08:58.596: E/AndroidRuntime(1336): ... 11 more 11-12 14:08:58.596: E/AndroidRuntime(1336): Caused by: java.lang.VerifyError: org/apache/poi/xwpf/usermodel/XWPFDocument 11-12 14:08:58.596: E/AndroidRuntime(1336): at com.example.voiceofgospel.SaveSong.Savedoc(SaveSong.java:241) 11-12 14:08:58.596: E/AndroidRuntime(1336): ... 14 more thanks for ur time... – user Nov 12 '14 at 08:42
  • Hmm I don't know what to say. Here's what the VerifyError exception means if you're curious: http://stackoverflow.com/a/2518002/1133344. I don't know how to help you anymore, but I suggest that you try to re-add the dependencies. Take a look again on the XWPF docs and make sure you only import the jars that you are supposed to. VerifyError could also be the result of importing jars with common classes (so you have duplicates). – aluxian Nov 12 '14 at 13:55