Why format changes while reading data from excel file using poi api java?

Bamadeva

I have an excel sheet, While reading the format changes like following

2 comes like 2.0, 1189736455 comes like 1.18973645E8 in Exponential format..

Why this happens, can anybody please help.. Thanks in advance...

here is my sample code Sheet_numUI and Sheet_numDB are the number of sheet form two files... Generally here I read from a file and compare with some value which I stored in a list and the result I store in another excel file... But while getting data from second file that is workBookUI (in my program) I'm not getting expected values...

the following are the files : reader enter image description here and output file is : enter image description here

   if(Sheet_numUI==Sheet_numDB){
            for(int i=0;i<Sheet_numUI;i++){
                Sheet_nameDB=workBookDB.getSheetAt(i).getSheetName();
                Sheet_nameUI=workBookUI.getSheetAt(i).getSheetName();
                ResultXLS_Reader =  new OMEGA_XLSX_Reader(file.getAbsolutePath());
                ResultXLS_Reader.addSheet1(Sheet_nameDB);
                counter=4;
                DBCol=readerDB.getColumnCount(Sheet_nameDB);
                DBRow=readerDB.getRowCount(Sheet_nameDB);

                UICol=readerUI.getColumnCount(Sheet_nameUI);
                UIRow=readerUI.getRowCount(Sheet_nameUI);
                for(int y=0;y<DBRow;y++){
                    for (int x=0;x<DBCol;x++){
                        if(y==0){
                            val=readerDB.getCellData(Sheet_nameDB, x, y+1);
                            ResultXLS_Reader.setCellDataStringColorLightGreen(Sheet_nameDB, x+1, y+1,val);
                        }else{
                            val=readerDB.getCellData(Sheet_nameDB, x, y+1);
                            ResultXLS_Reader.setCellData(Sheet_nameDB, x+1, y+1,val);
                            list.add(val);

                        }
                        System.out.println("List : "+ list);
                    }
                }
//              data insertion over
                compVal=(String) map.get(Sheet_nameDB);
                for(int k=0;k<=UIRow;k++){
                    for(int l=0;l<UICol;l++){
                        val=readerUI.getCellData(Sheet_nameUI, l, k);
                        if(val.equalsIgnoreCase(compVal)){

                            completeRow=readerUI.getRow(Sheet_nameUI, k-1);
                            for(Cell cell: completeRow){
                                list2.add(cell);
                            }
                            if(list2 != null && list2.size() > 0){
                            for(int m=0;m<list2.size();m++){

                                String val1=list.get(m).toString();
                                String val2=list2.get(m).toString();

                                if(val1.equalsIgnoreCase(val2)){
                                    ResultXLS_Reader.setCellDataColorLightGreen(Sheet_nameDB,m+1,counter, val1);

                                }else{
                                    ResultXLS_Reader.setCellDataColorRed(Sheet_nameDB, m+1,counter, val2);
                                }
                            }
                            counter=counter+1;
                        }
                            list2.clear();
                        }

                    }
                }
                list.clear();
                counter =0;
            }

        }
Alex

I'm assuming you're using the cell method .getNumericCellValue() which returns a double - a double will always print at least 1 decimal. As for the exponential format, that is just how large doubles print. See this question for how to deal with printing large doubles without scientific notation: How to print double value without scientific notation using Java?

Also, if your goal is printing the results back out into another spreadsheet with POI, you can create a cell style to format the numbers you put into a cell. For example:

DataFormat format = workbook.createDataFormat();
CellStyle number = workbook.createCellStyle();
number.setDataFormat(format.getFormat("#,##0"));

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Infinity loop while reading data from file

分類Dev

Reading excel file using OLEDB Data Provider

分類Dev

Reading columns from excel file using linq

分類Dev

Read from excel file .xlsx using java Apache POI 3.9 Eclipse

分類Dev

Cannot read from Excel file using apache poi

分類Dev

Find cumulative sum of a list while reading data from csv file

分類Dev

Makefile: using cp command while reading from a file

分類Dev

Error while reading json from pdf file using iText

分類Dev

Reading XML data from a file in python using Element tree

分類Dev

Reading large file in matlab with unique data format

分類Dev

Avoid inserting duplicates into MySQL while reading an excel file using spring boot

分類Dev

Characters not recognized while reading from file

分類Dev

Detect empty lines while reading from file

分類Dev

Writing to an excel using Apache POI corrupts the excel file

分類Dev

Reading from a txt file in Java

分類Dev

How to read input inside a while loop while reading from a file?

分類Dev

Reading from a CSV file and writing to a new CSV file using openCSV in java

分類Dev

Reading data from a file, only alpha characters

分類Dev

reading data from file and breaking it into tokens

分類Dev

create text reading data from a file

分類Dev

Accessing Excel Sheets in Java using Apache POI with Eclipse IDE

分類Dev

reading from a text file using fscanf()

分類Dev

Reading text file in java using scanner

分類Dev

Problems reading keys from properties file java

分類Dev

Missing first row while reading from file - Python Pandas

分類Dev

Scala writing and reading from a file inside a while loop

分類Dev

python [regex] - search function is not working while reading lines from a file

分類Dev

zcat skip streaming first line while reading from a compressed file

分類Dev

Illegal Argument Exception while Reading XML File in Java

Related 関連記事

  1. 1

    Infinity loop while reading data from file

  2. 2

    Reading excel file using OLEDB Data Provider

  3. 3

    Reading columns from excel file using linq

  4. 4

    Read from excel file .xlsx using java Apache POI 3.9 Eclipse

  5. 5

    Cannot read from Excel file using apache poi

  6. 6

    Find cumulative sum of a list while reading data from csv file

  7. 7

    Makefile: using cp command while reading from a file

  8. 8

    Error while reading json from pdf file using iText

  9. 9

    Reading XML data from a file in python using Element tree

  10. 10

    Reading large file in matlab with unique data format

  11. 11

    Avoid inserting duplicates into MySQL while reading an excel file using spring boot

  12. 12

    Characters not recognized while reading from file

  13. 13

    Detect empty lines while reading from file

  14. 14

    Writing to an excel using Apache POI corrupts the excel file

  15. 15

    Reading from a txt file in Java

  16. 16

    How to read input inside a while loop while reading from a file?

  17. 17

    Reading from a CSV file and writing to a new CSV file using openCSV in java

  18. 18

    Reading data from a file, only alpha characters

  19. 19

    reading data from file and breaking it into tokens

  20. 20

    create text reading data from a file

  21. 21

    Accessing Excel Sheets in Java using Apache POI with Eclipse IDE

  22. 22

    reading from a text file using fscanf()

  23. 23

    Reading text file in java using scanner

  24. 24

    Problems reading keys from properties file java

  25. 25

    Missing first row while reading from file - Python Pandas

  26. 26

    Scala writing and reading from a file inside a while loop

  27. 27

    python [regex] - search function is not working while reading lines from a file

  28. 28

    zcat skip streaming first line while reading from a compressed file

  29. 29

    Illegal Argument Exception while Reading XML File in Java

ホットタグ

アーカイブ