Hello everyone,
I want some data to come up in an Excel file from a servlet.The data includes +ve & -ve numbers.While exporting from
servlet i need to set the -ve numbers in red colour.I heard its possible. Anybody plz help me ...
i am not using any java-excel apis.
hre i am attaching the code also....
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
BufferedInputStream fileInputStream = null;
ServletOutputStream out = null;
// Read a file from the file system and stream it to the browser.
try {
out = resp.getOutputStream ();
}catch(IOException e) {}
// Set the output data's mime type based on the document's extension.
//resp.setContentType( "application/x-msexcel" ); // MIME type for EXCEL
doc //resp.setContentType( "application/vnd.ms-excel");
try {
// Use Buffered Stream for reading/writing.
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
// Read in a request parameter to determine if the file is on the file system
// or created on the fly.
String fileName = req.getParameter("file");
if (fileName.equals("xls") {
//get formatted output from session and then clear it from session
String outputDocument = (String) req.getSession().getAttribute("exportString");
String exportFileName = null;
if (fileName.equals("xls")) {
resp.setContentType( "application/vnd.ms-excel");
exportFileName = "export.xls";
}
resp.setHeader("Content-disposition","attachment; " + // For launching in a separate window."filename=" +exportFileName);
bis = new BufferedInputStream(new ByteArrayInputStream(outputDocument.getBytes()));
}
bos = new BufferedOutputStream(out);
byte[] buff = new byte[2048];
int bytesRead;
// Simple read/write loop.
while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
System.out.println("Writing byte by byte");
bos.flush();
}
} catch(Exception e) {}
finally {
// Close the input stream.
if (fileInputStream != null)
try {
fileInputStream.close();
}
catch (IOException e) {/* Can't do much. */e.printStackTrac(); }
}
WHOLE DATA IS THR IN "outputdocument".It is an arraylist..It contains -ve numbers also..I need to display tht numbers in red colour in the xls file
HERE EXPORTING PART IS WORKING FINE.BUT I DON'T KNOW HOW TO SET THE COLOUR.