Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Need help in excel data format for different cells

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,

I am facing problem in writing different data formats to excel. Please check the code below:

colorStyleFactors.setDataFormat(df.getFormat("0.0000")); //for fraction data
colorStyleNumber.setDataFormat(df.getFormat("0")); // for numbers
colorStyleRateAreaName.setDataFormat(df.getFormat("TEXT")); // for text/strings

// to write text
rowCell = newRow.createCell((short) 0);
rowCell.setCellStyle(colorStyleRateAreaName);
rowCell.setCellValue(rateFactorForm.getRateAreaName());

//to write number
rowCell=null;
rowCell = newRow.createCell((short) 1);
rowCell.setCellStyle(colorStyleNumber);
rowCell.setCellValue(rateFactorForm.getRateAreaNo());

// to write fractions or decimal values
rowCell=null;
rowCell = newRow.createCell((short) 2);
//rowCell.setCellStyle(colorStyleFactors);
rowCell.setCellValue(rateFactorForm.getSubs());
after executing this, all the excel cells contains data format as TEXT!! i dont know why and even though i set different formats for each cell. And what i actually found is when i change the order like below(order changed for fractions and number format);

colorStyleNumber.setDataFormat(df.getFormat("0")); // for numbers
colorStyleRateAreaName.setDataFormat(df.getFormat("TEXT")); // for text/strings
colorStyleFactors.setDataFormat(df.getFormat("0.0000")); //for fraction data

i got all the cells data format as decimals!!! i mean the last one takes the preference and write to all the cells... why its happening like this??? Please help me with this.




 
Nagaraj Shivaklara
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Report post to moderator
I am using apache poi 1.1 api..


Nagaraj Shivaklara wrote:Hi,

I am facing problem in writing different data formats to excel. Please check the code below:

colorStyleFactors.setDataFormat(df.getFormat("0.0000")); //for fraction data
colorStyleNumber.setDataFormat(df.getFormat("0")); // for numbers
colorStyleRateAreaName.setDataFormat(df.getFormat("TEXT")); // for text/strings

// to write text
rowCell = newRow.createCell((short) 0);
rowCell.setCellStyle(colorStyleRateAreaName);
rowCell.setCellValue(rateFactorForm.getRateAreaName());

//to write number
rowCell=null;
rowCell = newRow.createCell((short) 1);
rowCell.setCellStyle(colorStyleNumber);
rowCell.setCellValue(rateFactorForm.getRateAreaNo());

// to write fractions or decimal values
rowCell=null;
rowCell = newRow.createCell((short) 2);
//rowCell.setCellStyle(colorStyleFactors);
rowCell.setCellValue(rateFactorForm.getSubs());
after executing this, all the excel cells contains data format as TEXT!! i dont know why and even though i set different formats for each cell. And what i actually found is when i change the order like below(order changed for fractions and number format);

colorStyleNumber.setDataFormat(df.getFormat("0")); // for numbers
colorStyleRateAreaName.setDataFormat(df.getFormat("TEXT")); // for text/strings
colorStyleFactors.setDataFormat(df.getFormat("0.0000")); //for fraction data

i got all the cells data format as decimals!!! i mean the last one takes the preference and write to all the cells... why its happening like this??? Please help me with this.




 
Rancher
Posts: 43011
76
  • Likes 1
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please do not post the same question multiple times. Let's continue the discussion in this duplicate thread where you got an answer already.

I am using apache poi 1.1 api.


Really? Why? That must have been released in 2002. Since then there have been dozens of POI releases.
 
Paper beats rock. Scissors beats tiny ad.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!