android开发 将查询出来的数据导出为Excel

搁浅回忆_2013 2014-04-17 11:25:40
android开发中怎么将查询出来的数据插入到Excel表中,最好有源码。哪位大神帮帮忙
...全文
1002 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
  • 打赏
  • 举报
回复
lz也可以尝试保存成csv文件
gareth_liao 2014-04-17
  • 打赏
  • 举报
回复
保存文件内容的时候, 字段通过 \t 分开。就可以在Excel下面用啦。
gareth_liao 2014-04-17
  • 打赏
  • 举报
回复
啊。 还要源码啊。 给思路不行吗?
十三邵 2014-04-17
  • 打赏
  • 举报
回复
package com.neusoft.avnc.zzyc.zzyc_rest_test; import java.io.File; import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Semaphore; import jxl.Cell; import jxl.CellType; import jxl.DateCell; import jxl.NumberCell; import jxl.Sheet; import jxl.Workbook; import jxl.write.Label; import jxl.write.WritableSheet; import jxl.write.WritableWorkbook; /* * 解析excel,并且封装为bean,存入数据库 */ public class WriteToExcel { // list存放数据, filename是excel存放的路径以及名称 public static void ExportExcel(List<ExcelParameterBean> list, String filename) { try { WritableWorkbook book = Workbook.createWorkbook(new File( "F:\\write.xls")); WritableSheet sheet = book.createSheet("sheet1", 0); // 添加表头, 第一个参数是列,第二个是行 Label label1 = new Label(0, 0, "id"); // 第一列第一行 Label label2 = new Label(1, 0, "comand"); // 第二列第一行 Label label3 = new Label(2, 0, "request"); // 第二列第一行 Label label4 = new Label(3, 0, "exresponse"); // 第二列第一行 Label label5 = new Label(4, 0, "response"); // 第二列第一行 Label label6 = new Label(5, 0, "checkResult"); // 第二列第一行 Label label7 = new Label(6, 0, "RequestNum"); // 第二列第一行 Label label8 = new Label(7, 0, "ConcurrentNum"); // 第二列第一行 Label label9 = new Label(8, 0, "ResponseTime"); // 第二列第一行 Label label10 = new Label(9, 0, "Minprocesstime"); // 第二列第一行 Label label11 = new Label(10, 0, "Maxprocesstime"); // 第二列第一行 Label label12 = new Label(11, 0, "Processability"); // 第二列第一行 Label label13 = new Label(12, 0, "WrongNum"); // 第二列第一行 Label label14 = new Label(13, 0, "Url"); // 第二列第一行 // 添加到sheet1中 sheet.addCell(label1); sheet.addCell(label2); sheet.addCell(label3); sheet.addCell(label4); sheet.addCell(label5); sheet.addCell(label6); sheet.addCell(label7); sheet.addCell(label8); sheet.addCell(label9); sheet.addCell(label10); sheet.addCell(label11); sheet.addCell(label12); sheet.addCell(label13); sheet.addCell(label14); if (list.size() != 0) { Iterator it = list.iterator(); int i = 1; // 表示行 while (it != null && it.hasNext()) { ExcelParameterBean stu = (ExcelParameterBean) it.next(); Label l1 = new Label(0, i, stu.getId()); Label l2 = new Label(1, i, stu.getCommand()); Label l3 = new Label(2, i, stu.getRequest()); Label l4 = new Label(3, i, stu.getExresponse()); Label l5 = new Label(4, i, stu.getResponse()); Label l6 = new Label(5, i, stu.getCheckResult()); Label l7 = new Label(6, i, stu.getRequestNum()); Label l8 = new Label(7, i, stu.getConcurrentNum()); Label l9 = new Label(8, i, stu.getResponseTime()); Label l10 = new Label(9, i, stu.getMinprocesstime()); Label l11 = new Label(10, i, stu.getMaxprocesstime()); Label l12 = new Label(11, i, stu.getProcessability()); Label l13 = new Label(12, i, stu.getWrongNum()); Label l14 = new Label(13, i, stu.getUrl()); sheet.addCell(l1); sheet.addCell(l2); sheet.addCell(l3); sheet.addCell(l4); sheet.addCell(l5); sheet.addCell(l6); sheet.addCell(l7); sheet.addCell(l8); sheet.addCell(l9); sheet.addCell(l10); sheet.addCell(l11); sheet.addCell(l12); sheet.addCell(l13); sheet.addCell(l14); i++; } book.write(); book.close(); } } catch (Exception e) { System.out.println(e.getMessage()); } } } 屌不屌?我做过读取Excel,修改后再输出Excel,要全套代码可以加我QQ631747554
  • 打赏
  • 举报
回复
引用 5 楼 u013064347 的回复:
保存成csv 直接用Excel打开会乱码,要用记事本打开转换一下编码,我要直接能用Excel打开看的。。
改下编码再试试
搁浅回忆_2013 2014-04-17
  • 打赏
  • 举报
回复
引用 4 楼 hjywyj 的回复:
参考
用你的源码 cell.setEncoding(HSSFCell.ENCODING_UTF_16);这句代码编译通不过提示The method setEncoding(short) is undefined for the type HSSFCell
搁浅回忆_2013 2014-04-17
  • 打赏
  • 举报
回复
引用 3 楼 hjywyj 的回复:
lz也可以尝试保存成csv文件
保存成csv 直接用Excel打开会乱码,要用记事本打开转换一下编码,我要直接能用Excel打开看的。。
搁浅回忆_2013 2014-04-17
  • 打赏
  • 举报
回复
保存成csv 直接用Excel打开会乱码,要用记事本打开转换一下编码,我要直接能用Excel打开看的。。

80,354

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