/*
* 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. iOS 生命周期

       应用生命周期 App启动:当App启动时,首先由not running状态切换到inactive状态,此时调用application:didFinishLaunchingWithOptions: ...

  2. c# 日期函数[string.Format----GetDateTimeFormats]格式 .【转帖备查】

    DateTime dt = DateTime.Now;Label1.Text = dt.ToString();//2005-11-5 13:21:25Label2.Text = dt.ToFileTi ...

  3. 来自 Google 的 R 语言编码风格指南

    来自 Google 的 R 语言编码风格指南R 语言是一门主要用于统计计算和绘图的高级编程语言. 这份 R 语言编码风格指南旨在让我们的 R 代码更容易阅读.分享和检查. 以下规则系与 Google ...

  4. Linux下更新时间

    方法一.使用命令 ntpdate time-a.nist.gov 方法二.本地安装ntpdate客户端 在本地安装ntpdate客户端,更新时用 ntpdate cn.pool.ntp.org 如果你 ...

  5. 优化 PHP 代码建议

    1.如果能将类的方法定义成static,就尽量定义成static,它的速度会提升将近4倍.2.$row[’id’] 的速度是$row[id]的7倍.3.echo 比 print 快,并且使用echo的 ...

  6. Form表单中method为get和post的区别

    序,form表单中的方法分为get和post,但你都知道他们之间的区别吗? Form表单中method为get和post的区别: 例子如下,有个Form表单. <form action=&quo ...

  7. Nginx 502 bad gateway问题的解决方法

    Nginx 502 Bad Gateway的含义是请求的PHP-CGI已经执行,但是由于某种原因(一般是读取资源的问题)没有执行完毕而导致PHP-CGI进程终止,一般来说Nginx 502 Bad G ...

  8. solr多条件查询(三)

    1.昨天记了一下三条件的“并且” “并且”(  &&   &&  )的情况,今天再来记一下 “并且”  “或者” 的情况. 这里的或者情况,一定要搞清楚无论有多少情况, ...

  9. poj3070 (斐波那契,矩阵快速幂)

    Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9630   Accepted: 6839 Descrip ...

  10. bootstrap搜索框样式代码及效果

    <div class="container"> <div class="input-group"> <input type=&qu ...