jexcelapi 的使用

<result name="dayExcel" type="stream">
	<param name="contentType">application/vnd.ms-excel</param>
	<param name="contentDisposition">filename="export.xls"</param>
	<param name="bufferSize">1024</param>
</result>

 

	InputStream is;

	public String execute() {

		Label label;
		WritableWorkbook workbook;
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		try {
			workbook = Workbook.createWorkbook(os);
			WritableSheet sheet = workbook.createSheet("Sheet1", 0);
			label = new jxl.write.Label(0, 0, "Time/Hour");
			sheet.addCell(label);
			for (int i = 0; i < 24; i++) {
				if (i < 10) {
					label = new jxl.write.Label(0, i+1, "0" + i);
					sheet.addCell(label);
				} else {
					label = new jxl.write.Label(0, i+1, String.valueOf(i));
					sheet.addCell(label);
				}
			}

			workbook.write();
			workbook.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		is = new ByteArrayInputStream(os.toByteArray());
		return "excel";

	}

	public InputStream getIs() {
		return is;
	}

	public void setIs(InputStream is) {
		this.is = is;
	}

	public InputStream getInputStream() throws Exception {
		return is;
	}

 

你可能感兴趣的:(Excel)