mirror of
				https://github.com/gristlabs/grist-core.git
				synced 2025-06-13 20:53:59 +00:00 
			
		
		
		
	(core) Currency from grist column is persistent when exporting to excel
Summary: - when grist table is exported, currency is check and introduced in cell format in the form of "[currency symbol] [value]" (for example: zł 10000, $ 5000) . It's not what some cultures should display currences, but it's close enought - when no symbol is defined for the currency, currency 3 letters code is used instead - when currency is unknown, we are falling back to "$" Test Plan: - nbrowser test scenario added for that purpose, please check Currences.xlsx to see output format exported. Reviewers: georgegevoian Reviewed By: georgegevoian Differential Revision: https://phab.getgrist.com/D3886
This commit is contained in:
		
							parent
							
								
									8f34ba5157
								
							
						
					
					
						commit
						37347a79c0
					
				| @ -1,10 +1,11 @@ | ||||
| import {CellValue} from 'app/common/DocActions'; | ||||
| import * as gutil from 'app/common/gutil'; | ||||
| import * as gristTypes from 'app/common/gristTypes'; | ||||
| import * as gutil from 'app/common/gutil'; | ||||
| import {NumberFormatOptions} from 'app/common/NumberFormat'; | ||||
| import {FormatOptions, formatUnknown, IsRightTypeFunc} from 'app/common/ValueFormatter'; | ||||
| import {GristType} from 'app/plugin/GristData'; | ||||
| import {decodeObject} from 'app/plugin/objtypes'; | ||||
| import getSymbolFromCurrency from 'currency-symbol-map'; | ||||
| import {Style} from 'exceljs'; | ||||
| import moment from 'moment-timezone'; | ||||
| 
 | ||||
| @ -64,7 +65,13 @@ class BaseFormatter { | ||||
|     // those formats strings are the defaults that LibreOffice Calc is using.
 | ||||
|     if (this.widgetOptions.numMode) { | ||||
|       if (this.widgetOptions.numMode === 'currency') { | ||||
|         style.numFmt = '[$$-409]#,##0.00'; | ||||
|         // If currency name is undefined or null, it should be cast to unknown currency, because
 | ||||
|         // "getSymbolFromCurrency" expect argument to be string
 | ||||
|         const currencyName = this.widgetOptions.currency??""; | ||||
|         const currencySymbol = getSymbolFromCurrency(currencyName) | ||||
|           ?? this.widgetOptions.currency | ||||
|           ?? "$"; | ||||
|         style.numFmt = `"${currencySymbol} "#,##0.000`; | ||||
|       } else if (this.widgetOptions.numMode === 'percent') { | ||||
|         style.numFmt = '0.00%'; | ||||
|       } else if (this.widgetOptions.numMode === 'decimal') { | ||||
|  | ||||
| @ -130,6 +130,7 @@ | ||||
|     "cookie": "0.5.0", | ||||
|     "cookie-parser": "1.4.3", | ||||
|     "csv": "4.0.0", | ||||
|     "currency-symbol-map": "5.1.0", | ||||
|     "diff-match-patch": "1.0.5", | ||||
|     "dompurify": "3.0.0", | ||||
|     "double-ended-queue": "2.1.0-0", | ||||
|  | ||||
							
								
								
									
										
											BIN
										
									
								
								test/fixtures/docs/Currencies.grist
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								test/fixtures/docs/Currencies.grist
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								test/fixtures/export-xlsx/Currencies.xlsx
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								test/fixtures/export-xlsx/Currencies.xlsx
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -2747,6 +2747,11 @@ csv@4.0.0: | ||||
|     csv-stringify "^4.3.1" | ||||
|     stream-transform "^1.0.7" | ||||
| 
 | ||||
| currency-symbol-map@5.1.0: | ||||
|   version "5.1.0" | ||||
|   resolved "https://registry.yarnpkg.com/currency-symbol-map/-/currency-symbol-map-5.1.0.tgz#59531fbe977ba95e8d358e90e3c9e9053efb75ad" | ||||
|   integrity sha512-LO/lzYRw134LMDVnLyAf1dHE5tyO6axEFkR3TXjQIOmMkAM9YL6QsiUwuXzZAmFnuDJcs4hayOgyIYtViXFrLw== | ||||
| 
 | ||||
| cycle@1.0.x: | ||||
|   version "1.0.3" | ||||
|   resolved "https://registry.npmjs.org/cycle/-/cycle-1.0.3.tgz" | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user