3.java poi Word
3.java poi Word
3-0.download&install
Copiez le fichier "* .jar" du fichier bin téléchargé à partir du site suivant dans Project
https://poi.apache.org/
https://xmlbeans.apache.org/download/
--Sous-composant
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class SamplePoi {
public static void main(String[] args) throws IOException {
OutputStream os = null;
try {
os = new FileOutputStream("TestWordFile.docx");
XWPFDocument wordFile = new XWPFDocument();
wordFile.write(os);//Je crée un fichier Word ici.
} catch (IOException e) {
e.printStackTrace();
} finally {
if (os != null) {
os.close();
}
}
}
}
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class SamplePoi {
public static void main(String[] args) throws IOException {
OutputStream os = null;
try {
os = new FileOutputStream("TestWordFile2.docx");
XWPFDocument wordFile = new XWPFDocument();
XWPFParagraph paragraph = wordFile.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText("AIUEO");//J'écris des lettres ici.
run.setText("Kakikukeko");
wordFile.write(os);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (os != null) {
os.close();
}
}
}
}
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class SamplePoi {
public static void main(String[] args) throws IOException {
OutputStream os = null;
try {
os = new FileOutputStream("TestWordFile.docx");
XWPFDocument wordFile = new XWPFDocument();
XWPFParagraph paragraph = wordFile.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText("AIUEO");
run.setBold(true);//C'est en gras ici.
wordFile.write(os);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (os != null) {
os.close();
}
}
}
}
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class SamplePoi {
public static void main(String[] args) throws IOException {
OutputStream os = null;
try {
os = new FileOutputStream("TestWordFile.docx");
XWPFDocument wordFile = new XWPFDocument();
XWPFParagraph paragraph = wordFile.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText("AIUEO");
run.setItalic(true);//Je le mets en italique ici.
wordFile.write(os);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (os != null) {
os.close();
}
}
}
}
import org.apache.poi.xwpf.usermodel.UnderlinePatterns;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class SamplePoi {
public static void main(String[] args) throws IOException {
OutputStream os = null;
try {
os = new FileOutputStream("TestWordFile.docx");
XWPFDocument wordFile = new XWPFDocument();
XWPFParagraph paragraph = wordFile.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText("AIUEO");
run.setUnderline(UnderlinePatterns.DOUBLE);//Il est souligné ici. Le type de soulignement peut être sélectionné dans la classe "Modèles de soulignement".
wordFile.write(os);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (os != null) {
os.close();
}
}
}
}
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class SamplePoi {
public static void main(String[] args) throws IOException {
OutputStream os = null;
try {
os = new FileOutputStream("TestWordFile.docx");
XWPFDocument wordFile = new XWPFDocument();
XWPFParagraph paragraph = wordFile.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText("AIUEO");
run.setColor("FF0000");//La couleur du texte est spécifiée ici. Hexadécimal. "RRGGBB".
wordFile.write(os);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (os != null) {
os.close();
}
}
}
}
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class SamplePoi {
public static void main(String[] args) throws IOException {
OutputStream os = null;
try {
os = new FileOutputStream("TestWordFile.docx");
XWPFDocument wordFile = new XWPFDocument();
XWPFParagraph paragraph = wordFile.createParagraph();
XWPFRun run = paragraph.createRun();
run.addTab();//Je joins un onglet ici.
run.setText("AIUEO");
wordFile.write(os);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (os != null) {
os.close();
}
}
}
}
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class SamplePoi {
public static void main(String[] args) throws IOException {
OutputStream os = null;
try {
os = new FileOutputStream("TestWordFile.docx");
XWPFDocument wordFile = new XWPFDocument();
XWPFParagraph paragraph = wordFile.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText("AIUEO");
run.setStrikeThrough(true);//Un barré est ajouté ici.
wordFile.write(os);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (os != null) {
os.close();
}
}
}
}
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class SamplePoi {
public static void main(String[] args) throws IOException {
OutputStream os = null;
try {
os = new FileOutputStream("TestWordFile.docx");
XWPFDocument wordFile = new XWPFDocument();
XWPFParagraph paragraph = wordFile.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText("AIUEO");
run.setDoubleStrikethrough(true);//Un double barré est ajouté ici.
wordFile.write(os);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (os != null) {
os.close();
}
}
}
}
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class SamplePoi {
public static void main(String[] args) throws IOException {
OutputStream os = null;
try {
os = new FileOutputStream("TestWordFile.docx");
XWPFDocument wordFile = new XWPFDocument();
XWPFParagraph paragraph = wordFile.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText("AIUEO");
run.setFontSize(20);//Je change la taille de la police ici.
wordFile.write(os);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (os != null) {
os.close();
}
}
}
}
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class SamplePoi {
public static void main(String[] args) throws IOException {
OutputStream os = null;
try {
os = new FileOutputStream("TestWordFile.docx");
XWPFDocument wordFile = new XWPFDocument();
XWPFParagraph paragraph = wordFile.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText("Hello World.");
run.setFontFamily("Times New Roman");//La police est spécifiée ici.
run.addCarriageReturn();
run = paragraph.createRun();
run.setText("Hello World.");
run.setFontFamily("MS Gothic");//La police est spécifiée ici.
wordFile.write(os);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (os != null) {
os.close();
}
}
}
}
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class SamplePoi {
public static void main(String[] args) throws IOException {
OutputStream os = null;
try {
os = new FileOutputStream("TestWordFile.docx");
XWPFDocument wordFile = new XWPFDocument();
XWPFParagraph paragraph = wordFile.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText("Hello World.");
run.addCarriageReturn();//Je mets un saut de ligne ici.
run.setText("Hello World.");
wordFile.write(os);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (os != null) {
os.close();
}
}
}
}
Recommended Posts