import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; fileName=yourFileName.xls");
ServletOutputStream out = response.getOutputStream();
StringBuilder writer = new StringBuilder();
HSSFWorkbook book = new HSSFWorkbook();
HSSFFont bold = book.createFont();
bold.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
HSSFFont blue = book.createFont();
blue.setColor(HSSFColor.BLUE.index);
HSSFRow row;
HSSFRichTextString name;
HSSFRichTextString value;
HSSFSheet summary = book.createSheet("Summary");
summary.setColumnWidth(0, 7000);
summary.setColumnWidth(1, 20000);
row = summary.createRow(0);
name = new HSSFRichTextString("Subject:");
value = new HSSFRichTextString("your subject");
name.applyFont(bold);
value.applyFont(blue);
row.createCell(0).setCellValue(name);
row.createCell(1).setCellValue(value);
row = summary.createRow(1);
name = new HSSFRichTextString("second row:");
value = new HSSFRichTextString("your content");
name.applyFont(bold);
value.applyFont(blue);
row.createCell(0).setCellValue(name);
row.createCell(1).setCellValue(value);
OutputStream out = response.getOutputStream();
book.write(out);
out.flush();
out.close();
Comments
Post a Comment