以下是例子:
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的保存路径即可。
function AllAreaExcel(){var oXL = new ActiveXObject("Excel.Application")
var oWB = oXL.Workbooks.Add()
var oSheet = oWB.ActiveSheet
var sel=document.body.createTextRange()
sel.moveToElementText(export)
sel.select()
sel.execCommand("Copy")
oSheet.Paste()
oXL.Visible = true
}
<input type="button" value="表格导入excel" onclick="AllAreaExcel()">
<table id="export"><tr><td></td></tr></table>
测试的时候把ie的安全中心设置下~允许脚本运行和加载
满意请采纳。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)