| | |
| | | import org.apache.poi.hssf.usermodel.*; |
| | | import org.apache.poi.openxml4j.opc.OPCPackage; |
| | | import org.apache.poi.poifs.filesystem.POIFSFileSystem; |
| | | import org.apache.poi.ss.usermodel.Cell; |
| | | import org.apache.poi.ss.usermodel.Row; |
| | | import org.apache.poi.ss.usermodel.Sheet; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.apache.poi.xssf.streaming.SXSSFWorkbook; |
| | | import org.apache.poi.xssf.usermodel.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | |
| | | // 在索引0的位置创建行(最顶端的行) |
| | | HSSFRow row = sheet.createRow(0); |
| | | // =============================================================== |
| | | for (int i = 0; i < headList.length; i++) { |
| | | |
| | | HSSFCell cell; |
| | | for (int i = 0; i < headList.length; i++) { |
| | | // 在索引0的位置创建单元格(左上端) |
| | | HSSFCell cell = row.createCell(i); |
| | | cell = row.createCell(i); |
| | | // 定义单元格为字符串类型 |
| | | cell.setCellType(HSSFCell.CELL_TYPE_STRING); |
| | | // 在单元格中输入一些内容 |
| | |
| | | } |
| | | // =============================================================== |
| | | if (dataList != null) { |
| | | HSSFRow row_value; |
| | | Map<String, Object> dataMap; |
| | | for (int n = 0; n < dataList.size(); n++) { |
| | | // 在索引1的位置创建行 |
| | | HSSFRow row_value = sheet.createRow(n + 1); |
| | | Map<String, Object> dataMap = dataList.get(n); |
| | | row_value = sheet.createRow(n + 1); |
| | | dataMap = dataList.get(n); |
| | | // =============================================================== |
| | | for (int i = 0; i < fieldList.length; i++) { |
| | | // 在索引0的位置创建单元格(左上端) |
| | | HSSFCell cell = row_value.createCell(i); |
| | | cell = row_value.createCell(i); |
| | | // 定义单元格为字符串类型 |
| | | cell.setCellType(HSSFCell.CELL_TYPE_STRING); |
| | | // 在单元格中输入一些内容 |
| | |
| | | // 在索引0的位置创建行(最顶端的行) |
| | | HSSFRow row = sheet.createRow(0); |
| | | // =============================================================== |
| | | HSSFCell cell; |
| | | for (int i = 0; i < headList.length; i++) { |
| | | |
| | | // 在索引0的位置创建单元格(左上端) |
| | | HSSFCell cell = row.createCell(i); |
| | | cell = row.createCell(i); |
| | | // 定义单元格为字符串类型 |
| | | cell.setCellType(HSSFCell.CELL_TYPE_STRING); |
| | | // 在单元格中输入一些内容 |
| | |
| | | } |
| | | // =============================================================== |
| | | if (dataList != null) { |
| | | HSSFRow row_value; |
| | | Map<String, Object> dataMap; |
| | | for (int n = 0; n < dataList.size(); n++) { |
| | | // 在索引1的位置创建行 |
| | | HSSFRow row_value = sheet.createRow(n + 1); |
| | | Map<String, Object> dataMap = dataList.get(n); |
| | | row_value = sheet.createRow(n + 1); |
| | | dataMap = dataList.get(n); |
| | | // =============================================================== |
| | | for (int i = 0; i < fieldList.length; i++) { |
| | | // 在索引0的位置创建单元格(左上端) |
| | | HSSFCell cell = row_value.createCell(i); |
| | | cell = row_value.createCell(i); |
| | | // 定义单元格为字符串类型 |
| | | cell.setCellType(HSSFCell.CELL_TYPE_STRING); |
| | | // 在单元格中输入一些内容 |
| | |
| | | // 在索引0的位置创建行(最顶端的行) |
| | | HSSFRow row = sheet.createRow(0); |
| | | // =============================================================== |
| | | HSSFCell cell; |
| | | for (int i = 0; i < headList.length; i++) { |
| | | //高度 |
| | | row.setHeight(height.shortValue()); |
| | | sheet.setColumnWidth(i,width); |
| | | // 在索引0的位置创建单元格(左上端) |
| | | HSSFCell cell = row.createCell(i); |
| | | cell = row.createCell(i); |
| | | // 定义单元格为字符串类型 |
| | | cell.setCellType(HSSFCell.CELL_TYPE_STRING); |
| | | // 在单元格中输入一些内容 |
| | |
| | | } |
| | | // =============================================================== |
| | | if (dataList != null) { |
| | | HSSFRow row_value; |
| | | Map<String, Object> dataMap; |
| | | for (int n = 0; n < dataList.size(); n++) { |
| | | // 在索引1的位置创建行 |
| | | HSSFRow row_value = sheet.createRow(n + 1); |
| | | row_value = sheet.createRow(n + 1); |
| | | row_value.setHeight(height.shortValue()); |
| | | Map<String, Object> dataMap = dataList.get(n); |
| | | dataMap = dataList.get(n); |
| | | // =============================================================== |
| | | for (int i = 0; i < fieldList.length; i++) { |
| | | // 在索引0的位置创建单元格(左上端) |
| | | sheet.setColumnWidth(i,width); |
| | | HSSFCell cell = row_value.createCell(i); |
| | | cell = row_value.createCell(i); |
| | | // 定义单元格为字符串类型 |
| | | cell.setCellType(HSSFCell.CELL_TYPE_STRING); |
| | | // 在单元格中输入一些内容 |
| | |
| | | width = 5000; |
| | | } |
| | | // 创建新的Excel 工作簿 |
| | | XSSFWorkbook workbook = new XSSFWorkbook(); |
| | | |
| | | //XSSFWorkbook workbook = new XSSFWorkbook(); |
| | | SXSSFWorkbook workbook = new SXSSFWorkbook(1000); |
| | | |
| | | //合并的单元格样式 |
| | | XSSFCellStyle boderStyle = workbook.createCellStyle(); |
| | | CellStyle boderStyle = workbook.createCellStyle(); |
| | | //垂直居中 |
| | | boderStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); |
| | | boderStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式 |
| | |
| | | // 在Excel工作簿中建一工作表,其名为缺省值 |
| | | // 如要新建一名为"效益指标"的工作表,其语句为: |
| | | // HSSFSheet sheet = workbook.createSheet("效益指标"); |
| | | XSSFSheet sheet = workbook.createSheet(); |
| | | Sheet sheet = workbook.createSheet(); |
| | | // 在索引0的位置创建行(最顶端的行) |
| | | XSSFRow row = sheet.createRow(0); |
| | | Row row = sheet.createRow(0); |
| | | // =============================================================== |
| | | Cell cell; |
| | | for (int i = 0; i < headList.length; i++) { |
| | | //高度 |
| | | row.setHeight(height.shortValue()); |
| | | sheet.setColumnWidth(i,width); |
| | | // 在索引0的位置创建单元格(左上端) |
| | | XSSFCell cell = row.createCell(i); |
| | | cell = row.createCell(i); |
| | | // 定义单元格为字符串类型 |
| | | cell.setCellType(HSSFCell.CELL_TYPE_STRING); |
| | | // 在单元格中输入一些内容 |
| | |
| | | } |
| | | // =============================================================== |
| | | if (dataList != null) { |
| | | Row row_value; |
| | | Map<String, Object> dataMap; |
| | | for (int n = 0; n < dataList.size(); n++) { |
| | | // 在索引1的位置创建行 |
| | | XSSFRow row_value = sheet.createRow(n + 1); |
| | | row_value = sheet.createRow(n + 1); |
| | | row_value.setHeight(height.shortValue()); |
| | | Map<String, Object> dataMap = dataList.get(n); |
| | | dataMap = dataList.get(n); |
| | | // =============================================================== |
| | | for (int i = 0; i < fieldList.length; i++) { |
| | | // 在索引0的位置创建单元格(左上端) |
| | | sheet.setColumnWidth(i,width); |
| | | XSSFCell cell = row_value.createCell(i); |
| | | cell = row_value.createCell(i); |
| | | // 定义单元格为字符串类型 |
| | | cell.setCellType(HSSFCell.CELL_TYPE_STRING); |
| | | // 在单元格中输入一些内容 |
| | |
| | | |
| | | |
| | | |
| | | |
| | | /**读取excel文件,兼容2003和2007 |
| | | * 通过流读取Excel文件 |
| | | * @return |
| | |
| | | return null; |
| | | } |
| | | |
| | | |
| | | private static String getCellVal(Cell cell) { |
| | | if (null == cell) { |
| | | return ""; |