Currently, the developed system uses freemarker to export the image content to Word documents.
The newline \ n is invalid and becomes a space.
First of all, I suspect there is a problem with writing a Word file in Java. I tried the following code and it is normal.
File OUTFILE = new file ("D:/mine.doc ");
Writer out1 = NULL;
Try {
Out1 = new bufferedwriter (New outputstreamwriter (
New fileoutputstream (OUTFILE), "UTF-8 "));
Out1.write ("test1 \ r \ ntest2 ");
Out1.close ();
} Catch (exception e ){
E. printstacktrace ();
}
After reading the freemarker source code for half a day, there is no result.
Later I found that the table is used in the template file. Is this a problem. Sure enough.
The line break (\ r \ n) will be output as a space in the table of the word, but it will be normally displayed in a common word file.
Therefore, \ n is replaced for fields that may wrap in the template file. (It's a bit earthy, but there's no other good way. It's been around for a long time .)
<W: p wsp: rsidr = "003f5617" WSP: rsidrpr = "003f5617" WSP: rsidrdefault = "003f5617" WSP: rsidp = "003f5617">
<W: PPR>
<W: jc w: val = "Left"/>
<W: RPR>
<W: rfonts W: ASCII = "simsun" W: H-ANSI = "simsun"/>
<Wx: font wx: val = "simsun"/>
<W: sz w: val = "22"/>
</W: RPR>
</W: PPR>
<W: r wsp: rsidrpr = "003f5617">
<W: RPR>
<W: rfonts W: ASCII = "simsun" W: H-ANSI = "simsun"/>
<Wx: font wx: val = "simsun"/>
<W: B/>
<W: sz w: val = "22"/>
</W: RPR>
<W: T> responsibility Description: </W: T>
</W: r>
<W: r wsp: rsidr = "004b3f82">
<W: RPR>
<W: rfonts W: ASCII = "simsun" W: Fareast = "" W: H-ANSI = "simsun" W: hint = "Fareast"/>
<Wx: font wx: val = "simsun"/>
<W: sz w: val = "22"/>
</W: RPR>
<W: T >$ {ex. Responsibility? Replace ("\ n", "</W: T> </W: r> </W: P> <W: PPR> <W: RPR> <W: rfonts W: ASCII = \ "simsun \" W: Fareast = \ "\" W: H-ANSI = \ "simsun \" W: hint = \ "Fareast \"/> <wx: font wx: val = \ "simsun \"/> <W: sz w: val = \ "22 \"/> </W: RPR> </W: PPR> <W: r> <W: RPR> <W: rfonts W: ASCII = \ "simsun \"
W: Fareast = \ "\" W: H-ANSI = \ "simsun \" W: hint = \ "Fareast \"/> <wx: font wx: val = \ "simsun \"/> <W: sz w: val = \ "22 \"/> </W: RPR> <W: T> ")} </W: T>
</W: r>
</W: P>
I tried it in office2003 and 2007. OK ~!