标签:tin ppt nbsp windows static tla 成功 hot arraylist
1.Echarts:
demo.js:
function demo(selector){ var myEcharts=echarts.init(selector); var option = { title : { text: ‘某站点用户访问来源‘, subtext: ‘纯属虚构‘, x:‘center‘ }, tooltip : { trigger: ‘item‘, formatter: "{a} <br/>{b} : {c} ({d}%)" }, legend: { orient: ‘vertical‘, left: ‘left‘, data: [‘直接访问‘,‘邮件营销‘,‘联盟广告‘,‘视频广告‘,‘搜索引擎‘] }, series : [ { name: ‘访问来源‘, type: ‘pie‘, radius : ‘55%‘, center: [‘50%‘, ‘60%‘], data:[ {value:335, name:‘直接访问‘}, {value:310, name:‘邮件营销‘}, {value:234, name:‘联盟广告‘}, {value:135, name:‘视频广告‘}, {value:1548, name:‘搜索引擎‘} ], itemStyle: { emphasis: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: ‘rgba(0, 0, 0, 0.5)‘ } } } ] }; myEcharts.setOption(option); }
echarts.html:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"></meta> <title></title> <script type="text/javascript" src="echarts.common.min.js"></script> <script type="text/javascript" src="demo.js"></script> <script type="text/javascript"> function test(){ demo(document.getElementById("d")); } </script> </head> <body> <input type="button" id="test" value="测试" onclick="test()"/> <div id="d" style="border:1px; height:500px; width:500px"></div> </body> </html>
2.POI:
POIDemo1.java:
package com.zzsxt.lee.poi.demo; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; /** * @description 写入并创建xls文档 * @author Seven Lee * @date 2017年11月7日 下午1:41:25 * */ public class POIDemo1 { public static void main(String[] args) { // 指定目标路径和文件名 // windows的路径和linux以及mac的路径是不一样 // C:\\test\test.xls // 一般情况下可以使用File.separator-->\,/ File file = new File("D:/123/kuang.xls"); try { // 创建输出流(写入本地磁盘) OutputStream outputStream = new FileOutputStream(file); /** * poi提供 */ // 在目标路径创建目标名称的excel文件 // HSSFWorkbook:操作excel表格的 // 通过file的路径信息和文件名称,在目标路径创建出目标名称的excel文件 HSSFWorkbook workBook = new HSSFWorkbook(); // 创建excel工作表,并创建该工作页的主题名 // 创建表格的一个工作薄,并起名字为user HSSFSheet sheet = workBook.createSheet("user"); // 从数据库中查询出了数据List<> List<User> userList = new ArrayList<User>(); for (int j = 0; j < 10; j++) { User user = new User("zhangsan" + j, "123456" + j); userList.add(user); } User user = new User(); for (int i = -1; i < userList.size(); i++) { /** * 第一次for循环: * i--> -1 * 第二次循环: * i--> 0 */ // sheet.createRow(i+1):创建第一行 // sheet.createRow(i+1):创建第二行 HSSFRow row = sheet.createRow(i+1); for(int k = 0; k < user.getClass().getDeclaredFields().length; k++) { if(i == -1) { if(k == 0) { continue; } row.createCell(k-1).setCellValue((user.getClass().getDeclaredFields()[k]).getName()); continue; } if(((user.getClass().getDeclaredFields()[k]).getName()).equals("serialVersionUID")) { continue; } Field f = userList.get(i).getClass().getDeclaredFields()[k]; f.setAccessible(true); row.createCell(k-1).setCellValue((String)f.get(userList.get(i))); } } // // 为工作表新增加一行(第一行) // HSSFRow row1 = sheet.createRow(0); // // 在指定的行上增加两个单元格 // row1.createCell(0).setCellValue("name"); // row1.createCell(1).setCellValue("password"); // // // 为工作表新增加一行(第二行) // HSSFRow row2 = sheet.createRow(1); // row2.createCell(0).setCellValue("zhangsan"); // row2.createCell(1).setCellValue("123456"); // 调用输出流把excel表格写入硬盘中 workBook.write(outputStream); // 关闭输出流 outputStream.close(); System.out.println("生成excel成功"); } catch (Exception e) { e.printStackTrace(); } } }
POIDemo2.java:
package com.zzsxt.lee.poi.demo; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.InputStream; import java.lang.reflect.Field; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.POIFSFileSystem; /** * @description 通过java程序来从xls文档中读取出数据 * @author Seven Lee * @date 2017年11月7日 下午3:50:18 * */ public class POIDemo2 { public static void main(String[] args) { try { // 创建输入流,从磁盘中获取该文件的流信息 InputStream inputStream = new FileInputStream("D:/123/kuang.xls"); /** * poi提供 */ // 把从磁盘中读取出的流信息保存进缓冲区 BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream); // 创建POIFSFileSystem,对该文件进行解析 // 对该文件的流进行解析 POIFSFileSystem fileSystem = new POIFSFileSystem(bufferedInputStream); // 从目标路径的目标名称获取excel的文件信息-->通过fileSystem进行获取 HSSFWorkbook hssfWorkbook = new HSSFWorkbook(fileSystem); // 根据工作薄的name获取到目标的excel信息 HSSFSheet sheet = hssfWorkbook.getSheet("user"); User user = new User(); for (int i = 0;; i++) { if (i == 0) { continue; } HSSFRow row = sheet.getRow(i);// 获取行信息 if (row != null) { // 需要把所有的数据从excel中取出来 // getLastCellNum():excel表中有效单元格的列数 for (int j = 0; j < row.getLastCellNum(); j++) { String excelValue = row.getCell(j).getStringCellValue(); Field[] fields = user.getClass().getDeclaredFields(); fields[j].setAccessible(true); fields[j].set(user, excelValue); } bufferedInputStream.close(); } else { bufferedInputStream.close(); return; } System.out.println(user); } } catch (Exception e) { e.printStackTrace(); } } }
ReadDocFile.java:
package com.zzsxt.lee.poi.demo; import java.io.FileInputStream; import java.io.FileNotFoundException; import org.apache.poi.hwpf.extractor.WordExtractor; public class ReadDocFile { public static String readWord(String pathAndName) { FileInputStream in; String text = null; try { in = new FileInputStream(pathAndName); WordExtractor extractor = new WordExtractor(in); text = extractor.getText(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return text; } }
User.java:
package com.zzsxt.lee.poi.demo; import java.io.Serializable; public class User implements Serializable { private static final long serialVersionUID = 5157419433803033003L; private String name; private String password; public User() { } public User(String name, String password) { this.name = name; this.password = password; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Override public String toString() { return "User [name=" + name + ", password=" + password + "]"; } }
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.zzsxt.lee.poi.demo</groupId> <artifactId>excel_demo</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>excel_demo Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <!-- 操作excel --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.17</version> </dependency> <!-- 操作work和ppt --> <dependency> <groupId>poi</groupId> <artifactId>poi-scratchpad</artifactId> <version>3.1-FINAL</version> </dependency> </dependencies> <build> <finalName>excel_demo</finalName> </build> </project>
标签:tin ppt nbsp windows static tla 成功 hot arraylist
原文地址:http://www.cnblogs.com/kuangzhisen/p/7801008.html