ขนาดวิดีโอ: 1280 X 720853 X 480640 X 360
แสดงแผงควบคุมโปรแกรมเล่น
เล่นอัตโนมัติ
เล่นใหม่
Nice Tutorial!
Please send the link of the code
Create a normal java project then convert to maven project. Replace pom.xml 4.0.0 WordDemo WordDemo 0.0.1-SNAPSHOT org.apache.poi poi-ooxml 4.1.0 src maven-compiler-plugin 3.3 1.8 1.8 Here's the code:package tip.javaee;import java.io.FileOutputStream;import java.math.BigInteger;import org.apache.poi.xwpf.usermodel.XWPFAbstractNum;import org.apache.poi.xwpf.usermodel.XWPFDocument;import org.apache.poi.xwpf.usermodel.XWPFNumbering;import org.apache.poi.xwpf.usermodel.XWPFParagraph;import org.apache.poi.xwpf.usermodel.XWPFRun;import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTAbstractNum;import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNumbering;public class MultiLevelNumbering { private static int subIndex = 1; private static int mainIndex = 1; public static void main(String[] args) throws Exception { StringBuilder xml = new StringBuilder(); xml.append( ""); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append( " "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(" "); xml.append(""); XWPFDocument document = new XWPFDocument(); XWPFParagraph paragraph = document.createParagraph(); XWPFRun run = paragraph.createRun(); CTNumbering cTNumbering = CTNumbering.Factory.parse(xml.toString()); CTAbstractNum cTAbstractNum = cTNumbering.getAbstractNumArray(0); XWPFAbstractNum abstractNum = new XWPFAbstractNum(cTAbstractNum); XWPFNumbering numbering = document.createNumbering(); BigInteger abstractNumID = numbering.addAbstractNum(abstractNum); BigInteger numID = numbering.addNum(abstractNumID); int i = 1; createItem(paragraph, document, numID, run, i, false); createItem(paragraph, document, numID, run, i, true); createItem(paragraph, document, numID, run, i, true); createItem(paragraph, document, numID, run, i, false); createItem(paragraph, document, numID, run, i, true); paragraph = document.createParagraph(); run = paragraph.createRun(); String filename = "c:/test/test.docx"; FileOutputStream out = new FileOutputStream(filename); document.write(out); System.out.println(filename + " has been written successully"); } public static void createItem(XWPFParagraph paragraph, XWPFDocument document, BigInteger numID, XWPFRun run, int index, boolean isSub) { String text = "Main item "; paragraph = document.createParagraph(); paragraph.setNumID(numID); if (isSub) { text = "Sub item "; paragraph.getCTP().getPPr().getNumPr().addNewIlvl().setVal(BigInteger.valueOf(1)); } run = paragraph.createRun(); if (isSub) { run.setText(text + subIndex++); } else { run.setText(text + mainIndex++); } }}
pls share the code, this is word processing not this videos code
Nice Tutorial!
Please send the link of the code
Create a normal java project then convert to maven project. Replace pom.xml
4.0.0
WordDemo
WordDemo
0.0.1-SNAPSHOT
org.apache.poi
poi-ooxml
4.1.0
src
maven-compiler-plugin
3.3
1.8
1.8
Here's the code:
package tip.javaee;
import java.io.FileOutputStream;
import java.math.BigInteger;
import org.apache.poi.xwpf.usermodel.XWPFAbstractNum;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFNumbering;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTAbstractNum;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNumbering;
public class MultiLevelNumbering {
private static int subIndex = 1;
private static int mainIndex = 1;
public static void main(String[] args) throws Exception {
StringBuilder xml = new StringBuilder();
xml.append(
"");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(
" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append(" ");
xml.append("");
XWPFDocument document = new XWPFDocument();
XWPFParagraph paragraph = document.createParagraph();
XWPFRun run = paragraph.createRun();
CTNumbering cTNumbering = CTNumbering.Factory.parse(xml.toString());
CTAbstractNum cTAbstractNum = cTNumbering.getAbstractNumArray(0);
XWPFAbstractNum abstractNum = new XWPFAbstractNum(cTAbstractNum);
XWPFNumbering numbering = document.createNumbering();
BigInteger abstractNumID = numbering.addAbstractNum(abstractNum);
BigInteger numID = numbering.addNum(abstractNumID);
int i = 1;
createItem(paragraph, document, numID, run, i, false);
createItem(paragraph, document, numID, run, i, true);
createItem(paragraph, document, numID, run, i, true);
createItem(paragraph, document, numID, run, i, false);
createItem(paragraph, document, numID, run, i, true);
paragraph = document.createParagraph();
run = paragraph.createRun();
String filename = "c:/test/test.docx";
FileOutputStream out = new FileOutputStream(filename);
document.write(out);
System.out.println(filename + " has been written successully");
}
public static void createItem(XWPFParagraph paragraph, XWPFDocument document, BigInteger numID, XWPFRun run,
int index, boolean isSub) {
String text = "Main item ";
paragraph = document.createParagraph();
paragraph.setNumID(numID);
if (isSub) {
text = "Sub item ";
paragraph.getCTP().getPPr().getNumPr().addNewIlvl().setVal(BigInteger.valueOf(1));
}
run = paragraph.createRun();
if (isSub) {
run.setText(text + subIndex++);
} else {
run.setText(text + mainIndex++);
}
}
}
pls share the code, this is word processing not this videos code