Login Register






Tutorial Writing to a word file in Java filter_list
Author
Message
Writing to a word file in Java #1
In The Name OF Allah
Al-Salam Alekum

Hey guys today I'm going to teach how to write to a word file automatically using a Java script ;Wink
Well download required libraries and let's start. You will need to add these libs to your project:
  1. poi
  2. poi-ooxml
  3. poi-ooxml-schemas
  4. commons-compress
  5. xmlbeans
Let's Start I will show you everything: Open NetBeans or any IDE you are using for Java I'm using NetBeans.
[Image: p_1064lcgcl1.png]
Make a new Project
[Image: p_1064ewd842.png]
[Image: p_1064qu7ul3.png]

Okay now let's add the libraries:
[Image: p_1064hi10w4.png]
I added them:
[Image: p_10640stzy5.png]
Let's import needed packages(Libs):
[Image: p_1064uhsqm6.png]
I'll put full source down here If you had any problem post below ;Wink

PHP Code:
package writingword; import java.awt.Desktop; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFTable; import org.apache.poi.xwpf.usermodel.XWPFTableRow; /** * * @author Mr.Kurd */ public class WritingWord { /** * @param args the command line arguments */ public static void main(String[] args) throws Exception { XWPFDocument document = new XWPFDocument(); //Creating New Document file FileOutputStream out = new FileOutputStream(new File("create_table.docx")); //create table XWPFTable table = document.createTable(); //create first row XWPFTableRow tableRowOne = table.getRow(0); tableRowOne.getCell(0).setText("I"); tableRowOne.addNewTableCell().setText("Love"); tableRowOne.addNewTableCell().setText("Red Security"); //create second row XWPFTableRow tableRowTwo = table.createRow(); tableRowTwo.getCell(0).setText("I Love"); tableRowTwo.getCell(1).setText("You"); tableRowTwo.getCell(2).setText("All"); //Writing out the Data to the created file document.write(out); //Closig the process out.close(); System.out.println("create_table.docx written successully"); //Trying to open the file with the default program in ex. Word try { if (Desktop.isDesktopSupported()) { Desktop.getDesktop().open(new File("create_table.docx")); } } catch (IOException ioe) { ioe.printStackTrace(); } } }

The Output:
[Image: p_1064stoub7.png]
Now Microsoft Word opened automatically:
[Image: p_10644fmit8.png]

Note: I think people stopped using Java or this section is not active here lol so this would be my last tutorial in Java.

Wa Salam Alekum
Die  But Don't Lie
“Oh Abu Dharr! Don’t look at the smallness of the sin but look at the one you disobeyed.” Prophet Muhammad (pbuh)
[Image: p_237m2jx1.png]
Click for Free VPN

Reply

RE: Writing to a word file in Java #2
(01-04-2019, 09:44 PM)Mr.Kurd Wrote:
In The Name OF Allah
Al-Salam Alekum

Hey guys today I'm going to teach how to write to a word file automatically using a Java script ;Wink  
Well download required libraries and let's start. You will need to add these libs to your project:
  1. poi
  2. poi-ooxml
  3. poi-ooxml-schemas
  4. commons-compress
  5. xmlbeans
Let's Start I will show you everything: Open NetBeans or any IDE you are using for Java I'm using NetBeans.
[Image: p_1064lcgcl1.png]
Make a new Project
[Image: p_1064ewd842.png]
[Image: p_1064qu7ul3.png]

Okay now let's add the libraries:
[Image: p_1064hi10w4.png]
I added them:
[Image: p_10640stzy5.png]
Let's import needed packages(Libs):
[Image: p_1064uhsqm6.png]
I'll put full source down here If you had any problem post below ;Wink

PHP Code:
package writingword; import java.awt.Desktop; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFTable; import org.apache.poi.xwpf.usermodel.XWPFTableRow; /** * * @author Mr.Kurd */ public class WritingWord {    /**     * @param args the command line arguments     */    public static void main(String[] args) throws Exception {              XWPFDocument document = new XWPFDocument();              //Creating New Document file      FileOutputStream out = new FileOutputStream(new File("create_table.docx"));              //create table      XWPFTable table = document.createTable();      //create first row      XWPFTableRow tableRowOne = table.getRow(0);      tableRowOne.getCell(0).setText("I");      tableRowOne.addNewTableCell().setText("Love");      tableRowOne.addNewTableCell().setText("Red Security");      //create second row      XWPFTableRow tableRowTwo = table.createRow();      tableRowTwo.getCell(0).setText("I Love");      tableRowTwo.getCell(1).setText("You");      tableRowTwo.getCell(2).setText("All");            //Writing out the Data to the created file      document.write(out);      //Closig the process      out.close();      System.out.println("create_table.docx written successully");          //Trying to open the file with the default program in ex. Word    try {            if (Desktop.isDesktopSupported()) {                Desktop.getDesktop().open(new File("create_table.docx"));                    }        }    catch (IOException ioe) {        ioe.printStackTrace();        }          } }

The Output:
[Image: p_1064stoub7.png]
Now Microsoft Word opened automatically:
[Image: p_10644fmit8.png]

Note: I think people stopped using Java or this section is not active here lol so this would be my last tutorial in Java.

Wa Salam Alekum

very nice tutorial. Smile
My IT skills that I know perfect is SQL, HTML ,css ,wordpress, PHP.
coding skills that I know is Java, JavaScript and C#

Reply

RE: Writing to a word file in Java #3
(01-24-2019, 05:28 AM)darkninja1980 Wrote:
(01-04-2019, 09:44 PM)Mr.Kurd Wrote:
In The Name OF Allah
Al-Salam Alekum

Hey guys today I'm going to teach how to write to a word file automatically using a Java script ;Wink  
Well download required libraries and let's start. You will need to add these libs to your project:
  1. poi
  2. poi-ooxml
  3. poi-ooxml-schemas
  4. commons-compress
  5. xmlbeans
Let's Start I will show you everything: Open NetBeans or any IDE you are using for Java I'm using NetBeans.
[Image: p_1064lcgcl1.png]
Make a new Project
[Image: p_1064ewd842.png]
[Image: p_1064qu7ul3.png]

Okay now let's add the libraries:
[Image: p_1064hi10w4.png]
I added them:
[Image: p_10640stzy5.png]
Let's import needed packages(Libs):
[Image: p_1064uhsqm6.png]
I'll put full source down here If you had any problem post below ;Wink

PHP Code:
package writingword; import java.awt.Desktop; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFTable; import org.apache.poi.xwpf.usermodel.XWPFTableRow; /** * * @author Mr.Kurd */ public class WritingWord {    /**     * @param args the command line arguments     */    public static void main(String[] args) throws Exception {              XWPFDocument document = new XWPFDocument();              //Creating New Document file      FileOutputStream out = new FileOutputStream(new File("create_table.docx"));              //create table      XWPFTable table = document.createTable();      //create first row      XWPFTableRow tableRowOne = table.getRow(0);      tableRowOne.getCell(0).setText("I");      tableRowOne.addNewTableCell().setText("Love");      tableRowOne.addNewTableCell().setText("Red Security");      //create second row      XWPFTableRow tableRowTwo = table.createRow();      tableRowTwo.getCell(0).setText("I Love");      tableRowTwo.getCell(1).setText("You");      tableRowTwo.getCell(2).setText("All");            //Writing out the Data to the created file      document.write(out);      //Closig the process      out.close();      System.out.println("create_table.docx written successully");          //Trying to open the file with the default program in ex. Word    try {            if (Desktop.isDesktopSupported()) {                Desktop.getDesktop().open(new File("create_table.docx"));                    }        }    catch (IOException ioe) {        ioe.printStackTrace();        }          } }

The Output:
[Image: p_1064stoub7.png]
Now Microsoft Word opened automatically:
[Image: p_10644fmit8.png]

Note: I think people stopped using Java or this section is not active here lol so this would be my last tutorial in Java.

Wa Salam Alekum

very nice tutorial. Smile

After a long time lol, one reply not bad not bad Wink
Thank you.
Die  But Don't Lie
“Oh Abu Dharr! Don’t look at the smallness of the sin but look at the one you disobeyed.” Prophet Muhammad (pbuh)
[Image: p_237m2jx1.png]
Click for Free VPN

Reply

RE: Writing to a word file in Java #4
I completely missed this.

It's very well documented and Illustrated.
A job well done.
[Image: AD83g1A.png]

[+] 1 user Likes mothered's post
Reply

RE: Writing to a word file in Java #5
(01-24-2019, 09:27 PM)Mr.Kurd Wrote:
(01-24-2019, 05:28 AM)darkninja1980 Wrote:
(01-04-2019, 09:44 PM)Mr.Kurd Wrote:
In The Name OF Allah
Al-Salam Alekum

Hey guys today I'm going to teach how to write to a word file automatically using a Java script ;Wink  
Well download required libraries and let's start. You will need to add these libs to your project:
  1. poi
  2. poi-ooxml
  3. poi-ooxml-schemas
  4. commons-compress
  5. xmlbeans
Let's Start I will show you everything: Open NetBeans or any IDE you are using for Java I'm using NetBeans.
[Image: p_1064lcgcl1.png]
Make a new Project
[Image: p_1064ewd842.png]
[Image: p_1064qu7ul3.png]

Okay now let's add the libraries:
[Image: p_1064hi10w4.png]
I added them:
[Image: p_10640stzy5.png]
Let's import needed packages(Libs):
[Image: p_1064uhsqm6.png]
I'll put full source down here If you had any problem post below ;Wink

PHP Code:
package writingword; import java.awt.Desktop; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFTable; import org.apache.poi.xwpf.usermodel.XWPFTableRow; /** * * @author Mr.Kurd */ public class WritingWord {    /**     * @param args the command line arguments     */    public static void main(String[] args) throws Exception {              XWPFDocument document = new XWPFDocument();              //Creating New Document file      FileOutputStream out = new FileOutputStream(new File("create_table.docx"));              //create table      XWPFTable table = document.createTable();      //create first row      XWPFTableRow tableRowOne = table.getRow(0);      tableRowOne.getCell(0).setText("I");      tableRowOne.addNewTableCell().setText("Love");      tableRowOne.addNewTableCell().setText("Red Security");      //create second row      XWPFTableRow tableRowTwo = table.createRow();      tableRowTwo.getCell(0).setText("I Love");      tableRowTwo.getCell(1).setText("You");      tableRowTwo.getCell(2).setText("All");            //Writing out the Data to the created file      document.write(out);      //Closig the process      out.close();      System.out.println("create_table.docx written successully");          //Trying to open the file with the default program in ex. Word    try {            if (Desktop.isDesktopSupported()) {                Desktop.getDesktop().open(new File("create_table.docx"));                    }        }    catch (IOException ioe) {        ioe.printStackTrace();        }          } }

The Output:
[Image: p_1064stoub7.png]
Now Microsoft Word opened automatically:
[Image: p_10644fmit8.png]

Note: I think people stopped using Java or this section is not active here lol so this would be my last tutorial in Java.

Wa Salam Alekum

very nice tutorial. Smile

After a long time lol, one reply not bad not bad Wink
Thank you.

your welcome . Smile
My IT skills that I know perfect is SQL, HTML ,css ,wordpress, PHP.
coding skills that I know is Java, JavaScript and C#

[+] 1 user Likes darkninja1980's post
Reply

RE: Writing to a word file in Java #6
(01-25-2019, 04:17 AM)mothered Wrote: I completely missed this.

It's very well documented and Illustrated.
A job well done.

Thank you mothered.
Die  But Don't Lie
“Oh Abu Dharr! Don’t look at the smallness of the sin but look at the one you disobeyed.” Prophet Muhammad (pbuh)
[Image: p_237m2jx1.png]
Click for Free VPN

[+] 1 user Likes Mr.Kurd's post
Reply

RE: Writing to a word file in Java #7
(01-25-2019, 07:59 PM)Mr.Kurd Wrote:
(01-25-2019, 04:17 AM)mothered Wrote: I completely missed this.

It's very well documented and Illustrated.
A job well done.

Thank you mothered.

I am the one who bumps your post. Also, what did you use for making the screenshots?
My IT skills that I know perfect is SQL, HTML ,css ,wordpress, PHP.
coding skills that I know is Java, JavaScript and C#

Reply

RE: Writing to a word file in Java #8
(01-25-2019, 08:09 PM)darkninja1980 Wrote:
(01-25-2019, 07:59 PM)Mr.Kurd Wrote:
(01-25-2019, 04:17 AM)mothered Wrote: I completely missed this.

It's very well documented and Illustrated.
A job well done.

Thank you mothered.

I am the one who bumps your post. Also, what did you use for making the screenshots?

You need another thank? lol Okay Thanks(Thank + s) so more than a Thank xD
Well, I used Lightshot it is pretty nice and easy.
Die  But Don't Lie
“Oh Abu Dharr! Don’t look at the smallness of the sin but look at the one you disobeyed.” Prophet Muhammad (pbuh)
[Image: p_237m2jx1.png]
Click for Free VPN

Reply

RE: Writing to a word file in Java #9
(01-25-2019, 08:57 PM)Mr.Kurd Wrote:
(01-25-2019, 08:09 PM)darkninja1980 Wrote:
(01-25-2019, 07:59 PM)Mr.Kurd Wrote: Thank you mothered.

I am the one who bumps your post. Also, what did you use for making the screenshots?

You need another thank? lol Okay Thanks(Thank + s) so more than a Thank xD
Well, I used Lightshot it is pretty nice and easy.

Is Lightshot is a free program?
My IT skills that I know perfect is SQL, HTML ,css ,wordpress, PHP.
coding skills that I know is Java, JavaScript and C#

Reply

RE: Writing to a word file in Java #10
(01-25-2019, 09:10 PM)darkninja1980 Wrote:
(01-25-2019, 08:57 PM)Mr.Kurd Wrote:
(01-25-2019, 08:09 PM)darkninja1980 Wrote: I am the one who bumps your post. Also, what did you use for making the screenshots?

You need another thank? lol Okay Thanks(Thank + s) so more than a Thank xD
Well, I used Lightshot it is pretty nice and easy.

Is Lightshot is a free program?
Yep
https://app.prntscr.com/en/index.html
Die  But Don't Lie
“Oh Abu Dharr! Don’t look at the smallness of the sin but look at the one you disobeyed.” Prophet Muhammad (pbuh)
[Image: p_237m2jx1.png]
Click for Free VPN

[+] 2 users Like Mr.Kurd's post
Reply