Tuan_H
(Tuan H)
1
Bước 1: Tạo 1 sheet mới tại đây: spreadsheet.new
Bước 2: Tạo App Script trên sheet đang sử dụng
Bước 3: Dán đoạn code bên dưới vào và lưu lại
/**
* App Script Google Sheet
* Chuyển số thành chữ tiền tệ Việt Nam Đồng.
* Sản phẩm của CỌP - Thành viên WPVNTEAM
* Vui lòng ghi rõ nguồn nếu sao chép lại code
*
* @param {number} input The value to convert.
* @return The number in VNĐ
*/
function VND(input) {
const output = [];
const ty = Math.floor(input / 1000000000);
if (input >= 1000000000) {
output.push(`${ty} tỷ`);
} else {
const ty = 0;
}
const trieu = Math.floor(input - (ty*1000000000));
const httrieu = Math.floor(trieu / 1000000);
if (trieu >= 1000000) {
output.push(`${httrieu} triệu`);
}
const nghin = ((ty*1000000000) + (httrieu*1000000));
const ssnghin = Math.floor(input - nghin);
const htnghin = Math.floor(ssnghin / 1000);
if (ssnghin >= 1000) {
output.push(`${htnghin} ngàn`);
}
const dong = ((ty*1000000000) + (httrieu*1000000) + (htnghin*1000));
const htdong = Math.floor(input - dong);
if (htdong > 0) {
output.push(`${htdong} đồng`);
}
return [...output, ''] //Before Price VNĐ
.join(' ')
.split(/\s/)
.filter((e) => e)
.map((e) => e.substr(0, 1).toUpperCase() + e.substr(1))
.join(' ');
}
//Điều kiện: số tiền phải lớn hơn 1 triệu
function BDS(input) {
const output = [];
const ty = input / 1000000000;
if (input >= 1000000000) {
output.push(`${ty.toLocaleString()} tỷ`);
} else {
const ty = 0;
const trieu = Math.floor(input - (ty*1000000000));
const httrieu = Math.floor(trieu / 1000000);
if (trieu < 1000000000 && trieu > 1000000) {
output.push(`${httrieu.toLocaleString()} triệu`);
}
}
return [...output, ''] //Before Price VNĐ
.join(' ')
.split(/\s/)
.filter((e) => e)
.map((e) => e.substr(0, 1).toUpperCase() + e.substr(1))
.join(' ');
}
Bước 4: Để sử dụng full text dùng hàm
=VND($bien)
Sử dụng cho sản phẩm là Bất Động Sản hoặc TMĐT dùng hàm
=BDS($bien)
[center]
[/center]
Vui lòng ghi rõ nguồn WPVNTEAM khi sao chép lại thông tin này.
Chúc các bạn thành công 
1 Lượt thích
Tuan_H
(Tuan H)
2
Hướng dẫn tạo nhanh các bảng tính Google
In your browser, enter one of these URLs:
Docs
docs.new
doc.new
document.new
Sheets
sheets.new
sheet.new
spreadsheet.new
Slides
slides.new
slide.new
presentation.new
Forms
forms.new
form.new
A blank file opens, and you can start editing right away.
Tuan_H
(Tuan H)
3
Update phiên bản 2.0
/**
* App Script Google Sheet v2
* Chuyển số thành chữ tiền tệ Việt Nam Đồng.
* Sản phẩm của TIẾN CỌP - Thành viên WPVNTEAM
* Vui lòng ghi rõ nguồn nếu sao chép lại code
*
* @param {number} input The value to convert.
* @return The number in VND
*/
function VND(input) {
const output = [];
const ty = Math.floor(input / 1000000000);
if (input >= 1000000000) {
output.push(`${phantram(ty)} tỷ`);
} else {
const ty = 0;
}
const trieu = Math.floor(input - (ty*1000000000));
const httrieu = Math.floor(trieu / 1000000);
if (trieu >= 1000000) {
output.push(`${phantram(httrieu)} triệu`);
}
const nghin = ((ty*1000000000) + (httrieu*1000000));
const ssnghin = Math.floor(input - nghin);
const htnghin = Math.floor(ssnghin / 1000);
if (ssnghin >= 1000) {
output.push(`${phantram(htnghin)} nghìn`);
}
const dong = ((ty*1000000000) + (httrieu*1000000) + (htnghin*1000));
const htdong = Math.floor(input - dong);
if (htdong > 0) {
output.push(`${phantram(htdong)}`);
}
const tens = input % 100;
if (tens > 0) {
if (input > 100) output.push('lẻ');
output.push(`${phantram(tens)}`);
}
return [...output, 'đồng'] //Before Price VNĐ
.join(' ')
.split(/\s/)
.filter((e) => e)
.map((e) => e.substr(0, 1).toLowerCase() + e.substr(1)) //Chữ In Hoa toUpperCase()
.join(' ');
}
function mot(number) {
const motso = ['', 'một', 'hai', 'ba', 'bốn', 'năm', 'sáu', 'bảy', 'tám', 'chín'];
return motso[number] || '';
}
function muoi(number) {
const teens = ['mười','mười một','mười hai','mười ba','mười bốn','mười lăm','mười sáu','mười bảy','mười tám','mười chín'];
return teens[number] || '';
}
function haimuoi(number) {
const tens = ['', '', 'hai mươi', 'ba mươi', 'bốn mươi', 'năm mươi', 'sáu mươi', 'bảy mươi', 'tám mươi', 'chín mươi'];
return tens[number] || '';
}
function mottram(number) {
const mts = ['không trăm', 'một trăm', 'hai trăm', 'ba trăm', 'bốn trăm', 'năm trăm', 'sáu trăm', 'bảy trăm', 'tám trăm', 'chín trăm'];
return mts[number] || '';
}
function phantram(num) {
if (num > 0 && num < 10) {
return mot(num);
}
if (num >= 10 && num < 20) {
return muoi(num % 10);
}
if (num >= 20 && num < 100) {
return `${haimuoi(Math.floor(num / 10))} ${mot(num % 10)}`;
}
if (num >= 100 && num < 1000) {
const atram = Math.floor(num / 100);
const amuoi = (num - (atram * 100)) / 10;
const aso = num % 10;
return `${mottram(atram)} ${haimuoi(amuoi)} ${mot(aso)}`;
}
return '';
}
function VNDN(input) {
const output = [];
const ty = Math.floor(input / 1000000000);
if (input >= 1000000000) {
output.push(`${ty} tỷ`);
} else {
const ty = 0;
}
const trieu = Math.floor(input - (ty*1000000000));
const httrieu = Math.floor(trieu / 1000000);
if (trieu >= 1000000) {
output.push(`${httrieu} triệu`);
}
const nghin = ((ty*1000000000) + (httrieu*1000000));
const ssnghin = Math.floor(input - nghin);
const htnghin = Math.floor(ssnghin / 1000);
if (ssnghin >= 1000) {
output.push(`${htnghin} nghìn`);
}
const dong = ((ty*1000000000) + (httrieu*1000000) + (htnghin*1000));
const htdong = Math.floor(input - dong);
if (htdong > 0) {
output.push(`${htdong}`);
}
return [...output, 'đồng'] //Before Price VNĐ
.join(' ')
.split(/\s/)
.filter((e) => e)
.map((e) => e.substr(0, 1).toLowerCase() + e.substr(1)) //Chữ In Hoa toUpperCase()
.join(' ');
}
Để sử dụng chữ dùng hàm
=VND($bien)
Để sử dụng số + chữ dùng hàm
=VNDN($bien)
Cám ơn các bạn đã đóng góp ý kiến để hoàn thiện hơn 
1 Lượt thích
Hai_Man
(Hai Man)
4
Cảm ơn Tiến Cọp đã tạo app script rất hữu dụng.
Khi sử dụng phiên bản 2.0 mình có gặp lỗi ở ảnh mong bạn kiểm tra hỗ trợ giúp
