jsp页面table导入excel数据

jsp页面table导入excel数据,第1张

jsp页面中可以通过动态生成excel的方式把table数据导入并保存。

以下是例子:

public static void crExcel(List list, String absoluteFileString)

throws Exception {

// 字体格式

WritableFont wfc0 = new WritableFont(WritableFont.ARIAL, 22,WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.BLACK)

WritableCellFormat wcfFC0 = new WritableCellFormat(wfc0)

wcfFC0.setAlignment(jxl.format.Alignment.CENTRE)

wcfFC0.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE)

wcfFC0.setBorder(Border.ALL, BorderLineStyle.THIN,jxl.format.Colour.GRAY_25)

// 表头字体

WritableFont wfc8 = new WritableFont(WritableFont.ARIAL, 12,WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.BLACK)

WritableCellFormat wcfFC8 = new WritableCellFormat(wfc8)

wcfFC8.setAlignment(jxl.format.Alignment.CENTRE)

wcfFC8.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE)

wcfFC8.setBorder(Border.ALL, BorderLineStyle.THIN,jxl.format.Colour.GRAY_25)

WritableFont wfc1 = new WritableFont(WritableFont.ARIAL, 10,WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.BLACK)

WritableCellFormat wcfFC1 = new WritableCellFormat(wfc1)

wcfFC1.setAlignment(jxl.format.Alignment.CENTRE)

wcfFC1.setBorder(Border.ALL, BorderLineStyle.THIN,jxl.format.Colour.GRAY_25)

// 创建excel

OutputStream os = new FileOutputStream(absoluteFileString)

String readPath = I18nMessages.getText("efine.excel.dir")

InputStream input = new FileInputStream(readPath

+ "FKBalanceReport.xls")

Workbook workbook = Workbook.getWorkbook(input)

WritableWorkbook book = Workbook.createWorkbook(os, workbook)

WritableSheet sheet = book.getSheet(0)

// 数据写入

Label label = null

// Title

//label = new jxl.write.Label(3, 0, "到期付款信息表", wcfFC0)

//sheet.addCell(label)

/*

* label = new jxl.write.Label(0, 3, "备注", wcfFC4)

* sheet.addCell(label)

*/

label = new jxl.write.Label(0, 0, "到期日", wcfFC8)

sheet.addCell(label)

label = new jxl.write.Label(1, 0, "部门名称", wcfFC8)

sheet.addCell(label)

label = new jxl.write.Label(2, 0, "币种", wcfFC8)

sheet.addCell(label)

label = new jxl.write.Label(3, 0, "银行", wcfFC8)

sheet.addCell(label)

label = new jxl.write.Label(4, 0, "金额", wcfFC8)

sheet.addCell(label)

label = new jxl.write.Label(5, 0, "业务类型", wcfFC8)

sheet.addCell(label)

label = new jxl.write.Label(6, 0, "摘要", wcfFC8)

sheet.addCell(label)

sheet.setName("到期付款信息查询")

int j = 1

for (int i = 0i <list.size()i++) {

DNCM02 dto = (DNCM02) list.get(i)

label = new Label(0, i + j, CommonUtil.dateToStr(dto.getEndDay()),

wcfFC1)

sheet.addCell(label)

label = new Label(1, i + j, dto.getEndDeptName(), wcfFC1)

sheet.addCell(label)

label = new Label(2, i + j, dto.getCurrencyName(), wcfFC1)

sheet.addCell(label)

label = new Label(3, i + j, dto.getEndBankName(), wcfFC1)

sheet.addCell(label)

label = new Label(4, i + j, CommonUtil.formatString(dto

.getEndAmount().toString()), wcfFC1)

sheet.addCell(label)

label = new Label(5, i + j, dto.getEndTypeName(), wcfFC1)

sheet.addCell(label)

label = new Label(6, i + j, dto.getRemark(), wcfFC1)

sheet.addCell(label)

}

book.write()

book.close()

os.close()

}

然后指定excel的保存路径即可。

这些值是填到了表单里的,

点保存就相当于提交表单的submin那个东西

提交到用于计算和保存的jsp页面之后,那个页面接收表单传过来的值,然后计算得出结果。

剩下的就是jsp的数据库 *** 作部分了。获取数据库连接,创建语句对象,执行sql语句,返回结果。

JSP页面中用c标签遍历list,要显示数据的对象列表放到list中。

java代码:

1

request.setAttribute("list", yourList)

jsp代码:

<c:forEach var="user" items="${list}"> User Name: ${user.username}Age: ${user.age}</c:forEach>

注意在JSP中引入jstl的core标签,


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/10871530.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-11
下一篇 2023-05-11

发表评论

登录后才能评论

评论列表(0条)

保存