poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "rakesh.dev" <rakesh....@kudosedge.in>
Subject Re: Round to one Decimal place not happenning using " style.setDataFormat(format.getFormat("0.0")); "
Date Tue, 08 Mar 2011 06:47:24 GMT
Hi,

somehow the cell type is still General even after setting the type to
numeric as shownin code below.
here i am setting decimal zero for some columns and one for some which is
stored in string array.


HSSFCellStyle stylezero = wb.createCellStyle();
	 HSSFDataFormat dfzero = wb.createDataFormat();
	 stylezero.setDataFormat(dfzero.getFormat("0"));
	 stylezero.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
	 HSSFCellStyle styleone = wb.createCellStyle();
	 HSSFDataFormat dfone = null;
	 dfone = wb.createDataFormat();
	 styleone.setDataFormat(dfone.getFormat("0.0"));
	 styleone.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
	 
     DecimalFormat decFormat = null; 
     decFormat = new DecimalFormat( "0.0;'-'0.0" ); 
	String[] decimalPlace = this.decimalPlace.split("\\,");
	int dpsizes= decimalPlace.length;
	if (dpsizes!= 0)
	{
		for(int j=0;j<dpsizes;j++)
		{
			String tt = decimalPlace[j];
			String[] mm =tt.split("\\.");
			CellReference vals = new CellReference(mm[0]);
			 int colValue= vals.getCol();
			
			
			 
			 for (int i=14;i<rows;i++)
			    {
		HSSFCell  y=   wb.getSheetAt(0).getRow(i).getCell((short) colValue);
		
		if (y.getCellType() == HSSFCell.CELL_TYPE_STRING) {
			
		} else if (y.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
			
			float d=(float) y.getNumericCellValue();
			if (mm[1].equalsIgnoreCase("zero"))
				 {
			     y.setCellStyle(stylezero);
				
				 }
				 else if (mm[1].equalsIgnoreCase("one"))
				 {
						
					 double value = y.getNumericCellValue();
					 String strValue = decFormat.format(value);
					 value = Double.parseDouble(strValue); 
					 y.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                     y.setCellValue(value); 
					 y.setCellStyle(styleone);
					 
					 
					
					 
				 }
				 else
				 {
					 System.out.println("shouldnt enter this loop");
				 }
			
		} else  {
			System.out.println("The cell was nothing we're interested in");
		}
			    }
			 
			
		}
	}

Please help me on this.

Thanks
Rakesh

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Round-to-one-Decimal-place-not-happenning-using-style-setDataFormat-format-getFormat-0-0-tp3404980p3413576.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


Mime
View raw message