Ok, I think I managed to figure it out without anyone helping (thanks guys!). Nice guy that I am, I thought I'd post my solution for everyone's edificiation, and also to see if anyone can see any pitfalls to the way I'm doing this. There's obviously some optimizations and better naming I could do - this was just proof-of-concept that it could be done. Let me know what you think! Here it is in
servlet form:
String templateFileLocation = "C:\\template.xls";
res.setContentType("application/vnd.ms-excel");
try {
ServletOutputStream outStream = res.getOutputStream();
File inputFile = new File( templateFileLocation );
FileInputStream in = new FileInputStream(inputFile);
byte result[];
result = new byte[in.available()];
in.read(result);
in.close();
String temp = new String(result);
int location = temp.indexOf("R22");
String x = temp.substring( location, location + 3 );
String replacement = "XYZ";
byte replacementBytes[] = replacement.getBytes();
result[location] = replacementBytes[0];
result[location + 1] = replacementBytes[1];
result[location + 2] = replacementBytes[2];
outStream.write(result);
// Close the writer; the response is done.
outStream.close();
}
catch(IOException e) { System.out.println("Uhoh"); }