Java action execl is complex. For example, if you need a sophisticated format and multiple sheet tables, there is no perfect solution. Save the execl file as XML, then it is a good solution to operate execl like a text file!
However, during the specific operation, the file content saved after being edited in Java is exactly the same as that saved in execl, but it cannot be opened by execl, execl transfer to the XML in eclipse to view the UTF-8 format, Java generated XML file opened with a common text editor without garbled, but in eclipse garbled phenomenon, it should be the encoding of XML files generated by Java!
At first, filewriter could not control the format of the saved file. Instead, it used outputstreamwriter to solve the problem.
Configuration config = FreeMarkerUtil.getConfiguration(TestSaveAs.class, "template");Template template = config.getTemplate("test.xml");File file = new File("c:\\test.xml");Map root = new HashMap();Writer writer = new FileWriter(file);template.process(root, writer);writer.flush();writer.close();
Final code:
Configuration config = FreeMarkerUtil.getConfiguration(TestSaveAs.class, "template");Template template = config.getTemplate("test.xml");File file = new File("c:\\test.xml");Map root = new HashMap();Writer writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); template.process(root, writer);writer.flush();writer.close();