Winter Vacation record 13_ export word document

I exported word document from javaweb project was learning.

Export data to form a word document There are many ways, I am learning how to use the Apache POI to export data to a Word document.

Summarized as follows:

① create a word document, use $ {XXX} on the inside instead of the content they want to write. By the time the code can be substituted for the content.

② in the code above to access the database contents can be replaced by. If it is a lot of content, it can be derived by using a loop form.

The key code is as follows:

package hotWords.dao;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.sql.SQLException;
import hotWords.bean.Explain;
public class PrintWord {
public void word() throws ClassNotFoundException, SQLException {
LoadDaoImpl loadDaoImpl=new LoadDaoImpl();
List<Explain> explains=null;
explains=loadDaoImpl.load();
String title = "热词解释文档";
Map<String,Object> map = new HashMap<String,Object>();
map.put("title", title);
List<Map<String,String>> excelMapList = new ArrayList<Map<String,String>>();
Map<String,String> excelMapTemp = null;
printStackTrace (); }





















try {
export.export(map);
export.export(excelMapList,0);
export.generate(targetPath);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Guess you like

Origin www.cnblogs.com/ruangongyouxi/p/12310242.html