One way to make sure grid lines are intact is to export to csv instead of using html tags to write out your content.
You also can assign css to your to td elements but the borders will not look like they do natively in excel.
Here is an example of using csv. This is a simplified version of something I used in afterRenderResponse:
var exCon = facesContext.getExternalContext();
var writer = facesContext.getResponseWriter();
var response = exCon.getResponse();
var output = "";
var colHeaders = "col1,col2,col3,col4,col5";
// Loop through data set
while (doc != null) {
output+="\"" + val1 + "\",";
output+="\"" + val2 + "\",";
output+="\"" + val3 + "\",";
output+="\"" + val4 + "\",";
output+="\"" + val5 + "\",";
output += @Char(13)+@Char(10); // start a new row
}
response.setContentType("application/csv-tab-delimited-table;charset=utf-8");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Content-Disposition", "attachment;filename=actionExport.csv");
writer.write(colHeaders+@Char(13)+@Char(10)); // Add the first row as column titles and add line feed
writer.write(output+@Char(13)+@Char(10)); //
writer.endDocument();