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.