java apache poi 日期格式和空白单元格处理

发布于 2024-12-23 00:52:56 字数 671 浏览 0 评论 0原文

XSSFWorkbook workbook07 = new XSSFWorkbook(xlname);                     
XSSFSheet sheet1 = workbook07.getSheet(sheetname);
CellReference cvalue = new CellReference("E11"); 
Row nrow = sheet1.getRow(cvalue.getRow());
Cell cell = (nrow.getCell(cvalue.getCol());

当我尝试从单元格中获取日期值 1/9/2009 时,它会以 1-oct-2009 等格式返回它。我需要获取单元格中日期的确切格式,并将其打印为输出..这意味着我需要将其输出为 1/9/2009

如果我试图获取一个空白单元格值并返回 null.pointer 异常,我必须再问一个问题。 它在获取值本身时返回异常,所以我无法处理它

Cell cell = (nrow.getCell(cvalue.getCol());

,所以我无法像这样处理它,

if {cell.Cell_TYPE_}

任何人都可以帮助我......!!

XSSFWorkbook workbook07 = new XSSFWorkbook(xlname);                     
XSSFSheet sheet1 = workbook07.getSheet(sheetname);
CellReference cvalue = new CellReference("E11"); 
Row nrow = sheet1.getRow(cvalue.getRow());
Cell cell = (nrow.getCell(cvalue.getCol());

when am trying to get a date value of 1/9/2009 from a cell means, its returning it in some format like 1-oct-2009. i need to get the exact format of the date what ever in the cell, and print it as a output ..that means i need out put as 1/9/2009.

and i have to ask one more, using this if am trying to get a blankcell values its returning null.pointer exception ..
its returning exception while getting the values itself so i cont able to handle it

Cell cell = (nrow.getCell(cvalue.getCol());

so i can't able handle it like this

if {cell.Cell_TYPE_}

can any one plz help me out..!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风蛊 2024-12-30 00:52:56

如果您知道该单元格确实是日期单元格(而不是有人手动输入日期作为字符串的字符串单元格),只需调用 Cell.getDateCellValue() 你会得到一个 Java Date 对象

你也可以使用 DateUtil.isCellDateFormatted(cell) 如果你想检查一个单元格是否是日期单元格(Excel 没有日期单元格的特定类型,它们只是数字具有特殊格式规则的单元格)

If you know the cell is really a Date cell (and not a String cell where someone has typed in a date by hand as a String), just call Cell.getDateCellValue() and you'll get back a Java Date object

You can also use DateUtil.isCellDateFormatted(cell) if you want to check if a cell is a date one or not (Excel doesn't have a specific type for date cells, they're just number cells with special formatting rules)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文