当前位置: 首页 > news >正文

民治营销网站嵌入式和网站开发

民治营销网站,嵌入式和网站开发,做eso哪家网站好,网站在百度上搜索不到JExcel API使用笔记 JExcel是一个开源的支持excel的java类库#xff0c;广泛利用其api来生成excel报表 API基本使用 1.创建excel文件 workbook Workbook.createWorkbook(file);//传入file文件2.创建sheet页 WritableSheet sheet workbook.createSheet(记录表广泛利用其api来生成excel报表 API基本使用 1.创建excel文件 workbook Workbook.createWorkbook(file);//传入file文件2.创建sheet页 WritableSheet sheet workbook.createSheet(记录表, 0);//可以调整sheet页的名称与索引3.创建标题栏 创建完sheet页后我们先创建一行标题栏 sheet.addCell(new Label(c, r, fileName, arial14format));//r是行c是列标签内容单元格格式4.设置单元格行高、列宽 sheet.setRowView(0, 340); //设置行高 sheet.setColumnView(0, 45); //设置列宽5.单元格格式设置 //字体设置 arial14font new WritableFont(WritableFont.ARIAL, 14, WritableFont.BOLD);//字体、大小、样式 arial14font.setColour(jxl.format.Colour.LIGHT_BLUE);//字体颜色 arial14format new WritableCellFormat(arial14font); arial14format.setAlignment(jxl.format.Alignment.CENTRE);//居中 arial14format.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);//边界样式 arial14format.setBackground(jxl.format.Colour.VERY_LIGHT_YELLOW);//背景颜色6.添加普通标签 获取到WritableSheet的变量后就能添加单元格了 sheet.addCell(new Label(5, 6, “hello”, arial14format));//在第51列第61行添加一个hello行、列都是从0开始算的 7.添加数字 sheet.addCell(new Number(i, j 1, Integer.parseInt(list.get(i)), arial12format));添加格式化后的数字 NumberFormat nf new NumberFormat(#.##); WritableCellFormat wcfN new WritableCellFormat(nf); Number labelNF new jxl.write.Number(1, 1, 3.1415926, wcfN); ws.addCell(labelNF);8.添加日期 WritableCellFormat dateCellFormat new WritableCellFormat(new DateFormat(yyyy/MM/dd HH:mm:ss)); dateCellFormat.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK); dateCellFormat.setBackground(Colour.AQUA); sheet.addCell(new DateTime(c, r, (Date) list.get(i), dateCellFormat));9.添加链接 WritableHyperlink hyperlink new WritableHyperlink(i, j, new URL(http://baidu.com)); Label issueLink new Label(i, j, http://baidu.com, arial12format); hyperlink.setDescription(issueLink.getContents());sheet.addCell(issueLink); sheet.addHyperlink(hyperlink);10.添加Boolean对象 Boolean labelB new jxl.write.Boolean(0, 2, false); sheet.addCell(labelB);11.添加图片 WritableImage wimage new WritableImage(0, 1, 2, 2, image);//0,1分别代表x,y.2,2代表宽和高占的单元格数 //image文件或byte[] sheet.addImage(wimage);12.将列设置为自适应 CellView cellView sheet.getColumnView(i); cellView.setAutosize(true); sheet.setColumnView(i, cellView);13.写入工作表 writebook.write();14.关闭工作表 writebook.close();15.获取单元格的数据 public static void readExcel(String filePath) {try {InputStream is new FileInputStream(filePath);Workbook rwb Workbook.getWorkbook(is);//Sheet st rwb.getSheet(0)这里有两种方法获取sheet表,1为名字而为下标从0开始Sheet st rwb.getSheet(original);Cell c00 st.getCell(0, 0);//通用的获取cell值的方式,返回字符串String strc00 c00.getContents();//获得cell具体类型值的方式if (c00.getType() CellType.LABEL) {LabelCell labelc00 (LabelCell) c00;strc00 labelc00.getString();}//输出System.out.println(strc00);//关闭rwb.close();} catch (Exception e) {e.printStackTrace();} }根据文件路径打开输入流得到文件内容获取到sheet获取到00的内容判断单元格中数据的格式最后输出。 for (int j 0;jsheet.getColumns();j){StringBuffer sb new StringBuffer();for (int i0;isheet.getRows();i){// 列,行cell sheet.getCell(j, i);sb.append(cell.getContents());// 获取单元格内容sb.append(,);// 将单元格的每行内容用逗号隔开}list.add(sb.toString());//将每行的字符串用一个String类型的集合保存。}循环获取内容添加到集合中。 Android下简单使用 依赖 implementation net.sourceforge.jexcelapi:jxl:2.6.12工具类 import android.content.Context; import android.os.Environment; import android.widget.Toast;import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.ArrayList; import java.util.Date; import java.util.List;import jxl.CellView; import jxl.Workbook; import jxl.WorkbookSettings; import jxl.format.Border; import jxl.format.BorderLineStyle; import jxl.format.Colour; import jxl.write.DateFormat; import jxl.write.DateTime; import jxl.write.Label; import jxl.write.Number; import jxl.write.WritableCell; import jxl.write.WritableCellFormat; import jxl.write.WritableFont; import jxl.write.WritableHyperlink; import jxl.write.WritableSheet; import jxl.write.WritableWorkbook; import jxl.write.WriteException;public class ExcelUtil {public static WritableFont arial14font null;public static WritableCellFormat arial14format null;public static WritableFont arial10font null;public static WritableCellFormat arial10format null;public static WritableFont arial12font null;public static WritableCellFormat arial12format null;public final static String UTF8_ENCODING UTF-8;public final static String GBK_ENCODING GBK;/*** 单元格的格式设置 字体大小 颜色 对齐方式、背景颜色等...*/public static void format() {try {arial14font new WritableFont(WritableFont.ARIAL, 14, WritableFont.BOLD);arial14font.setColour(jxl.format.Colour.LIGHT_BLUE);arial14format new WritableCellFormat(arial14font);arial14format.setAlignment(jxl.format.Alignment.CENTRE);arial14format.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);arial14format.setBackground(jxl.format.Colour.VERY_LIGHT_YELLOW);arial10font new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD);arial10format new WritableCellFormat(arial10font);arial10format.setAlignment(jxl.format.Alignment.CENTRE);arial10format.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);arial10format.setBackground(Colour.GRAY_25);arial12font new WritableFont(WritableFont.ARIAL, 10);arial12format new WritableCellFormat(arial12font);arial12format.setAlignment(jxl.format.Alignment.CENTRE);//对齐格式arial10format.setAlignment(jxl.format.Alignment.CENTRE);//对齐格式arial12format.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); //设置边框} catch (WriteException e) {e.printStackTrace();}}/*** 初始化Excel** param fileName* param colName*/public static void initExcel(String fileName, String[] colName) {format();WritableWorkbook workbook null;try {File file new File(fileName);if (!file.exists()) {file.createNewFile();}workbook Workbook.createWorkbook(file);WritableSheet sheet workbook.createSheet(成绩表, 0);//创建标题栏sheet.addCell((WritableCell) new Label(0, 0, fileName, arial14format));for (int col 0; col colName.length; col) {sheet.addCell(new Label(col, 0, colName[col], arial10format));}sheet.setRowView(0, 340); //设置行高workbook.write();} catch (Exception e) {e.printStackTrace();} finally {if (workbook ! null) {try {workbook.close();} catch (Exception e) {e.printStackTrace();}}}}SuppressWarnings(unchecked)public static T void writeListToExcel(ListT objList, String fileName, Context c) {if (objList ! null objList.size() 0) {WritableWorkbook writebook null;InputStream in null;try {WorkbookSettings setEncode new WorkbookSettings();setEncode.setEncoding(UTF8_ENCODING);in new FileInputStream(new File(fileName));Workbook workbook Workbook.getWorkbook(in);writebook Workbook.createWorkbook(new File(fileName), workbook);WritableSheet sheet writebook.getSheet(0);for (int j 0; j objList.size(); j) {ArrayListObject list (ArrayListObject) objList.get(j);for (int i 0; i list.size(); i) {if (list.get(i) instanceof String) {sheet.addCell(new Label(i, j 1, (String) list.get(i), arial12format));} else if (list.get(i) instanceof Integer) {sheet.addCell(new Number(i, j 1, (Integer) list.get(i), arial12format));} else if (list.get(i) instanceof Double) {sheet.addCell(new Number(i, j 1, (Double) list.get(i), arial12format));} else if (list.get(i) instanceof Date) {WritableCellFormat dateCellFormat new WritableCellFormat(new DateFormat(yyyy/MM/dd HH:mm:ss));dateCellFormat.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK);dateCellFormat.setBackground(Colour.AQUA);sheet.addCell(new DateTime(i, j 1, (Date) list.get(i), dateCellFormat));} else {WritableHyperlink hyperlink new WritableHyperlink(i, j, new URL(http://jira.jd.com/browse/));Label issueLink new Label(i, j, http://jira.jd.com/browse/, arial12format);hyperlink.setDescription(issueLink.getContents());sheet.addCell(issueLink);sheet.addHyperlink(hyperlink);}sheet.setColumnView(i, list.get(i).toString().length() 5); //设置列宽}sheet.setRowView(j 1, 350); //设置行高}expandColumns(sheet, objList.size()); // sheet.addCell(new Label(5, 6, hello, arial14format));//在第7行第6列添加一个hellowritebook.write();Toast.makeText(c, Success, Toast.LENGTH_SHORT).show();} catch (Exception e) {e.printStackTrace();} finally {if (writebook ! null) {try {writebook.close();} catch (Exception e) {e.printStackTrace();}}if (in ! null) {try {in.close();} catch (IOException e) {e.printStackTrace();}}}}}/**** 根据内容调整 列的宽度* param sheet* param columnSize*/private static void expandColumns(WritableSheet sheet, int columnSize) {for (int i 0; i columnSize; i) {CellView cellView sheet.getColumnView(i);cellView.setAutosize(true);sheet.setColumnView(i, cellView);}}public static String getSDPath() {File sdDir null;boolean sdCardExist Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);if (sdCardExist) {sdDir Environment.getExternalStorageDirectory();}String dir sdDir.toString();return dir;}public static void makeDir(File dir) {if (!dir.getParentFile().exists()) {makeDir(dir.getParentFile());}dir.mkdir();}}调用 调用前需要先申请权限次步骤略过 /*** 导出excel*/public void exportExcel1() {String[] title {观音心咒, 百字明, 顶礼, 35佛};File file new File(ExcelUtil.getSDPath() /bluetooth);ExcelUtil.makeDir(file);SimpleDateFormat sdf new SimpleDateFormat(yyyy-MM-dd HH:mm:ss);String time sdf.format(new Date());//Calendar.getInstance().toString();String fileName file.toString() / 20240614 - time 修行量.xls;ExcelUtil.initExcel(fileName, title);ExcelUtil.writeListToExcel(getObjData(), fileName, this);}private ArrayListArrayListObject getObjData() {ArrayListArrayListObject recordList new ArrayList();for (int i 0; i 30; i) {ArrayListObject beanList new ArrayList();beanList.add(里 i);beanList.add(i 外);beanList.add(30 * i);beanList.add(12.23 * i);beanList.add(new Date());beanList.add(1f);recordList.add(beanList);}return recordList;}注意这个工具类是输出excel的读取的excel不能是xlsx格式需要自己转换后才能读。 参考链接 JExcel API使用笔记 java 读取数据库数据生成excel文件 Android Jxl读写Excel Jxl 包下载 Java Excel API 2.6.10 API
http://www.w-s-a.com/news/303325/

