Use POI on Android export word, use POI version 3.14(05 March 2016 - POI 3.14),
use is replaced in the template content to be derived, if the word template in
the form of column number is less than or equal to 6 is replaced each column in
the normal export of, if the form template is greater than 6 columns is derived
from the word can not be opened, do not know what that is? You had encountered
this problem? How to solve it.
code??
public void writeDoc(File demoFile ,File newFile ,Map<String, String>
map)
{
try
{
FileInputStream in = new FileInputStream(demoFile);
HWPFDocument hdt = new HWPFDocument(in);
// Fields fields = hdt.getFields();
// ????word????????
Range range = hdt.getRange();
// System.out.println(range.text());
// ????????????
for(Map.Entry<String, String> entry : map.entrySet())
{
range.replaceText(entry.getKey(),
entry.getValue());
}
ByteArrayOutputStream ostream = new
ByteArrayOutputStream();
FileOutputStream out = new FileOutputStream(newFile,
true);
hdt.write(ostream);
// ??????????
out.write(ostream.toByteArray());
out.close();
ostream.close();
}
catch(IOException e)
{
e.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
}
templet??