1、POI是什么

Apache POI - the Java API for Microsoft Documents,顾名思义,Apache的三方包,用来操作微软office文档的,多数时候用来操作excel,所以这里就以excel方面来说明。

需要引入两个包,maven地址如下(version 3.9):
  1. <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
  2. <dependency>
  3. <groupId>org.apache.poi</groupId>
  4. <artifactId>poi</artifactId>
  5. <version>3.9</version>
  6. </dependency>
  7. <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
  8. <dependency>
  9. <groupId>org.apache.poi</groupId>
  10. <artifactId>poi-ooxml</artifactId>
  11. <version>3.9</version>
  12. </dependency>
13
 
1
  1. <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
2
  1. <dependency>
3
  1.    <groupId>org.apache.poi</groupId>
4
  1.    <artifactId>poi</artifactId>
5
  1.    <version>3.9</version>
6
  1. </dependency>
7
  1.  
8
  1. <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
9
  1. <dependency>
10
  1.    <groupId>org.apache.poi</groupId>
11
  1.    <artifactId>poi-ooxml</artifactId>
12
  1.    <version>3.9</version>
13
  1. </dependency>

POI的组件列表中,针对excel的主要是HSSF和XSSF组件,前者针对97-2007的通用版excel,即后缀xls;后者针对2007或更高版的excel,即后缀xlsx。官方概要如下:
  1. HSSF is the POI Project's pure Java implementation of the Excel '97(-2007) file format.
  2. XSSF is the POI Project's pure Java implementation of the Excel 2007 OOXML (.xlsx) file format.
2
 
1
  1. HSSF is the POI Project's pure Java implementation of the Excel '97(-2007) file format.
2
  1. XSSF is the POI Project's pure Java implementation of the Excel 2007 OOXML (.xlsx) file format.

2、POI核心类

面向对象面向对象,既然如此,自然去找找一些能表示excel中内容的类。

2.1 工作簿 Workbook

创建或维护Excel工作簿的所有类的超接口,Workbook,属于org.apache.poi.ss.usermodel包。其下有两个实现类:
  • HSSFWorkbook : 有读取.xls 格式和写入Microsoft Excel文件的方法。它与微软Office97-2003版本兼容
  • XSSFWorkbook : 有读写Microsoft Excel和OpenOffice的XML文件的格式.xls或.xlsx的方法。它与MS-Office版本2007或更高版本兼容

所以在针对不同版本的excel时,需要对应以上使用不同的Workbook。构造函数中,常用的:

HSSFWorkbook
  1. //直接创建新的
  2. HSSFWorkbook()
  3. //通过输入流创建
  4. HSSFWorkbook(java.io.InputStream s)
5
 
1
  1. //直接创建新的
2
  1. HSSFWorkbook()
3
  1.  
4
  1. //通过输入流创建
5
  1. HSSFWorkbook(java.io.InputStream s)

XSSFWorkbook
  1. //直接创建新的
  2. XSSFWorkbook()
  3. //通过File类创建
  4. XSSFWorkbook(java.io.File file)
  5. //通过输入流创建
  6. XSSFWorkbook(java.io.InputStream is)
8
 
1
  1. //直接创建新的
2
  1. XSSFWorkbook()
3
  1.  
4
  1. //通过File类创建
5
  1. XSSFWorkbook(java.io.File file)
6
  1.  
7
  1. //通过输入流创建
8
  1. XSSFWorkbook(java.io.InputStream is)

2.2 标签页 Sheet

HSSFSheet 和 XSSFSheet 都是Sheet接口的实现类,Sheet可以使用Workbook的两个方法获得:
  1. workbook.createSheet();
  2. workbook.createSheet(String sheetName);
2
 
1
  1. workbook.createSheet();
2
  1. workbook.createSheet(String sheetName);

2.3 行 Row

同理,Row是 HSSFRow 和 XSSFRow 的接口,通过Sheet获取:
  1. sheet.createRow(int rownum);
1
 
1
  1. sheet.createRow(int rownum);

2.4 单元格 Cell

