`

struts2 poi excel

阅读更多
<action name="link" class="LinkAction">
			<result name="excel" type="stream">
				<param name="contentType">application/vnd.ms-excel</param>
				<param name="contentDisposition">attachment;filename="links.xls"</param>
				<param name="inputName">excelFile</param>
			</result>
		</action>
 
private InputStream excelFile;

public InputStream getExcelFile() {
		return excelFile;
	}

	public void setExcelFile(InputStream excelFile) {
		this.excelFile = excelFile;
	}

public String excel() throws Exception {
		HSSFWorkbook book = new HSSFWorkbook();

		HSSFSheet sheet0 = book.createSheet("01");

		HSSFRow row = sheet0.createRow((short) 0);

		HSSFCell cell = row.createCell(0);

		cell.setCellType(HSSFCell.CELL_TYPE_STRING);

		cell.setCellValue("增加值");

		ByteArrayOutputStream output = new ByteArrayOutputStream();
		book.write(output);

		byte[] ba = output.toByteArray();
		excelFile = new ByteArrayInputStream(ba);

		output.flush();
		output.close();
		return EXCEL;
	}
 
分享到:
评论
1 楼 kchiu 2015-01-08  
你这个写的太简略

相关推荐

Global site tag (gtag.js) - Google Analytics