You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by mariag <gm...@hotmail.com> on 2008/04/11 21:28:08 UTC
read custom format date hh:mm:ss:00
Hi All,
I am new to this HSSF. I have an urgent requirement to read an excel file.
But it has a time field that I don't know how to read it.
Can anyone please help me in reading a date cell with excel custom format
hh\:mm\:ss.00? if I have the value in the cell as 00.00.18.13 ,excel is
displaying itas 12:00:18 AM.
Thanks,
Maria
--
View this message in context: http://www.nabble.com/read-custom-format-date-hh%3Amm%3Ass%3A00%E2%80%8F-tp16628223p16628223.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: read custom format date hh:mm:ss:00�
Posted by mariag <gm...@hotmail.com>.
Hi Jakub & Nick
Thank you very much for your reply.
Today I tried again with SimpleDateFormat and I am getting the time that I
want.
I need to get it in the format KK:mm:ss:SS
K Hour in am/pm (0-11)
So I read about the java date formats and I am glad that I made it with the
help of you both.
Next step that I will have to learn how to convert excel 95 to excel 97.
Thank you very much to you both.
Maria
jakub kuzela wrote:
>
> Sorry i think u are able to working with date in java:
>
> java.text.SimpleDateFormat sdf = new
> java.text.SimpleDateFormat("hh.mm.ss.SS");
> System.out.println(sdf.format(readDate));
>
> http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
>
> Jakub.
>
> 2008/4/14, mariag <gm...@hotmail.com>:
>>
>>
>> Hi Jakub,
>> Thank you for your reply.
>>
>> I used the code and I am getting the output as
>>
>> DATE IS: Sun Dec 31 00:01:05 EST 1899
>>
>> But, I would like to get the same time as in the cell as 00:01:05.13 and
>> is
>> formatted as hh\:mm\:ss.00.
>>
>> Please help me to get the time.
>>
>> Thanks,
>> Maria
>>
>>
>>
>> jakub kuzela wrote:
>> >
>> > Hi,
>> >
>> > if you want create cell with format hh:mm:ss.00 u can do this:
>> >
>> > HSSFCellStyle cellData = wb.createCellStyle();
>> > HSSFDataFormat formatData = wb.createDataFormat();
>> > cellData.setDataFormat(formatData.getFormat("hh:mm:ss.00"));
>> >
>> > HSSFWorkbook wb = new HSSFWorkbook();
>> > HSSFSheet sheet = wb.createSheet("new sheet");
>> > HSSFRow row = sheet.createRow((short)0);
>> >
>> > cell = row.createCell((short)1);
>> > cell.setCellStyle(cellStyle);
>> > java.util.Date utilDate = new java.util.Date();
>> > cell.setCellValue(utilDate);
>> >
>> > if you want read this cell back you can do this:
>> >
>> > InputStream inp = new FileInputStream("D:/workbook.xls");
>> >
>> > wb = new HSSFWorkbook(new POIFSFileSystem(inp));
>> > sheet = wb.getSheet("new sheet");
>> > row = sheet.getRow((short)0);
>> > cell = row.getCell((short)1);
>> >
>> > java.util.Date readDate = cell.getDateCellValue();
>> > System.out.println("DATE IS: "+readDate);
>> >
>> > Is this what you ask?
>> >
>> > Jakub.
>> >
>> >
>> >
>> > 2008/4/14, Nick Burch <ni...@torchbox.com>:
>> >>
>> >> On Fri, 11 Apr 2008, mariag wrote:
>> >>
>> >> > I am new to this HSSF. I have an urgent requirement to read an excel
>> >> > file.
>> >> > But it has a time field that I don't know how to read it.
>> >> >
>> >> > Can anyone please help me in reading a date cell with excel custom
>> >> > format hh\:mm\:ss.00? if I have the value in the cell as
>> >> 00.00.18.13,excel is displaying itas 12:00:18 AM.
>> >> >
>> >>
>> >> I'm not sure quite what you're after, but have you tried reading:
>> >> http://poi.apache.org/hssf/quick-guide.html#CreateDateCells
>> >> http://poi.apache.org/hssf/quick-guide.html#DataFormats
>> >> ?
>> >>
>> >> Nick
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> >> For additional commands, e-mail: user-help@poi.apache.org
>> >>
>> >>
>> >
>> >
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/read-custom-format-date-hh%3Amm%3Ass%3A00%E2%80%8F-tp16628223p16677658.html
>> Sent from the POI - User mailing list archive at Nabble.com.
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>>
>>
>
>
--
View this message in context: http://www.nabble.com/read-custom-format-date-hh%3Amm%3Ass%3A00%E2%80%8F-tp16628223p16687666.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: read custom format date hh:mm:ss:00�
Posted by jakub kuzela <po...@gmail.com>.
Sorry i think u are able to working with date in java:
java.text.SimpleDateFormat sdf = new
java.text.SimpleDateFormat("hh.mm.ss.SS");
System.out.println(sdf.format(readDate));
http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
Jakub.
2008/4/14, mariag <gm...@hotmail.com>:
>
>
> Hi Jakub,
> Thank you for your reply.
>
> I used the code and I am getting the output as
>
> DATE IS: Sun Dec 31 00:01:05 EST 1899
>
> But, I would like to get the same time as in the cell as 00:01:05.13 and
> is
> formatted as hh\:mm\:ss.00.
>
> Please help me to get the time.
>
> Thanks,
> Maria
>
>
>
> jakub kuzela wrote:
> >
> > Hi,
> >
> > if you want create cell with format hh:mm:ss.00 u can do this:
> >
> > HSSFCellStyle cellData = wb.createCellStyle();
> > HSSFDataFormat formatData = wb.createDataFormat();
> > cellData.setDataFormat(formatData.getFormat("hh:mm:ss.00"));
> >
> > HSSFWorkbook wb = new HSSFWorkbook();
> > HSSFSheet sheet = wb.createSheet("new sheet");
> > HSSFRow row = sheet.createRow((short)0);
> >
> > cell = row.createCell((short)1);
> > cell.setCellStyle(cellStyle);
> > java.util.Date utilDate = new java.util.Date();
> > cell.setCellValue(utilDate);
> >
> > if you want read this cell back you can do this:
> >
> > InputStream inp = new FileInputStream("D:/workbook.xls");
> >
> > wb = new HSSFWorkbook(new POIFSFileSystem(inp));
> > sheet = wb.getSheet("new sheet");
> > row = sheet.getRow((short)0);
> > cell = row.getCell((short)1);
> >
> > java.util.Date readDate = cell.getDateCellValue();
> > System.out.println("DATE IS: "+readDate);
> >
> > Is this what you ask?
> >
> > Jakub.
> >
> >
> >
> > 2008/4/14, Nick Burch <ni...@torchbox.com>:
> >>
> >> On Fri, 11 Apr 2008, mariag wrote:
> >>
> >> > I am new to this HSSF. I have an urgent requirement to read an excel
> >> > file.
> >> > But it has a time field that I don't know how to read it.
> >> >
> >> > Can anyone please help me in reading a date cell with excel custom
> >> > format hh\:mm\:ss.00? if I have the value in the cell as
> >> 00.00.18.13,excel is displaying itas 12:00:18 AM.
> >> >
> >>
> >> I'm not sure quite what you're after, but have you tried reading:
> >> http://poi.apache.org/hssf/quick-guide.html#CreateDateCells
> >> http://poi.apache.org/hssf/quick-guide.html#DataFormats
> >> ?
> >>
> >> Nick
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> >> For additional commands, e-mail: user-help@poi.apache.org
> >>
> >>
> >
> >
>
>
> --
> View this message in context:
> http://www.nabble.com/read-custom-format-date-hh%3Amm%3Ass%3A00%E2%80%8F-tp16628223p16677658.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>
Re: read custom format date hh:mm:ss:00�
Posted by mariag <gm...@hotmail.com>.
Hi Jakub,
Thank you for your reply.
I used the code and I am getting the output as
DATE IS: Sun Dec 31 00:01:05 EST 1899
But, I would like to get the same time as in the cell as 00:01:05.13 and is
formatted as hh\:mm\:ss.00.
Please help me to get the time.
Thanks,
Maria
jakub kuzela wrote:
>
> Hi,
>
> if you want create cell with format hh:mm:ss.00 u can do this:
>
> HSSFCellStyle cellData = wb.createCellStyle();
> HSSFDataFormat formatData = wb.createDataFormat();
> cellData.setDataFormat(formatData.getFormat("hh:mm:ss.00"));
>
> HSSFWorkbook wb = new HSSFWorkbook();
> HSSFSheet sheet = wb.createSheet("new sheet");
> HSSFRow row = sheet.createRow((short)0);
>
> cell = row.createCell((short)1);
> cell.setCellStyle(cellStyle);
> java.util.Date utilDate = new java.util.Date();
> cell.setCellValue(utilDate);
>
> if you want read this cell back you can do this:
>
> InputStream inp = new FileInputStream("D:/workbook.xls");
>
> wb = new HSSFWorkbook(new POIFSFileSystem(inp));
> sheet = wb.getSheet("new sheet");
> row = sheet.getRow((short)0);
> cell = row.getCell((short)1);
>
> java.util.Date readDate = cell.getDateCellValue();
> System.out.println("DATE IS: "+readDate);
>
> Is this what you ask?
>
> Jakub.
>
>
>
> 2008/4/14, Nick Burch <ni...@torchbox.com>:
>>
>> On Fri, 11 Apr 2008, mariag wrote:
>>
>> > I am new to this HSSF. I have an urgent requirement to read an excel
>> > file.
>> > But it has a time field that I don't know how to read it.
>> >
>> > Can anyone please help me in reading a date cell with excel custom
>> > format hh\:mm\:ss.00? if I have the value in the cell as
>> 00.00.18.13,excel is displaying itas 12:00:18 AM.
>> >
>>
>> I'm not sure quite what you're after, but have you tried reading:
>> http://poi.apache.org/hssf/quick-guide.html#CreateDateCells
>> http://poi.apache.org/hssf/quick-guide.html#DataFormats
>> ?
>>
>> Nick
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>>
>>
>
>
--
View this message in context: http://www.nabble.com/read-custom-format-date-hh%3Amm%3Ass%3A00%E2%80%8F-tp16628223p16677658.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: read custom format date hh:mm:ss:00�
Posted by jakub kuzela <po...@gmail.com>.
Hi,
if you want create cell with format hh:mm:ss.00 u can do this:
HSSFCellStyle cellData = wb.createCellStyle();
HSSFDataFormat formatData = wb.createDataFormat();
cellData.setDataFormat(formatData.getFormat("hh:mm:ss.00"));
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
HSSFRow row = sheet.createRow((short)0);
cell = row.createCell((short)1);
cell.setCellStyle(cellStyle);
java.util.Date utilDate = new java.util.Date();
cell.setCellValue(utilDate);
if you want read this cell back you can do this:
InputStream inp = new FileInputStream("D:/workbook.xls");
wb = new HSSFWorkbook(new POIFSFileSystem(inp));
sheet = wb.getSheet("new sheet");
row = sheet.getRow((short)0);
cell = row.getCell((short)1);
java.util.Date readDate = cell.getDateCellValue();
System.out.println("DATE IS: "+readDate);
Is this what you ask?
Jakub.
2008/4/14, Nick Burch <ni...@torchbox.com>:
>
> On Fri, 11 Apr 2008, mariag wrote:
>
> > I am new to this HSSF. I have an urgent requirement to read an excel
> > file.
> > But it has a time field that I don't know how to read it.
> >
> > Can anyone please help me in reading a date cell with excel custom
> > format hh\:mm\:ss.00? if I have the value in the cell as 00.00.18.13,excel is displaying itas 12:00:18 AM.
> >
>
> I'm not sure quite what you're after, but have you tried reading:
> http://poi.apache.org/hssf/quick-guide.html#CreateDateCells
> http://poi.apache.org/hssf/quick-guide.html#DataFormats
> ?
>
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>
Re: read custom format date hh:mm:ss:00
Posted by Nick Burch <ni...@torchbox.com>.
On Mon, 14 Apr 2008, mariag wrote:
> But they have example for writing the cell, but not for reading the
> custom formated cell.
Ah, reading's easy. Just find the cell with your time in it, then do
cell.getDateCellValue()
That'll give you back a standard java date object. If you just want the
time out, then pass that to a java calendar, and call the getters to get
the hour, minute, second etc. If just want to print the time as a string,
use java.text.SimpleDateFormat to format the date as you want it
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: read custom format date hh:mm:ss:00
Posted by mariag <gm...@hotmail.com>.
Hi Nick,
Thank you for your reply.
Yes I tried to read.
But they have example for writing the cell, but not for reading the custom
formated cell.
As I am new to POI, I am not sure how to get the cell data with the custom
formatted time(00:01:05.00 - hh:mm:ss.00)
If you know how to get the data, please help.
Thanks,
Maria
Nick Burch wrote:
>
> On Fri, 11 Apr 2008, mariag wrote:
>> I am new to this HSSF. I have an urgent requirement to read an excel
>> file.
>> But it has a time field that I don't know how to read it.
>>
>> Can anyone please help me in reading a date cell with excel custom
>> format hh\:mm\:ss.00? if I have the value in the cell as 00.00.18.13
>> ,excel is displaying itas 12:00:18 AM.
>
> I'm not sure quite what you're after, but have you tried reading:
> http://poi.apache.org/hssf/quick-guide.html#CreateDateCells
> http://poi.apache.org/hssf/quick-guide.html#DataFormats
> ?
>
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/read-custom-format-date-hh%3Amm%3Ass%3A00%E2%80%8F-tp16628223p16677662.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: read custom format date hh:mm:ss:00
Posted by Nick Burch <ni...@torchbox.com>.
On Fri, 11 Apr 2008, mariag wrote:
> I am new to this HSSF. I have an urgent requirement to read an excel file.
> But it has a time field that I don't know how to read it.
>
> Can anyone please help me in reading a date cell with excel custom
> format hh\:mm\:ss.00? if I have the value in the cell as 00.00.18.13
> ,excel is displaying itas 12:00:18 AM.
I'm not sure quite what you're after, but have you tried reading:
http://poi.apache.org/hssf/quick-guide.html#CreateDateCells
http://poi.apache.org/hssf/quick-guide.html#DataFormats
?
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org