WordTemplate Class open setLocale setDataSource process save |
WordTemplate.open Method |
open(java.lang.String templateFileName)
Opens a WordWriter template specified by file name.
|
open(java.io.InputStream templateStream)
Opens a WordWriter template from a java.io.InputStream
|
public void open
(java.lang.String templateFileName)
Opens the WordWriter template specified by the templateFileName
parameter. A WordWriter template is a file created in Microsoft Word that contains
merge fields.
WordWriter supports Microsoft Word 97, 2000, and 2002 (XP). Do not
use open
to open files created in earlier versions of
Microsoft Word.
templateFileName
open
will throw this exception if templateFileName
specifies an invalid path or if access to the file is denied.open
will throw this exception if templateFileName
is null
or an empty string.open
will throw this exception if the file specified by
templateFileName
is not a valid WordWriter template,
or if another error occurs. ...
oWW = new WordTemplate();
ServletContext ctx = this.getServletContext();
oWW.open(ctx.getRealPath("/WordWriterTemplates/Template1.doc"));
oWW.setDataSource(arrValue, arrName);
oWW.process();
oWW.save(response, "Output.doc", true);
...
public void open
(java.io.InputStream templateStream)
Opens a WordWriter template from a
java.io.InputStream
. A WordWriter
template is a file created in Microsoft Word that contains merge fields.
WordWriter supports Microsoft Word 97, 2000, and 2002 (XP). Do not
use open
to open files created in earlier versions of
Microsoft Word.
templateStream
java.io.InputStream
that represents
the template file.open
will throw this exception if templateStream
is null
.open
will throw this exception if the InputStream
does not contain a valid WordWriter template, or if another error occurs. ...
//--- Path to the template file, relative to the Servlet context root.
String templateFile = "/Basic/StreamIO/StreamIOTemplate.doc";
//--- Path to the system temp directory, where output files will be stored
//--- Append either a / or \ to the end to make it a directory path
String tmpdir = System.getProperty("java.io.tmpdir");
if(!tmpdir.endsWith(File.separator))
tmpdir += File.separator;
WordTemplate oWW = null;
InputStream iStream = null;
FileOutputStream outputfstream = null;
...
outputfstream = new FileOutputStream(tmpdir + "StreamIOOutput.doc");
oWW = new WordTemplate();
iStream = new BufferedInputStream(application.getResourceAsStream(templateFile));
oWW.open(iStream);
oWW.setDataSource(arrValue, arrName);
oWW.process();
oWW.save(outputfstream);
...
WordTemplate Class open setLocale setDataSource process save |