导航:首页 > 编程语言 > excel导入日期java

excel导入日期java

发布时间:2024-04-03 13:31:29

㈠ 如何把excel数据导入java

用第三和源芹方组件poi读取,给个例子你参考一下
public class ApachePOIExcelRead {

private static final String FILE_NAME = "/tmp/MyFirstExcel.xlsx";

public static void main(String[] args) {

try {

FileInputStream excelFile = new FileInputStream(new File(FILE_NAME));
Workbook workbook = new XSSFWorkbook(excelFile);
Sheet datatypeSheet = workbook.getSheetAt(0);
Iterator<裂槐Row>唤毕 iterator = datatypeSheet.iterator();

while (iterator.hasNext()) {

Row currentRow = iterator.next();
Iterator<Cell> cellIterator = currentRow.iterator();

while (cellIterator.hasNext()) {

Cell currentCell = cellIterator.next();
//getCellTypeEnum shown as deprecated for version 3.15
//getCellTypeEnum ill be renamed to getCellType starting from version 4.0
if (currentCell.getCellTypeEnum() == CellType.STRING) {
System.out.print(currentCell.getStringCellValue() + "--");
} else if (currentCell.getCellTypeEnum() == CellType.NUMERIC) {
System.out.print(currentCell.getNumericCellValue() + "--");
}

}
System.out.println();

}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

}
}

㈡ java代码怎么实现 excel导入的文本值转换成日期

读取excel文件中日期内容是通过poi获取的,代码如下:

HSSFWorkbookexcbook=newHSSFWorkbook(ExcFile);
//获取第一个仿州sheet页HSSFSheetexcSheet=excbook.getSheetAt(0);
//获取第一行
HSSFRowoneRow=excSheet.getRow(0);
//获取第一行的第一个表格
HSSFCelloneCell=oneRow.getCell(0);
switch(oneCell.getCellType()){

caseHSSFCell.CELL_TYPE_NUMERIC:

SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-dd");

if(HSSFDateUtil.isCellDateFormatted(oneCell)){

Stringstr=sdf.format(HSSFDateUtil.getJavaDate(oneCell.getNumericCellValue())).toString();

System.out.println(str);
庆大友}
break;
}

誉槐

㈢ excel中日期格式是数字,想转成java的日期格式,遇到了问题

java读取excel时间格式出现数字的处理方法:
Excel存储日期、时间均以数值类型进行存储,读取时POI先判断是是否是数值类型,再进行判断转化
1、数值格式(CELL_TYPE_NUMERIC):
1.纯数值格式:getNumericCellValue() 直接获取数据
2.日期格式:处理yyyy-MM-dd, d/m/yyyy h:mm, HH:mm 等不含文字的日期格式
1).判断是否是日期格式:HSSFDateUtil.isCellDateFormatted(cell)
2).判断是日期或者时间
cell.getCellStyle().getDataFormat() == HSSFDataFormat.getBuiltinFormat("h:mm")
OR: cell.getCellStyle().getDataFormat() == HSSFDataFormat.getBuiltinFormat("yyyy-MM-dd")
3.自定义日期格式:处理yyyy年m月d日,h时mm分,yyyy年m月等含文字的日期格式
判断cell.getCellStyle().getDataFormat()值,解析数值格式
yyyy年m月d日----->31
m月d日---->58
h时mm分--->32
举例说明:
private String parseExcel(Cell cell) {
String result = new String();

㈣ java导出excel时的日期和时间问题

提问虽然已经过去很长时间了,但是这个问题很普遍。我来补充一下,希望大家能看到吧、、
给导出时间格式的字段增加一个css样式:mso-number-format:'\@' 即可('\@'是格式化为文本方式)。
例:<td style="mso-number-format:'\@';"><%=myDateTime %></td>

㈤ java读取excel文件,怎么取日期列

一、定义excel的格式为普通文本,读出来永远都是String格式的字符串,再通过字符串转时间。
二、定义为时间格式的,读取用getDateCellValue。

如果你这样一直读出来都是数字的话,转为long的毫秒,再转为date。
那个数字是日期距离1900年1月1日的天数

㈥ JAVA如何从excel表格中读取正确的时间

excel的VBA里:

dim xStrTime as string
xstrtime = format(celles(2,1).value,"hh:mm:ss")

可以把单元格A2的时间赋值给字符串变量xstrtime,格式就是24小时制。

你的JAVA应该也可以用。

㈦ java 如何读取Excel中的日期 我取得的日期怎么是这样的例如:12-6-27 我想得到2012-04-27格式的

这个问题我也遇到过 excle读取日期 导入到数据库里面的如扮哪的日期格式就是12-6-27
所以要做下处理 给你个例子:
import com.ibm.icu.text.SimpleDateFormat;
class p{ public static void main(String[] args) { String s= "12-07-03";//你取得的日期格式 String y="MM-dd-yy";//yy是年缺慧,dd是月,MM是日 String x="yyyy-MM-dd"; SimpleDateFormat str = new SimpleDateFormat(y); SimpleDateFormat format = new SimpleDateFormat(x); try { str.parse(s);//这个是按照y的格式,将s变成一渣码个Date对象 format.format( str.parse(s));//按照X的格式,输出Date对象的值 System.out.println(format.format( str.parse(s))); //结果是2003-12-07 } catch (Exception e) { e.printStackTrace(); } }}

㈧ Java 出力Excel 文件,并向该文件中写固定格式的日期。我往文件里写的是yyyy-mm-dd

你写入的yyyy-mm-dd而显示yyyy/mm/dd这是正常的,表示EXCEL理解了你写入的数据是日期格式,显示的时候由于没有指定单元格的格式,所以系统以默认的yyyy/mm/dd格式显示,这个其实没关系。

如果你特别希望显示为yyyy-mm-dd格式,可以写入内容前增加一个单引号(半角英文),这样强制告诉EXCEL这是个文本,不要理解为日期。

还有一个办法,就是JAVA里面写入数据完毕,设置单元格的格式为yyyy-mm-dd,通过设置.NumberFormat 属性为 "yyyy-mm-dd"实现。

阅读全文

与excel导入日期java相关的资料

热点内容
苹果开机白屏带文件夹问号 浏览:731
体验服为什么服务器会关闭 浏览:39
酒店命令 浏览:750
中走丝线切割编程视频 浏览:78
衣服压缩袋手泵原理 浏览:714
通达信编程书籍 浏览:981
车用压缩天然气瓶阀 浏览:971
鞋的程序员 浏览:259
车的压缩比是什么意思 浏览:202
网站源码怎么传到文件夹 浏览:914
海南压缩机在哪里 浏览:491
电脑文件夹清晰的文件结构 浏览:839
如何把苹果手机的app转到安卓 浏览:305
java同步并发 浏览:249
fw压缩图片 浏览:258
淘宝申请源码靠谱吗 浏览:874
androidupdater 浏览:635
c2d游戏源码大全可复制版 浏览:771
电脑怎样重置网关命令 浏览:411
winftplinux 浏览:335