/*
* this function will read from excel
* and will return the items of excel
*/ public static String[][] readExcel(String config) throws IOException
{ File f=new File(config);
if(!f.exists())
{
return null;
}
FileInputStream fs = new FileInputStream(f);
//create a workbook
Workbook wb = new HSSFWorkbook(fs); Sheet sheet = wb.getSheetAt(0);
int rows=sheet.getLastRowNum();
Row firstRow=sheet.getRow(0);
int columns=firstRow.getLastCellNum();
String[][] data=new String[rows+1][columns];
for(int rownum=0;rownum<=sheet.getLastRowNum();rownum++) {
//for (Cell cell : row)
Row row = sheet.getRow(rownum); if (row == null) { continue; }
String value;
for(int cellnum=0;cellnum<=row.getLastCellNum();cellnum++){ Cell cell=row.getCell(cellnum);
// filter the null cells
if(cell==null)
{
continue;
}
else {
value="";
}
switch (cell.getCellType()) {
case Cell.CELL_TYPE_STRING:
// System.out.println(cell.getRichStringCellValue().getString());
value=cell.getRichStringCellValue().getString();
break;
case Cell.CELL_TYPE_NUMERIC:
if (DateUtil.isCellDateFormatted(cell)) {
//System.out.println(cell.getDateCellValue());
value=cell.getDateCellValue().toString(); } else {
// System.out.println(cell.getNumericCellValue());
value=Double.toString((int)cell.getNumericCellValue()); }
break;
case Cell.CELL_TYPE_BOOLEAN:
//System.out.println(cell.getBooleanCellValue());
value=Boolean.toString(cell.getBooleanCellValue());
break;
case Cell.CELL_TYPE_FORMULA:
//System.out.println(cell.getCellFormula());
value=cell.getCellFormula().toLowerCase();
break;
default:
value=" ";
System.out.println();
}
System.out.println(value); data[rownum][cellnum]=value; }
}
return data; }

java读取excel的更多相关文章

  1. Java读取Excel文件的几种方法

    Java读取 Excel 文件的常用开源免费方法有以下几种: 1. JDBC-ODBC Excel Driver 2. jxl.jar 3. jcom.jar 4. poi.jar 简单介绍: 百度文 ...

  2. Java读取excel表格

    Java读取excel表格 一般都是用poi技术去读取excel表格的,但是这个技术又是什么呢 什么是Apache POI? Apache POI是一种流行的API,它允许程序员使用Java程序创建, ...

  3. java读取excel文件的代码

    如下内容段是关于java读取excel文件的内容,应该能对各朋友有所用途. package com.zsmj.utilit; import java.io.FileInputStream;import ...

  4. Java读取Excel数据

    Java读取Excel数据,解析文本并格式化输出 Java读取Excel数据,解析文本并格式化输出 Java读取Excel数据,解析文本并格式化输出 下图是excel文件的路径和文件名 下图是exce ...

  5. 关于解决java读取excel文件遇空行抛空指针的问题 !

    关于解决java读取excel文件遇空行抛空指针的问题 ! package exceRead; import java.io.File; import java.io.FileInputStream; ...

  6. java 读取Excel文件并数据持久化方法Demo

    import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util ...

  7. java读取excel文件数据

    package com.smp.server.Ctrl; import java.io.File;import java.io.FileInputStream;import java.io.FileN ...

  8. JAVA读取EXCEL文件异常Unable to recognize OLE stream

    异常: jxl.read.biff.BiffException: Unable to recognize OLE stream at jxl.read.biff.CompoundFile.<in ...

  9. java 读取excel 正常 xls

    package com.sun.test; import java.io.BufferedInputStream;import java.io.File;import java.io.FileInpu ...

  10. java 读取excel(Map结构)xls

    package com.sun.test; import java.io.FileInputStream;import java.io.FileNotFoundException;import jav ...

随机推荐

  1. mysql存储过程之异常处理篇

    mysql存储过程也提供了对异常处理的功能:通过定义HANDLER来完成异常声明的实现 语法如下: DECLARE handler_type HANDLER FOR condition_value[, ...

  2. JQuery Easy Ui dataGrid 数据表格

    数据表格 - DataGrid 英文文档:http://www.jeasyui.com/documentation/index.php# 继承$.fn.panel.defaults,使用$.fn.da ...

  3. checkstyle配置文件说明

    属性说明 basedir代码所在的位置 AbstractClassNameformat: 定义抽象类的命名规则 PackageNameformat: 定义包名的命名规则 TypeNameformat: ...

  4. 利用flexbox实现按字符长度排列dom元素

    说明:请使用chrome浏览器打开 See the Pen pvyjGV by lilyH (@lilyH) on CodePen. 如上图所示,我们你要实现的效果就是,(1)在一行中显示两块元素:( ...

  5. 网络安全&信息安全&系统安全常用名词汇总

    拖库(脱裤) 隐写术 拖库(脱裤) 隐写术 拖库(脱裤) 隐写术 拖库(脱裤) 隐写术

  6. log4net的基本配置及用法

    [1].[代码] [C#]代码 跳至 [1] [2] ? 1 2 using System.Reflection;  //使用反射 static private ILog log = log4net. ...

  7. AngularJS API之toJson 对象转为JSON

    toJson()能把对象序列化为json 方法讲解 这个方法最多支持2个参数: angular.toJson(obj, pretty); obj 是想要转换的对象, pretty 可以调节格式化的样式 ...

  8. svn搬移到gitlab及使用

    svn是一款非常简便,易用的源代码管理工具,用了这么多年,对它情有独钟.都说习惯最难改,那为何要搬移到gitlab上呢? 喜欢尝试新东西,前提还是git比较强大,svn有的它都有,svn没有的它也有. ...

  9. 【C语言入门教程】1.2 函数库 和 链接

    程序员可以不需要从头开始设计每一个函数,完成用C语言命令所实现的函数非常罕见.因为所有的C语言编辑器都提供能完成各种常见任务函数,如printf()函数等.C语言编译器的实现者已经编写了大部分常见的通 ...

  10. MVC中下拉列表绑定方法

    方法一: 前端 @Html.DropDownListFor(a=>a.acate,ViewBag.CateList as IEnumerable<SelectListItem>) 后 ...