Apache POI - how to create new and read Microsoft Excel Document with Eclipse

  Рет қаралды 3,357

JavaEE Tips

JavaEE Tips

Күн бұрын

Пікірлер: 4
@helinchooi6741
@helinchooi6741 5 жыл бұрын
Nice Tutorial!
@iremsaltoglu5998
@iremsaltoglu5998 4 жыл бұрын
pls share the code, this is word processing not this videos code
@b.o.t7888
@b.o.t7888 5 жыл бұрын
Please send the link of the code
@javaeetips868
@javaeetips868 5 жыл бұрын
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++); } } }
Introduction to Apache POI | Selenium WebDriver |
9:53
H Y R Tutorials
Рет қаралды 37 М.
Thank you Santa
00:13
Nadir Show
Рет қаралды 52 МЛН
小路飞和小丑也太帅了#家庭#搞笑 #funny #小丑 #cosplay
00:13
家庭搞笑日记
Рет қаралды 11 МЛН
Миллионер | 3 - серия
36:09
Million Show
Рет қаралды 2,2 МЛН
JSP/Servlet Profesional - Part 12 Apache POI Export  to excel
7:54
Learn to generate Excel XLSX files in Java with Eclipse
11:33
Sylvain Saurel
Рет қаралды 58 М.
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 92 МЛН
Read an Excel XLSX file in java with Eclipse
9:37
Slash Code
Рет қаралды 46 М.
How To Create and Run Maven Project with Eclipse and CommandLine | Step by Step
16:27
How To Read and Write Excel data in java using Apache POI
23:32
ProTechBeach
Рет қаралды 31 М.
Solving one of PostgreSQL's biggest weaknesses.
17:12
Dreams of Code
Рет қаралды 216 М.
Thank you Santa
00:13
Nadir Show
Рет қаралды 52 МЛН