Thanks for your help. An interesting aspect is that if I get rid of the
formula in the first column of the spreadsheet ,it is processed in
normal fashion and gives me more than 31 rows.

I will try to incorporate that jar file and check .We are using POI
version 1.8.x



        -----Original Message-----
        From: Page, Michael A. [mailto:[EMAIL PROTECTED]
        Sent: Monday, August 29, 2005 4:58 PM
        To: POI Users List
        Subject: RE: Problem reading Excel File



        I didn't actually look at your code. I'm hoping what I send you
will help
        you fix yours.

        The attached java source file was able to read your excel
spreadsheet.
        I copied your excel file to the root of my c drive and renamed
it HSSF.xls.
        I use eclipse 3.1 as my development package and have the
poi-2.5.1-final-20040804.jar added as an external jar file. This jar
file resides in the

        same location of the java source file. I'm not sure why my code
indicates
        more rows and columns then your data would indicate. Perhaps you
have some
        hidden values floating around.

        Hope this helps.

        Mike

        -----Original Message-----
        From: Anand,Anuj [mailto:[EMAIL PROTECTED]
        Sent: Monday, August 29, 2005 3:25 PM
        To: POI Users List
        Subject: RE: Problem reading Excel File


        Sorry for sending out the message repeatedly....Attached is the
inline
        code


        import java.io.FileInputStream;
        import java.io.FileOutputStream;
        import java.io.IOException;
        import java.io.InputStream;
        import java.util.Calendar;
        import java.util.Date;


        import org.apache.poi.hssf.dev.HSSF;
        import org.apache.poi.hssf.record.Record;
        import org.apache.poi.hssf.usermodel.HSSFCell;
        import org.apache.poi.hssf.usermodel.HSSFCellStyle;
        import org.apache.poi.hssf.usermodel.HSSFDataFormat;
        import org.apache.poi.hssf.usermodel.HSSFDateUtil;
        import org.apache.poi.hssf.usermodel.HSSFFont;
        import org.apache.poi.hssf.usermodel.HSSFRow;
        import org.apache.poi.hssf.usermodel.HSSFSheet;
        import org.apache.poi.hssf.usermodel.HSSFWorkbook;
        import org.apache.poi.hssf.util.Region;
        import org.apache.poi.poifs.filesystem.POIFSFileSystem;






        /**
         * File for HSSF testing/examples
         *
         * THIS IS NOT THE MAIN HSSF FILE!!  This is a util for testing
        functionality.
         * It does contain sample API usage that may be educational to
regular
        API users.
         *
         * @see #main
         * @author Andrew Oliver (acoliver at apache dot org)
         */


        public class Test
        {
            private String         filename     = null;


            // private POIFSFileSystem     fs           = null;
            private InputStream    stream       = null;
            private Record[]       records      = null;
            protected HSSFWorkbook hssfworkbook = null;
             static char cell_flag = 'N';
             static char row_flag = 'N';

            /**
             * Constructor HSSF - creates an HSSFStream from an
InputStream.
        The HSSFStream
             * reads in the records allowing modification.
             *
             *
             * @param filename
             *
             * @exception IOException
             *
             */


            public Test(String filename)
                throws IOException
            {
                this.filename = filename;
                POIFSFileSystem fs =
                    new POIFSFileSystem(new FileInputStream(filename));


             /*   POIFSFileSystem fs1 =
                    new POIFSFileSystem(new FileInputStream(filename));
               / p1 = new FileInputStream(*/
              

                hssfworkbook = new HSSFWorkbook(fs);


                // records = RecordFactory.createRecords(stream);
            }


            /**
             * Constructor HSSF - given a filename this outputs a sample
sheet
        with just
             * a set of rows/cells.
             *
             *
             * @param filename
             * @param write
             *
             * @exception IOException
             *
             */


            public Test(String filename, boolean write)
                throws IOException
            {
                short            rownum = 0;
                FileOutputStream out    = new
FileOutputStream(filename);
                HSSFWorkbook     wb     = new HSSFWorkbook();
                HSSFSheet        s      = wb.createSheet();
                HSSFRow          r      = null;
                HSSFCell         c      = null;
                HSSFCellStyle    cs     = wb.createCellStyle();
                HSSFCellStyle    cs2    = wb.createCellStyle();
                HSSFCellStyle    cs3    = wb.createCellStyle();
                HSSFFont         f      = wb.createFont();
                HSSFFont         f2     = wb.createFont();


                f.setFontHeightInPoints(( short ) 12);
                f.setColor(( short ) 0xA);
                f.setBoldweight(f.BOLDWEIGHT_BOLD);
                f2.setFontHeightInPoints(( short ) 10);
                f2.setColor(( short ) 0xf);
                f2.setBoldweight(f2.BOLDWEIGHT_BOLD);
                cs.setFont(f);



cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("($#,##0_);[Red]($#,##0

        )"));
                cs2.setBorderBottom(cs2.BORDER_THIN);
                cs2.setFillPattern(( short ) 1);   // fill w fg
                cs2.setFillForegroundColor(( short ) 0xA);
                cs2.setFont(f2);
                wb.setSheetName(0, "HSSF Test");
                for (rownum = ( short ) 0; rownum < 300; rownum++)
                {
                    r = s.createRow(rownum);
                    if ((rownum % 2) == 0)
                    {
                        r.setHeight(( short ) 0x249);
                    }


                    // r.setRowNum(( short ) rownum);
                    for (short cellnum = ( short ) 0; cellnum < 50;
cellnum +=
        2)
                    {
                       c = r.createCell(cellnum,
HSSFCell.CELL_TYPE_NUMERIC);
                       c = r.createCell(cellnum);
                       c.setCellValue(HSSFCell.CELL_TYPE_NUMERIC);
                       c.setCellValue(rownum * 10000 + cellnum
                                       + ((( double ) rownum / 1000)
                                          + (( double ) cellnum /
10000)));
                        if ((rownum % 2) == 0)
                        {
                            c.setCellStyle(cs);
                        }
                        /************AA***************************/
                        c = r.createCell(( short ) (cellnum + 1),
                                         HSSFCell.CELL_TYPE_STRING);
                      

                       // c = r.createCell(( short ) (cellnum + 1));
                       // c.setCellValue(HSSFCell.CELL_TYPE_STRING);
                        c.setCellValue("TEST");
                        s.setColumnWidth(( short ) (cellnum + 1),
                                         ( short ) ((50 * 8) / (( double
) 1 /
        20)));
                        if ((rownum % 2) == 0)
                        {
                            c.setCellStyle(cs2);
                        }
                    }   // 50 characters divided by 1/20th of a point
                }


                // draw a thick black border on the row at the bottom
using
        BLANKS
                rownum++;
                rownum++;
                r = s.createRow(rownum);
                cs3.setBorderBottom(cs3.BORDER_THICK);
                for (short cellnum = ( short ) 0; cellnum < 50;
cellnum++)
                {
                    c = r.createCell(cellnum, HSSFCell.CELL_TYPE_BLANK);

                    //c = r. createCell(cellnum)
                    //c.setCellValue(HSSFCell.CELL_TYPE_BLANK);
                  

                    c.setCellStyle(cs3);
                }
                s.addMergedRegion(new Region(( short ) 0, ( short ) 0, (
short )
        3,
                                             ( short ) 3));
                s.addMergedRegion(new Region(( short ) 100, ( short )
100,
                                             ( short ) 110, ( short )
110));


                // end draw thick black border
                // create a sheet, set its title then delete it
                s = wb.createSheet();
                wb.setSheetName(1, "DeletedSheet");
                wb.removeSheetAt(1);


                // end deleted sheet
                wb.write(out);
                out.close();
            }


            /**
             * Constructor HSSF - takes in file - attempts to read it
then
        reconstruct it
             *
             *
             * @param infile
             * @param outfile
             * @param write
             *
             * @exception IOException
             *
             */


            public Test(String infile, String outfile, boolean write)
                throws IOException
            {
                this.filename = filename;
                POIFSFileSystem fs =
                    new POIFSFileSystem(new FileInputStream(filename));


                hssfworkbook = new HSSFWorkbook(fs);


                // HSSFWorkbook book = hssfstream.getWorkbook();
            }


            /**
             * Method main
             *
             * Given 1 argument takes that as the filename, inputs it
and dumps
        the
             * cell values/types out to sys.out
             *
             * given 2 arguments where the second argument is the word
"write"
        and the
             * first is the filename - writes out a sample (test)
spreadsheet
        (see
             * public HSSF(String filename, boolean write)).
             *
             * given 2 arguments where the first is an input filename
and the
        second
             * an output filename (not write), attempts to fully read in
the
             * spreadsheet and fully write it out.
             *
             * given 3 arguments where the first is an input filename
and the
        second an
             * output filename (not write) and the third is "modify1",
attempts
        to read in the
             * spreadsheet, deletes rows 0-24, 74-99.  Changes cell at
row 39,
        col 3 to
             * "MODIFIED CELL" then writes it out.  Hence this is
"modify test
        1".  If you
             * take the output from the write test, you'll have a valid
        scenario.
             *
             * @param args
             *
             */


            public static void main(String [] args)
            {
              

              



                   try
                      

                        {
                        //HSSF hssf = new HSSF(args[ 0 ]);
                        //HSSF hssf = new HSSF("C://Documents and

Settings//c031902//Desktop//supplemental//supplemental_formats_01.xls");


                        Test test = new Test("C://Documents and
        Settings//c031902//Desktop//File23.xls"); 

                      

                      

                        System.out.println("Data dump:\n");
                        HSSFWorkbook wb = test.hssfworkbook;
                       

                        for (int k = 0; k < wb.getNumberOfSheets(); k++)

                        {
                            System.out.println("Sheet " + k);
                            HSSFSheet sheet = wb.getSheetAt(k);
                            int       rows  =
sheet.getPhysicalNumberOfRows();


                            for (int r = 0; r < rows; r++)
                            {
                              

                                                    

                                row_flag = 'N';
                                String cellText = null;
                              

                                try{
                                HSSFRow row   = sheet.getRow(r) ;
                              

                                int     cells =
row.getPhysicalNumberOfCells();
                              

                                System.out.println("ROW " +
row.getRowNum());
                              

                                for (short c = 0; c < cells; c++)
                                {
                                    cell_flag = 'N';
                                    HSSFCell cell  = row.getCell(c);
                                    String   value = null;
                                    Calendar cal =
Calendar.getInstance();
                                  

                                    try{


                                    switch (cell.getCellType())
                                    {


                                        case HSSFCell.CELL_TYPE_FORMULA
:
                                            value = "FORMULA value " +
        cell.getNumericCellValue();
                                            if (
cell.getNumericCellValue() ==
        2.0)

System.out.println("value
        matches");


                                            //rmulaParser form = new
        FormulaParser(
                                            //rm.GetNameAsIs();
                                          

                                            break;


                                        case HSSFCell.CELL_TYPE_NUMERIC
:
                                            if
(isCellDateFormatted(cell)){
                                             double d =
        cell.getNumericCellValue();
                                               java.util.Date dated =
        HSSFDateUtil.getJavaDate(d);

                                              cal.setTime(dated);
                                               cellText =
        String.valueOf(cal.get(Calendar.YEAR)).substring(2);
                                               cellText =
        cal.get(Calendar.MONTH)+1 + "/" + cal.get(Calendar.DAY_OF_MONTH)
+ "/" +
        cellText;
                                            }


                                          value = "NUMERIC value="
                                                    +
        cell.getNumericCellValue();
                                            break;


                                        case HSSFCell.CELL_TYPE_STRING :

                                            value = "STRING value="
                                                    +
cell.getStringCellValue();
                                            break;


                                        case HSSFCell.CELL_TYPE_BLANK :
                                             value = "BLANK  value=" +
        cell.getStringCellValue();
                                            break;
                                        default :
                                    }
                                  

                                    System.out.println("CELL col="
                                                       +
cell.getCellNum()
                                                       + " VALUE=" +
value);
                                }catch(NullPointerException n)
                                     { //n.printStackTrace();
                                        cell_flag = 'Y';
                                     }
                                if (cell_flag =='Y')
                                    continue;
                              

                                }
                                }catch(NullPointerException n){
                                  //n.printStackTrace();
                                  row_flag = 'Y';
                                 }
                               if (row_flag =='Y')
                                    continue;
                          

                            }
                        }
                    }catch (Exception e)
                    {
                        e.printStackTrace();
                    }
                }
                 




         public  static boolean isCellDateFormatted(HSSFCell cell) {
           boolean bDate = false;


          double d = cell.getNumericCellValue();
          if ( HSSFDateUtil.isValidExcelDate(d) ) {
             HSSFCellStyle style = cell.getCellStyle();
             int i = style.getDataFormat();
             switch(i) {
              // Internal Date Formats as described on page 427 in
Microsoft


              case 0x0e:
              case 0x0f:
              case 0x10:
              case 0x11:
              case 0x12:
              case 0x13:
              case 0x14:
              case 0x15:
              case 0x16:
              case 0x2d:
              case 0x2e:
              case 0x2f:
                bDate = true;
               break;


              default:
                bDate = false;
               break;
             }
           }

           return bDate;
        }



        }









                -----Original Message-----
                From: Anand,Anuj [mailto:[EMAIL PROTECTED]

                Sent: Monday, August 29, 2005 4:19 PM
                To: [email protected]
                Subject: Problem reading Excel File





                Attached is the JAVA File which tries to read the
following
        Excel File.

                <<Test.java>>




                <<File23.xls>>

                The problem is that only the first 32 Rows are read by
the
        Program although the Total Number of Rows are more than that
number.

                Any idea why this is happening?



                         -----Original Message-----

                        From:   Anand,Anuj

                        Sent:   Monday, August 29, 2005 3:35 PM

                        To:     '[email protected]'

                        Subject:        FW:




                         -----Original Message-----

                        From:   Anand,Anuj

                        Sent:   Monday, August 29, 2005 3:27 PM

                        To:     '[EMAIL PROTECTED]'

                        Subject:      


                        I need to resolve the following spreadsheet


                         << File: File23.xls >>


                        POI is reading only the first 32 rows from it.
Cna
        somebody help me out with that



        E-MAIL CONFIDENTIALITY NOTICE: The contents of this e-mail
message and
        any attachments are intended solely for the

        addressee(s) and may contain confidential and/or legally
privileged
        information. If you are not the

        intended recipient of this message or if this message has been
addressed
        to you in error, please

        immediately alert the sender by reply e-mail and then delete
this
        message and any attachments. If you

        are not the intended recipient, you are notified that any use,
        dissemination, distribution, copying, or

        storage of this message or any attachment is strictly
prohibited.





        E-MAIL CONFIDENTIALITY NOTICE:  The contents of this e-mail
message and any attachments are intended solely for the

        addressee(s) and may contain confidential and/or legally
privileged information. If you are not the

        intended recipient of this message or if this message has been
addressed to you in error, please

        immediately alert the sender by reply e-mail and then delete
this message and any attachments. If you

        are not the intended recipient, you are notified that any use,
dissemination, distribution, copying, or

        storage of this message or any attachment is strictly
prohibited.





E-MAIL CONFIDENTIALITY NOTICE:  The contents of this e-mail message and any 
attachments are intended solely for the
addressee(s) and may contain confidential and/or legally privileged 
information. If you are not the
intended recipient of this message or if this message has been addressed to you 
in error, please
immediately alert the sender by reply e-mail and then delete this message and 
any attachments. If you
are not the intended recipient, you are notified that any use, dissemination, 
distribution, copying, or
storage of this message or any attachment is strictly prohibited.

Reply via email to