By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,275 Members | 1,990 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,275 IT Pros & Developers. It's quick & easy.

How do you set Accounting format in Google Script App?

P: 208
In the function below, I am using column H to adjust the format of column F. I would like to adjust this format to an accounting format, but I am struggling to do so. Does anyone know how to convert this string, "USD":"[Red][$$]#,##0.00", to an accounting format in the Google Script App?

Expand|Select|Wrap|Line Numbers
  1. function onEdit(e){
  3.     var sheetName = "Debt"; //name of sheet to adjust formatting on
  4.     var currencyCol = 8; //column H
  5.     var amountCol = 6; //column F
  6.     var defaultFormat = "[$]#,##0.00";
  7.     var currencyFormat = {"USD":"[Red][$$]#,##0.00",
  8.                           "GBP":"[Red][$]#,##0.00",
  9.                           "EUR":"[Red][$]#,##0.00"};
  11.     var r = e.range;
  12.     if(e.source.getSheetName()==sheetName && r.getColumn() == currencyCol){ //edits one cell at a time
  13.       var uf = currencyFormat[r.getValue()];
  14.       uf = uf?uf:defaultFormat;
  15.       r.offset(0,amountCol-currencyCol).setNumberFormat(uf);
  16.     }
  17. }
3 Weeks Ago #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.