同理,Cell是 HSSFCell 和 XSSFCell 的接口,通过Row获取:
  1. row.createCell(int column);
  2. row.createCell(int column, int type);
2
 
1
  1. row.createCell(int column);
2
  1. row.createCell(int column, int type);

3、创建和读取

其实如果能理解面向对象,就很简单了,另外包括字体,公式,超链接等,都有对应的封装类,此处只提出了核心的几个,需要了解更多的需要自行展开。

例子的话,直接从别人教程里摘出来吧,另,读取的workbook,可以debug瞅瞅内容。

3.1 创建空白工作簿

  1. import java.io.*;
  2. import org.apache.poi.xssf.usermodel.*;
  3. public class CreateWorkBook
  4. {
  5. public static void main(String[] args)throws Exception
  6. {
  7. //Create Blank workbook
  8. XSSFWorkbook workbook = new XSSFWorkbook();
  9. //Create file system using specific name
  10. FileOutputStream out = new FileOutputStream(
  11. new File("createworkbook.xlsx"));
  12. //write operation workbook using file out object
  13. workbook.write(out);
  14. out.close();
  15. System.out.println("
  16. createworkbook.xlsx written successfully");
  17. }
  18. }
18
 
1
  1. import java.io.*;
2
  1. import org.apache.poi.xssf.usermodel.*;
3
  1. public class CreateWorkBook
4
  1. {
5
  1.   public static void main(String[] args)throws Exception
6
  1.   {
7
  1.      //Create Blank workbook
8
  1.      XSSFWorkbook workbook = new XSSFWorkbook();
9
  1.      //Create file system using specific name
10
  1.      FileOutputStream out = new FileOutputStream(
11
  1.      new File("createworkbook.xlsx"));
12
  1.      //write operation workbook using file out object
13
  1.      workbook.write(out);
14
  1.      out.close();
15
  1.      System.out.println("
16
  1.      createworkbook.xlsx written successfully");
17
  1.   }
18
  1. }

3.2 打开现有的工作簿

  1. import java.io.*;
  2. import org.apache.poi.xssf.usermodel.*;
  3. public class OpenWorkBook
  4. {
  5. public static void main(String args[])throws Exception
  6. {
  7. File file = new File("openworkbook.xlsx");
  8. FileInputStream fIP = new FileInputStream(file);
  9. //Get the workbook instance for XLSX file
  10. XSSFWorkbook workbook = new XSSFWorkbook(fIP);
  11. if(file.isFile() && file.exists())
  12. {
  13. System.out.println(
  14. "openworkbook.xlsx file open successfully.");
  15. }
  16. else
  17. {
  18. System.out.println(
  19. "Error to open openworkbook.xlsx file.");
  20. }
  21. }
  22. }
22
 
1
  1. import java.io.*;
2
  1. import org.apache.poi.xssf.usermodel.*;
3
  1. public class OpenWorkBook
4
  1. {
5
  1.   public static void main(String args[])throws Exception
6
  1.   {
7
  1.      File file = new File("openworkbook.xlsx");
8
  1.      FileInputStream fIP = new FileInputStream(file);
9
  1.      //Get the workbook instance for XLSX file
10
  1.      XSSFWorkbook workbook = new XSSFWorkbook(fIP);
11
  1.      if(file.isFile() && file.exists())
12
  1.     {
13
  1.         System.out.println(
14
  1.         "openworkbook.xlsx file open successfully.");
15
  1.     }
16
  1.      else
17
  1.     {
18
  1.         System.out.println(
19
  1.         "Error to open openworkbook.xlsx file.");
20
  1.     }
21
  1.   }
22
  1. }

4、方法示例:任意对象List转至为Excel文档(可用注解定义标签名和列名)

写了个方法,可以将某个类的List转换为对应的Excel文档,列名如果在不使用注解的情况下默认为属性名:

类:
  1. @Excel(name = "学生标签页")
  2. public class Student {
  3. @Excel(name = "姓名")
  4. private String name;
  5. private boolean male;
  6. @Excel(name = "身高")
  7. private int height;
  8. public String getName() {
  9. return name;
  10. }
  11. public void setName(String name) {
  12. this.name = name;
  13. }
  14. public boolean isMale() {
  15. return male;
  16. }
  17. public void setMale(boolean male) {
  18. this.male = male;
  19. }
  20. public int getHeight() {
  21. return height;
  22. }
  23. public void setHeight(int height) {
  24. this.height = height;
  25. }
  26. }
35
 
1
  1. @Excel(name = "学生标签页")
2
  1. public class Student {
3
  1.  
4
  1.    @Excel(name = "姓名")
5
  1.    private String name;
6
  1.  
7
  1.    private boolean male;
8
  1.  
9
  1.    @Excel(name = "身高")
10
  1.    private int height;
11
  1.  
12
  1.    public String getName() {
13
  1.        return name;
14
  1.   }
15
  1.  
16
  1.    public void setName(String name) {
17
  1.        this.name = name;
18
  1.   }
19
  1.  
20
  1.    public boolean isMale() {
21
  1.        return male;
22
  1.   }
23
  1.  
24
  1.    public void setMale(boolean male) {
25
  1.        this.male = male;
26
  1.   }
27
  1.  
28
  1.    public int getHeight() {
29
  1.        return height;
30
  1.   }
31
  1.  
32
  1.    public void setHeight(int height) {
33
  1.        this.height = height;
34
  1.   }
35
  1. }

测试方法:
  1. public static void main(String[] args) {
  2. List<Student> list = new ArrayList<Student>();
  3. Student student1 = new Student();
  4. student1.setName("小红");
  5. student1.setMale(false);
  6. student1.setHeight(167);
  7. Student student2 = new Student();
  8. student2.setName("小明");
  9. student2.setMale(true);
  10. student2.setHeight(185);
  11. list.add(student1);
  12. list.add(student2);
  13. File file = new File("C:/Users/Dulk/Desktop/1314.xls");
  14. createExcel(list, file);
  15. }
18
 
1
  1. public static void main(String[] args) {
2
  1.    List<Student> list = new ArrayList<Student>();
3
  1.    Student student1 = new Student();
4
  1.    student1.setName("小红");
5
  1.    student1.setMale(false);
6
  1.    student1.setHeight(167);
7
  1.  
8
  1.    Student student2 = new Student();
9
  1.    student2.setName("小明");
10
  1.    student2.setMale(true);
11
  1.    student2.setHeight(185);
12
  1.  
13
  1.    list.add(student1);
14
  1.    list.add(student2);
15
  1.  
16
  1.    File file = new File("C:/Users/Dulk/Desktop/1314.xls");
17
  1.    createExcel(list, file);
18
  1. }

输出结果:
 

注解:
  1. import java.lang.annotation.Retention;
  2. import java.lang.annotation.RetentionPolicy;
  3. @Retention(RetentionPolicy.RUNTIME)
  4. public @interface Excel {
  5. //设置名称
  6. public String name() default "";
  7. }
9
 
1
  1. import java.lang.annotation.Retention;
2
  1. import java.lang.annotation.RetentionPolicy;
3
  1.  
4
  1.  
5
  1. @Retention(RetentionPolicy.RUNTIME)
6
  1. public @interface Excel {
7
  1.    //设置名称
8
  1.    public String name() default "";
9
  1. }

方法:
  1. import org.apache.log4j.Logger;
  2. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  3. import org.apache.poi.ss.usermodel.Cell;
  4. import org.apache.poi.ss.usermodel.Row;
  5. import org.apache.poi.ss.usermodel.Sheet;
  6. import org.apache.poi.ss.usermodel.Workbook;
  7. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  8. import java.io.File;
  9. import java.io.FileInputStream;
  10. import java.io.FileNotFoundException;
  11. import java.io.FileOutputStream;
  12. import java.io.IOException;
  13. import java.io.InputStream;
  14. import java.io.OutputStream;
  15. import java.lang.reflect.Field;
  16. import java.lang.reflect.InvocationTargetException;
  17. import java.lang.reflect.Method;
  18. import java.util.ArrayList;
  19. import java.util.List;
  20. /**
  21. * Excel的操作工具类
  22. */
  23. public class ExcelUtil {
  24. private static Logger log = Logger.getLogger(ExcelUtil.class);
  25. /**
  26. * 获取某个File文件对应的Workbook工作簿对象
  27. */
  28. public static Workbook gainWorkbook(File file) throws ExcelException {
  29. if (!isExcel(file)) {
  30. throw new ExcelException("文件不是Excel类型");
  31. }
  32. //如果文件不存在则新建
  33. if (!file.exists()) {
  34. try {
  35. OutputStream os = new FileOutputStream(file);
  36. Workbook workbook = isOlderEdition(file) ? new HSSFWorkbook() : new XSSFWorkbook();
  37. workbook.write(os);
  38. log.debug("文件不存在,新建该Excel文件");
  39. os.close();
  40. } catch (FileNotFoundException e) {
  41. e.printStackTrace();
  42. } catch (IOException e) {
  43. e.printStackTrace();
  44. }
  45. }
  46. try {
  47. InputStream is = new FileInputStream(file);
  48. return isOlderEdition(file) ? new HSSFWorkbook(is) : new XSSFWorkbook(is);
  49. } catch (FileNotFoundException e) {
  50. e.printStackTrace();
  51. } catch (IOException e) {
  52. e.printStackTrace();
  53. }
  54. return null;
  55. }
  56. /**
  57. * 判断某个Excel文件是否是2003-2007通用旧版
  58. */
  59. private static boolean isOlderEdition(File file) {
  60. return file.getName().matches(".+\\.(?i)xls");
  61. }
  62. /**
  63. * 判断文件是否是一个Excel文件
  64. */
  65. private static boolean isExcel(File file) {
  66. String fileName = file.getName();
  67. String regXls = ".+\\.(?i)xls";
  68. String regXlsx = ".+\\.(?i)xlsx";
  69. return fileName.matches(regXls) || fileName.matches(regXlsx);
  70. }
  71. /**
  72. * 将某个对象的List转换为Excel工作簿
  73. */
  74. public static <E> Workbook createExcel(List<E> list, File file) {
  75. String sheetName = "default";
  76. if (list.size() == 0) {
  77. return null;
  78. }
  79. Workbook workbook = null;
  80. try {
  81. Class clazz = list.get(0).getClass();
  82. Field[] fields = clazz.getDeclaredFields();
  83. if (clazz.isAnnotationPresent(Excel.class)) {
  84. Excel excel = (Excel) clazz.getAnnotation(Excel.class);
  85. sheetName = excel.name();
  86. }
  87. workbook = gainWorkbook(file);
  88. Sheet sheet = workbook.createSheet(sheetName);
  89. //创建首行
  90. Row line = sheet.createRow(0);
  91. for (int k = 0; k < fields.length; k++) {
  92. Cell cell = line.createCell(k);
  93. String columnName = fields[k].getName();
  94. if (fields[k].isAnnotationPresent(Excel.class)) {
  95. Excel excel = fields[k].getAnnotation(Excel.class);
  96. columnName = excel.name();
  97. }
  98. cell.setCellValue(columnName);
  99. }
  100. //创建数据
  101. for (int i = 1; i <= list.size(); i++) {
  102. Row row = sheet.createRow(i);
  103. for (int j = 1; j <= fields.length; j++) {
  104. Cell cell = row.createCell(j - 1);
  105. String fieldName = fields[j - 1].getName();
  106. String fieldFirstLetterUpper = fieldName.substring(0, 1).toUpperCase();
  107. String prefix = "get";
  108. if ("boolean".equals(fields[j - 1].getType().getName())) {
  109. prefix = "is";
  110. }
  111. String methodName = prefix + fieldFirstLetterUpper + fieldName.substring(1);
  112. Method method = clazz.getMethod(methodName);
  113. cell.setCellValue(String.valueOf(method.invoke(list.get(i - 1))));
  114. }
  115. }
  116. log.debug("List读入完毕");
  117. OutputStream os = new FileOutputStream(file);
  118. workbook.write(os);
  119. os.close();
  120. } catch (ExcelException e) {
  121. e.printStackTrace();
  122. } catch (InvocationTargetException e) {
  123. e.printStackTrace();
  124. } catch (NoSuchMethodException e) {
  125. e.printStackTrace();
  126. } catch (IllegalAccessException e) {
  127. e.printStackTrace();
  128. } catch (FileNotFoundException e) {
  129. e.printStackTrace();
  130. } catch (IOException e) {
  131. e.printStackTrace();
  132. }
  133. return workbook;
  134. }
  135. }
x
 
1
  1. import org.apache.log4j.Logger;
2
  1. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
3
  1. import org.apache.poi.ss.usermodel.Cell;
4
  1. import org.apache.poi.ss.usermodel.Row;
5
  1. import org.apache.poi.ss.usermodel.Sheet;
6
  1. import org.apache.poi.ss.usermodel.Workbook;
7
  1. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
8
  1.  
9
  1. import java.io.File;
10
  1. import java.io.FileInputStream;
11
  1. import java.io.FileNotFoundException;
12
  1. import java.io.FileOutputStream;
13
  1. import java.io.IOException;
14
  1. import java.io.InputStream;
15
  1. import java.io.OutputStream;
16
  1. import java.lang.reflect.Field;
17
  1. import java.lang.reflect.InvocationTargetException;
18
  1. import java.lang.reflect.Method;
19
  1. import java.util.ArrayList;
20
  1. import java.util.List;
21
  1.  
22
  1. /**
23
  1. * Excel的操作工具类
24
  1. */
25
  1. public class ExcelUtil {
26
  1.    private static Logger log = Logger.getLogger(ExcelUtil.class);
27
  1.  
28
  1.    /**
29
  1.     * 获取某个File文件对应的Workbook工作簿对象
30
  1.     */
31
  1.    public static Workbook gainWorkbook(File file) throws ExcelException {
32
  1.        if (!isExcel(file)) {
33
  1.            throw new ExcelException("文件不是Excel类型");
34
  1.       }
35
  1.        //如果文件不存在则新建
36
  1.        if (!file.exists()) {
37
  1.            try {
38
  1.                OutputStream os = new FileOutputStream(file);
39
  1.                Workbook workbook = isOlderEdition(file) ? new HSSFWorkbook() : new XSSFWorkbook();
40
  1.                workbook.write(os);
41
  1.                log.debug("文件不存在,新建该Excel文件");
42
  1.                os.close();
43
  1.  
44
  1.           } catch (FileNotFoundException e) {
45
  1.                e.printStackTrace();
46
  1.           } catch (IOException e) {
47
  1.                e.printStackTrace();
48
  1.           }
49
  1.       }
50
  1.  
51
  1.        try {
52
  1.            InputStream is = new FileInputStream(file);
53
  1.            return isOlderEdition(file) ? new HSSFWorkbook(is) : new XSSFWorkbook(is);
54
  1.  
55
  1.       } catch (FileNotFoundException e) {
56
  1.            e.printStackTrace();
57
  1.       } catch (IOException e) {
58
  1.            e.printStackTrace();
59
  1.       }
60
  1.  
61
  1.        return null;
62
  1.   }
63
  1.  
64
  1.    /**
65
  1.     * 判断某个Excel文件是否是2003-2007通用旧版
66
  1.     */
67
  1.    private static boolean isOlderEdition(File file) {
68
  1.        return file.getName().matches(".+\\.(?i)xls");
69
  1.   }
70
  1.  
71
  1.    /**
72
  1.     * 判断文件是否是一个Excel文件
73
  1.     */
74
  1.    private static boolean isExcel(File file) {
75
  1.        String fileName = file.getName();
76
  1.        String regXls = ".+\\.(?i)xls";
77
  1.        String regXlsx = ".+\\.(?i)xlsx";
78
  1.        return fileName.matches(regXls) || fileName.matches(regXlsx);
79
  1.   }
80
  1.  
81
  1.    /**
82
  1.     * 将某个对象的List转换为Excel工作簿
83
  1.     */
84
  1.    public static <E> Workbook createExcel(List<E> list, File file) {
85
  1.        String sheetName = "default";
86
  1.        if (list.size() == 0) {
87
  1.            return null;
88
  1.       }
89
  1.  
90
  1.        Workbook workbook = null;
91
  1.        try {
92
  1.            Class clazz = list.get(0).getClass();
93
  1.            Field[] fields = clazz.getDeclaredFields();
94
  1.            if (clazz.isAnnotationPresent(Excel.class)) {
95
  1.                Excel excel = (Excel) clazz.getAnnotation(Excel.class);
96
  1.                sheetName = excel.name();
97
  1.           }
98
  1.  
99
  1.            workbook = gainWorkbook(file);
100
  1.            Sheet sheet = workbook.createSheet(sheetName);
101
  1.            //创建首行
102
  1.            Row line = sheet.createRow(0);
103
  1.            for (int k = 0; k < fields.length; k++) {
104
  1.                Cell cell = line.createCell(k);
105
  1.                String columnName = fields[k].getName();
106
  1.                if (fields[k].isAnnotationPresent(Excel.class)) {
107
  1.                    Excel excel = fields[k].getAnnotation(Excel.class);
108
  1.                    columnName = excel.name();
109
  1.               }
110
  1.                cell.setCellValue(columnName);
111
  1.           }
112
  1.            //创建数据
113
  1.            for (int i = 1; i <= list.size(); i++) {
114
  1.                Row row = sheet.createRow(i);
115
  1.                for (int j = 1; j <= fields.length; j++) {
116
  1.                    Cell cell = row.createCell(j - 1);
117
  1.                    String fieldName = fields[j - 1].getName();
118
  1.                    String fieldFirstLetterUpper = fieldName.substring(0, 1).toUpperCase();
119
  1.                    String prefix = "get";
120
  1.                    if ("boolean".equals(fields[j - 1].getType().getName())) {
121
  1.                        prefix = "is";
122
  1.                   }
123
  1.                    String methodName = prefix + fieldFirstLetterUpper + fieldName.substring(1);
124
  1.                    Method method = clazz.getMethod(methodName);
125
  1.                    cell.setCellValue(String.valueOf(method.invoke(list.get(i - 1))));
126
  1.               }
127
  1.           }
128
  1.            log.debug("List读入完毕");
129
  1.            OutputStream os = new FileOutputStream(file);
130
  1.            workbook.write(os);
131
  1.            os.close();
132
  1.  
133
  1.       } catch (ExcelException e) {
134
  1.            e.printStackTrace();
135
  1.       } catch (InvocationTargetException e) {
136
  1.            e.printStackTrace();
137
  1.       } catch (NoSuchMethodException e) {
138
  1.            e.printStackTrace();
139
  1.       } catch (IllegalAccessException e) {
140
  1.            e.printStackTrace();
141
  1.       } catch (FileNotFoundException e) {
142
  1.            e.printStackTrace();
143
  1.       } catch (IOException e) {
144
  1.            e.printStackTrace();
145
  1.       }
146
  1.        return workbook;
147
  1.   }
148
  1. }


5、参考链接



通过Excel认识POI的更多相关文章

  1. java写入excel文件poi

    java写入excel文件 java写入excel文件poi,支持xlsx与xls,没有文件自动创建 package com.utils; import java.io.File; import ja ...

  2. 一脸懵逼学习Java操作Excel之POI(Apache POI)

    Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能. 1:下面简单的程序来创建一个空白Microsoft ...

  3. Excel的poi缓存问题

    Excel的poi缓存问题 背景: 最近工作需要,需要完成生成新的Excel,然后从Excel中读取包含公式的文本内容. 问题: 当程序中修改公式对应的单元格数据变化时,公式获取的值仍然还是原来的值, ...

  4. java操作excel总结---poi

    前不久做过Excel的导入导出功能,其主要的难点是java如何操作Excel文档.现在就来介绍一下利用Apache的poi如何操作Excel. 1.准备工作:导入Apache POI的相关jar包,P ...

  5. Java 实现导出excel表 POI

    1.首先下载poi-3.6-20091214.jar 2.Student.java import java.util.Date; public class Student { private int ...

  6. flex+java将数据库里的数据导出到指定目录下excel表里(poi)

    数据写入到excel中采用的是Apache POI: //java后台的一个工具类(该工具类适用于为不同字段添加,方便) /* 下面这个方法是将list转换为Excel工作表的 */ public s ...

  7. Java 操作Excel 之Poi(第一讲)

    1.Poi 简介 Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能.HSSF - 提供读写Micros ...

  8. springMVC导入excel案例poi

    直接上代码: 第一步,controller 引入 private static final String CHECK_FILE = "checkExceFile"; /** * 对 ...

  9. importExcel运用注解实现EXCEL导入poi类

    JAVA报表 package com.app.common.excel; import java.io.File; import java.io.FileInputStream; import jav ...

  10. C++读写EXCEL文件OLE,java读写excel文件POI 对比

    C++读写EXCEL文件方式比较 有些朋友问代码的问题,将OLE读写的代码分享在这个地方,大家请自己看.http://www.cnblogs.com/destim/p/5476915.html C++ ...

随机推荐

  1. 浏览器支持播放的视频播放格式要求(H5的video标签)

    今天给一个客户上传视频后发现,即使是MP4格式的视频浏览器也打不开,找了好久的问题,最红发现客户视频的编码方式不是h5支持的,折腾了好久,最终确认了浏览器对于MP4编码方式的如下: 浏览器对mp4的编 ...

  2. SQLite在C#中的安装与操作

    SQLite 介绍 SQLite,是一款轻型的数据库,用于本地的数据储存. 先说说优点,它占用资源非常的低,在嵌入式设备中需要几百K的内存就够了:作为轻量级数据库,他的处理速度也足够快:支持的的容量级 ...

  3. Integer陷阱(0~127和其他 数值相等对象比较)

    Integer 类在对象中包装了一个基本类型 int 的值. 有一个陷阱存在,经常出现在面试题中,情况如下面代码 public class IntegerDemo { public static vo ...

  4. Python量化投资知识总结贴

    Ricequant 量化社区的初衷让各位爱好量化的人士可以碰撞思维,在分享和争辩中学习到有用且实战的量化知识.有赖于各位在社区中贡献满满的干货以及有质量的讨论,从编程入门教学到技术指标再到多因子选股. ...

  5. HTTP常见状态码

    1.100状态码 1xx:临时响应,表示临时相应并需要请求者继续操作的状态码 100   (继续) 请求者应当继续提出请求. 服务器返回此代码表示已收到请求的第一部分,正在等待其余部分.   101 ...

  6. PYQT4 : QSystemTrayIcon练习

    照着demo自己做了一遍,练练手 import sys from PyQt4 import QtGui from PyQt4 import QtCore class SysTray(QtGui.QDi ...

  7. TensorFlow框架(4)之CNN卷积神经网络

    1. 卷积神经网络 1.1 多层前馈神经网络 多层前馈神经网络是指在多层的神经网络中,每层神经元与下一层神经元完全互连,神经元之间不存在同层连接,也不存在跨层连接的情况,如图 11所示. 图 11 对 ...

  8. maven 搭建 SpringMVC + MyBatis(1)

    ·做了两年多Java Web一多半的项目都是SSM架构的,只搭建过两次,趁着周末做个总结整理. Eclipse搭建Maven项目 1.new project  --> Maven project ...

  9. python基础教程(十)

    魔法方法.属性 ------------------------ 准备工作 为了确保类是新型类,应该把 _metaclass_=type 入到你的模块的最开始. class NewType(Objec ...

  10. 修改 Pattern代码使 Java 正则表达式支持下划线 '_'

    为什么 由于工作是做数据ETL的,很多时候会使用到正则对数据进行提取,但是java的正则中的groupname不支持'_',官方的文档中是这样的: Group name A capturing gro ...