![]() |
|
Tutorial Writing to a word file in Java - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Java, JVM, & JRE (https://sinister.li/Forum-Java-JVM-JRE) +--- Thread: Tutorial Writing to a word file in Java (/Thread-Tutorial-Writing-to-a-word-file-in-Java) Pages:
1
2
|
Writing to a word file in Java - Mr.Kurd - 01-04-2019 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 ; Well download required libraries and let's start. You will need to add these libs to your project: Let's Start I will show you everything: Open NetBeans or any IDE you are using for Java I'm using NetBeans. ![]() Make a new Project ![]() ![]() Okay now let's add the libraries: ![]() I added them: ![]() Let's import needed packages(Libs): ![]() I'll put full source down here If you had any problem post below ; 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: ![]() Now Microsoft Word opened automatically: ![]() 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
RE: Writing to a word file in Java - darkninja1980 - 01-24-2019 (01-04-2019, 09:44 PM)Mr.Kurd Wrote: very nice tutorial.
RE: Writing to a word file in Java - Mr.Kurd - 01-24-2019 (01-24-2019, 05:28 AM)darkninja1980 Wrote:(01-04-2019, 09:44 PM)Mr.Kurd Wrote: After a long time lol, one reply not bad not bad Thank you. RE: Writing to a word file in Java - mothered - 01-25-2019 I completely missed this. It's very well documented and Illustrated. A job well done. RE: Writing to a word file in Java - darkninja1980 - 01-25-2019 (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: your welcome .
RE: Writing to a word file in Java - Mr.Kurd - 01-25-2019 (01-25-2019, 04:17 AM)mothered Wrote: I completely missed this. Thank you mothered. RE: Writing to a word file in Java - darkninja1980 - 01-25-2019 (01-25-2019, 07:59 PM)Mr.Kurd Wrote:(01-25-2019, 04:17 AM)mothered Wrote: I completely missed this. I am the one who bumps your post. Also, what did you use for making the screenshots? RE: Writing to a word file in Java - Mr.Kurd - 01-25-2019 (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. 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. RE: Writing to a word file in Java - darkninja1980 - 01-25-2019 (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. Is Lightshot is a free program? RE: Writing to a word file in Java - Mr.Kurd - 01-25-2019 (01-25-2019, 09:10 PM)darkninja1980 Wrote:Yep(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? https://app.prntscr.com/en/index.html |