导出数据到excel
来源:互联网 发布:淘宝代理软件是什么 编辑:程序博客网 时间:2024/06/05 06:26
/** * * @param datas数据行 * @param filePath导出文件路径 * @param title标题 * @return */public boolean ListArray2Excel(List<String[]> datas, String filePath,String[] title) {boolean flag = false;WritableWorkbook workbook = null;WritableSheet sheet = null;Label label = null;// 创建Excel表try {workbook = Workbook.createWorkbook(new File(filePath));// 创建Excel表中的sheetsheet = workbook.createSheet("seo_url", 0);// 向Excel中添加数据int row = 0;// 添加标题for (int i = 0; i < title.length; i++) {label = new Label(i, row, title[i]);sheet.addCell(label);}row++;for (String[] data : datas) {for (int i = 0; i < data.length; i++) {for (int j = 0; j < title.length; j++) {label = new Label(i, row, data[i]);sheet.addCell(label);}}row++;}// 关闭文件workbook.write();workbook.close();workbook = null;flag = true;} catch (RowsExceededException e) {} catch (WriteException e) {} catch (IOException e) {} finally {try {workbook.close();} catch (Exception e) {}}return flag;}
测试:
/** * 测试方法 * * @param args */public static void main(String[] args) {//List<String[]> data = new ArrayList<String[]>();String[] strArray = { "铜", "http://www.baidu.com" };String[] strArray2 = { "紫铜", "http://www.guge.com" };data.add(strArray);data.add(strArray2);try {String[] title = { "词名", "url" };if (!new ExcelUtil().ListArray2Excel(data,"d:/test/" + System.currentTimeMillis() + ".xls", title)) {System.out.println("数据写入失败");}} catch (Exception e) {e.printStackTrace();}}
0 0
- 数据导出到Excel
- 数据导出到Excel
- 导出数据到EXCEL
- 导出数据到Excel
- 导出数据到EXCEL
- 导出数据到excel
- 导出数据到Excel
- 导出数据到excel
- 数据导出到excel
- 导入excel数据,导出数据到excel
- 导出数据到Excel概述
- 导出数据到Excel概述
- 导出数据到Excel概述
- VB导出数据到excel
- datagrid数据导出到excel
- c#导出数据到Excel
- js导出数据到excel
- js导出数据到excel
- JSON与XML的区别比较
- java.lang.NoSuchMethodError: org.apache.axiom.soap.SOAPEnvelope.hasFault()Z错误的解决
- APP推送通知相关实现
- MATLAB——scatter的简单应用
- Android handler(工具类)弱引用 WeakReference
- 导出数据到excel
- Solr入门
- java监听器+quartz实现每天动态时间执行任务的功能
- 预制件的问题
- Android 影藏和打开软键盘
- 使用maven构建基本的web项目结构
- easyui treegrud 无法识别state
- Linux基础命令-find常见用法示例
- Spring的事务管理