Java Replacement word2003

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.