You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by anjanajose <an...@gmail.com> on 2013/06/24 23:54:14 UTC

Currency format with three characters

Hi

I need help with creating format. I am trying to create a currency format
for Canadian currency. I have to format the amount as CAD#,##0.0000.

If I put CAD, it is not writing the format to excel, but if I put 'CA' or
'$CA', it works.

Can someone please help me figure out what is the issue? 

A sample code I wrote to write to excel is below.

                    Workbook wb = new HSSFWorkbook();
		    Sheet sheet = wb.createSheet("format sheet");
		    CellStyle style;
		    DataFormat format = wb.createDataFormat();
		    Row row;
		    Cell cell;
		    short rowNum = 0;
		    short colNum = 0; 

		    row = sheet.createRow(rowNum++);
		    cell = row.createCell(colNum);
		    cell.setCellValue(11111.25);
		    style = wb.createCellStyle();
		    style.setDataFormat(format.getFormat("CAD#,##0.0000"));
		    cell.setCellStyle(style);

		    FileOutputStream fileOut;
			try
			{
				fileOut = new FileOutputStream("c:/workbook.xls");
				 wb.write(fileOut);
				    fileOut.close();
			}
			catch (FileNotFoundException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			catch (IOException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Currency-format-with-three-characters-tp5713092.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


Re: Currency format with three characters

Posted by anjanajose <an...@gmail.com>.
Thank You Nick.
I found from excel that for putting CAD, it should be set as C\A\D. 

-Anjana



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Currency-format-with-three-characters-tp5713092p5713110.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


Re: Currency format with three characters

Posted by Nick Burch <ap...@gagravarr.org>.
On Mon, 24 Jun 2013, anjanajose wrote:
> I need help with creating format. I am trying to create a currency 
> format for Canadian currency. I have to format the amount as 
> CAD#,##0.0000.

If in doubt, put what you want into Excel, save the file, then read it 
from POI. That'll tell you what really gets stored in an excel file for 
that format, which is what you need to ask POI for

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org