I am trying to create a word document using apache POI but I am getting noclassdeffound error I have done so far this:
import java.io.File;
import java.io.FileOutputStream;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
public class DocFile {
public void newWordDoc(String filename, String fileContent)
throws Exception {
XWPFDocument document = new XWPFDocument();
XWPFParagraph tmpParagraph = document.createParagraph();
XWPFRun tmpRun = tmpParagraph.createRun();
tmpRun.setText(fileContent);
tmpRun.setFontSize(18);
FileOutputStream fos = new FileOutputStream(new File("C:\\"+filename + ".doc"));
document.write(fos);
fos.close();
}
public static void main(String[] args) throws Exception {
DocFile app = new DocFile();
app.newWordDoc("testfile", "Hi hw r u?");
}
}
XWPFDocument doc = new XWPFDocument();
XWPFParagraph paragraph = doc.createParagraph();
XWPFRun tmpRun = paragraph.createRun();
String folder = "E:/New folder/";
String filename = "newDocx.docx";
File f = new File(filename);
FileOutputStream out = new FileOutputStream(new File(folder + filename));
doc.write(out);
System.out.println("_ok");
doc.close();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.