POI XSSF和SAX(事件API)的日期格式问题 [英] Date format issue with POI XSSF and SAX (Event API)

查看:734
本文介绍了POI XSSF和SAX(事件API)的日期格式问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用POI的事件API来处理大量记录,而没有任何内存占用问题. 此处是其引用.

I am using POI's Event API to process large volume of records without any memory foot print issues. Here is the refernce for it.

当我处理XLSX工作表时,我得到的日期值格式与Excel工作表中指定的格式不同. Excel工作表中列的日期格式为"dd-mm-yyyy",在此我以"mm/dd/yy"格式获取值.

When i processing XLSX sheet, i am getting different format of Date value than specified format in excel sheet. Date format for a column in excel sheet is 'dd-mm-yyyy' where as I am getting the value in 'mm/dd/yy' format.

有人可以告诉我如何获取excel工作表中给出的实际格式.下面给出了代码段的参考.

Can some one tell me how to get the actual format given in excel sheet. Reference of code snippet is given below.

ContentHandler handler = new XSSFSheetXMLHandler(styles, strings,
          new SheetContentsHandler() {
            public void startRow(int rowNum) {
            }
            public void endRow() {
            }
            public void cell(String cellReference, String formattedValue) {
                  System.out.println(formattedValue);
                } catch (IOException e) {
                    System.out.println(
                      "Exception during file writing");
                }
              }

在单元格方法中为日期列获取formmatedValue就像'mm/dd/yy',因此我无法在我的pl/sql程序中正确进行验证.

Getting formmatedValue in cell method for date column is like 'mm/dd/yy' and hence i cant able to do the validations properly in my pl/sql program.

推荐答案

Excel存储带有区域设置的某些日期.例如,在Excel的数字格式对话框中,您会看到如下警告:

Excel stores some dates with regional settings. For example in the number format dialog in Excel you will see a warning like this:

根据您指定的类型和语言环境(位置),将日期和时间序列号显示为日期值.以星号(*)开头的日期格式响应控制面板"中指定的区域日期和时间设置的更改.没有星号的格式不受控制面板"设置的影响.

Displays date and time serial numbers as date values, according to the type and locale (location) that you specify. Date formats that begin with an asterisk (*) respond to changes in regional date and time settings that are specified in Control Panel. Formats without an asterisk are not affected by Control Panel settings.

您正在读取的Excel文件可能正在使用这些*日期之一.在这种情况下,POI可能会使用美国默认值.

The Excel file that you are reading may be using one of those *dates. In which case POI probably uses a US default value.

您可能需要添加一些解决方法代码,以将日期格式字符串映射为所需的格式.

You will probably need to add some workaround code to map the date format strings to the format that you want.

有关Excel中区域日期设置的讨论,另请参见以下内容.

这篇关于POI XSSF和SAX(事件API)的日期格式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