相关文章:

  • 建设厅网站查询网页设计好就业吗
  • 惠东县网站建设wordpress 如何回到初始
  • 如何让公司网站网站转备案
  • 获得网站所有关键字北京网站建设116net
  • 铜陵电子商务网站建设做龙之向导网站有用吗
  • 购物网站制作费用沧州新华区
  • 信宜网站设计公司在线购物商城系统
  • 网站维护是什么样如何制作网站教程视频讲解
  • 网站建设网络推广代理公司wordpress图片防盗链
  • 网站备案关站沈阳男科医院哪家好点
  • 王者荣耀网站建设的步骤网站页面用什么软件做
  • 典型网站开发的流程房屋装修效果图三室一厅
  • 制作微网站多少钱阿里巴巴做网站的电话号码
  • 风铃建站模板安卓手机软件开发外包
  • 深圳市住房和建设局门户网站域名转移影响网站访问吗
  • 做母婴网站赚钱汕头百姓网
  • 那个网站建设好动漫制作技术升本可以升什么专业
  • 网站建设企业响应式网站模板广西建设部投诉网站
  • app营销的特点wordpress优化方案
  • 静安网站建设公司如何编辑wordpress
  • 做网站的职位叫什么问题常州金坛网站建设
  • 保健品网站模板用jsp做的网站前后端交互
  • 网站带后台品牌网页设计图片
  • 保定清苑住房和城乡建设局网站分类信息网站程序
  • 可以做视频推广的网站选择大连网站建设
  • 在线网站开发网站在哪里
  • 建站的步骤上海快速优化排名
  • 招聘网站做一下要多少钱网站设计公司 国际
  • 巩义专业网站建设公司首选seo研究院
  • 大流量网站解决访问量友情链接如何添加