Map.put ("Year", year);
Map.put ("Yearmonthday", yearmonthday);
Map.put ("Month", month);
Map.put ("Xun", Xun);
Map.put ("Lastmonth", lastmonth);
Map.put ("Lastxun", Lastxun);
Map.put ("Dwavgtemp", dwavgtemp);
Map.put ("Dwhistorytemp", dwhistorytemp);
Map.put ("Dwhistoryrain", Dwhistoryrain);
Map.put ("Psavgtemp", psavgtemp);
Map.put ("Pshistorytemp", pshistorytemp);
Map.put ("Pshistoryrain", Pshistoryrain);
Map.put ("Maxtemp", maxtemp);
Map.put ("Mintemp", mintemp);
Map.put ("SiteName", siteName);
Map.put ("SiteName2", siteName2);
/**
* Start replacing Word data
* Map to be replaced @param map
* @throws Exception
*/
private void Write (Map<string,string> Map) throws Exception {
String TemplatePath = "d:\\ Interim weather forecast. doc";
String Outpath = "D:\\write.doc";
String fileName = "Write.doc";
try {
FileInputStream fis = new FileInputStream (new File (TemplatePath));
Hwpfdocument doc = new hwpfdocument (FIS);
Range Bodyrange = Doc.getrange ();
For (map.entry<string, string> entry:map.entrySet ()) {
String key = Entry.getkey ();
String value = Entry.getvalue ();
Bodyrange.replacetext ("${" + Key + "}", value);
}
Bytearrayoutputstream ostream = new Bytearrayoutputstream ();
try{
Doc.write (ostream);
}catch (Exception ex) {
Ex.printstacktrace ();
}
OutputStream outs=new FileOutputStream (Outpath);
Outs.write (Ostream.tobytearray ());
Outs.close ();
Fis.close ();
} catch (Exception e) {
E.printstacktrace ();
}
}
Java Replacement word2003