Hello, please write to whom it is not difficult code that deletes the first line in the .doc file using the Apache POI library. It is advisable to explain from start to finish how to work with this library. Understand the time itself is sorely lacking. Either give please the code of any small program using Apache POI.

  • And what is the "first line" in the .doc file? The first paragraph, perhaps? - cy6erGn0m 1:58
  • Yes, the first paragraph. - SoulOfAngel

1 answer 1

In theory, it should look something like this

HWPFDocument doc; try (FileInputStream fis = new FileInputStream("myfile.doc")) { doc = new HWPFDocument(fis); } doc.getRange().getParagraph(0).delete(); try (FileInputStream fos = new FileInputStream("myfile-out.doc")) { doc.write(fos); } 

But, for some unknown reason, it doesn't work: Word (at least my Word Starter) says something is wrong with the document .. moreover, styles are flying off ..

So if you need something reliable, then it seems the only reliable option is OpenOffice in server mode . But studying this method is not an easy task at all .. no, not simple ..

  • I added a library to the project, what classes should I use to make this code recognized by the compiler at least? import. . . - SoulOfAngel
  • Oh, I connected the poi and poi-scratchpad artifacts - cy6erGn0m mavena from the group org.apache.poi
  • Yes, my word also swears at this code. Can I try to set the properties of the document using Apache POI? Or should they have been saved? - SoulOfAngel
  • In theory, all this should be supported .. and yet there are clearly some bugs there, so apparently they are still dangerous to edit documents. - cy6erGn0m