3.java poi Word
3.java poi Word
3-0.download&install
Kopieren Sie die Datei "* .jar" aus der Bin-Datei, die von der folgenden Site heruntergeladen wurde, in Project
https://poi.apache.org/
https://xmlbeans.apache.org/download/
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);//Ich erstelle hier eine Word-Datei.
} 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");//Ich schreibe hier Briefe.
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);//Es ist hier fett gedruckt.
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);//Ich mache es hier kursiv.
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);//Es ist hier unterstrichen. Der Unterstreichungstyp kann in der Klasse "Unterstreichungsmuster" ausgewählt werden.
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");//Hier wird die Textfarbe angegeben. Hexadezimal. "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();//Ich füge hier einen Tab hinzu.
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);//Hier wird ein Durchstreichen hinzugefügt.
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);//Hier wird ein doppelter Durchschlag hinzugefügt.
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);//Ich ändere hier die Schriftgröße.
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");//Die Schriftart wird hier angegeben.
run.addCarriageReturn();
run = paragraph.createRun();
run.setText("Hello World.");
run.setFontFamily("MS Gothic");//Die Schriftart wird hier angegeben.
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();//Ich mache hier einen Zeilenumbruch.
run.setText("Hello World.");
wordFile.write(os);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (os != null) {
os.close();
}
}
}
}
Recommended Posts