Ok, I've checked this SO question, but it has not helped me at all.
I need to get a csv file to a user, so they can export it into PeopleSoft. One of the fields (batch_id) has to be 4 digits exactly, and currently Excel keeps dropping those leading zeroes. I've also opened the csv file in TextPad and verified that those zeroes are gone.
So heres the process:
Browser is pointed to myapp/Batch/course as shown below:
@GET
@Path( "Batch/{course}" )
@Produces( "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" )
@HttpHeader( values="Content-Disposition=attachment;filename=Batch.csv" )
public String getNextBatch ( @PathParam( "course" ) String course )
{
...
}
Within that method, an Oracle database is queried and gets data sent back as XML (In the XML, batch_id has the correct number of digits). That XML is then processed into one long comma separated String via StringBuffer.append(), which the method then returns. The @Produces attribute takes that String and makes sure Excel handles it, and the file is downloaded.
I can get it to appear as 4 digits by appending tabs after each comma, but then it bombs when its loaded into PeopleSoft. I can also get it to appear with the correct 4 digits if I single quote it (either a single leading quote, or quoting the entire batch_id), but again theres the problem of the PeopleSoft upload.
More info: I'm appending the data as such (but in a loop):
NodeList participants = XmlUtil.selectNodeList( doc, "Batch/row" );
buffer.append( "\t" + item.getAttribute( "batchid" ) );
Does anyone have any idea how to get Excel to behave correctly?
Edit: I marked a solution, because in any other case it would work. Trying to spit out the data to Excel like I am now is just a kludge, so I'm just going to rewrite it a different way.