在书面表格中输入日期
Input Date to Written form
我正在尝试从相邻的单元格中写入一个输入日期。
即在 A1 中输入日期,B1 = A1 但以单词形式 (西班牙语).
我即将找到解决方案,但我确信会让事情变得比他们需要的更复杂。
日期列(A)
目前正在分成 3 个;
日(B)
、月(D)
、年(F)
、使用; =LEFT($A1;2)
、=MID($A1;4;2)
、=RIGHT($A1;4)
相应地。
在第 C
、E
、G
列中,我正在使用
=INDEX(IMPORTXML("https://www.buscapalabra.com/numeros-a-letras.html?cifra="&B1;"//li[1]//strong");1)
其中 B1
更改为 E1
,F1
取决于列
最后在 H
列中,我将在其中写入日期:
=trim(LOwer($C2&"de "&TEXT($D2;"mmmm")&" de "&$F2))&If(Value(Right($E2;1))=1;If(Value(MID($E2;4;1))<>1;"o";"");"")
出于某种原因,从站点返回的文本值的末尾有一个 space,并且没有正确地以 1 结尾的单词数字。因此使用 TRIM()
和嵌套的 IF()
它目前有效,我还没有完全测试它,但我很想听听人们的想法,我是表格的新手,但必须有一种更简洁的方法来做到这一点。
使用自定义函数:
您可以使用 Apps 脚本执行此操作 Custom Function。
首先,通过选择工具 > 脚本编辑器 打开一个绑定脚本,并将以下函数复制到脚本中(查看内联注释以获取更多信息):
function DATE_IN_WORDS(date) {
const day = date.getDate(); // Day of the month in numbers
const year = date.getFullYear(); // Year in numbers
const options = { month: 'long'};
const month = new Intl.DateTimeFormat('es-ES', options).format(date); // Month in words
const dayAndYear = [day, year].map(number => { // Retrieve word for day and year
const url = "https://www.buscapalabra.com/numeros-a-letras.html?cifra=" + number
const resp = UrlFetchApp.fetch(url).getContentText();
const first = "<em>Como sustantivo:</em> El <strong>";
const cut = resp.substring(resp.indexOf(first), resp.length);
let word = cut.substring(first.length, cut.indexOf("</strong>")); // Get desired section of HTML
if (number.toString().slice(-1) == "1" && number.toString().slice(-2) != "11") {
word = word.trim() + "o"; // Replace "un" with "uno"
let arrayWord = word.split(" ");
let lastWord = arrayWord.pop();
if (lastWord === "veintiúno") { // If 21, replace "ú" with "u"
lastWord = lastWord.replace("ú", "u");
arrayWord.push(lastWord);
word = arrayWord.join(" ");
}
return word;
} else return word;
});
return dayAndYear.join("de " + month + " de "); // Join day, month and year
}
此函数使用:
- Intl.DateTimeFormat 以西班牙语检索月份。
- UrlFetchApp 从
https://www.buscapalabra.com/numeros-a-letras.html
. 获取信息
定义后,您可以像使用任何工作表内置函数一样使用函数 DATE_IN_WORDS
。此函数将接受带有 Date
的单元格作为参数。
示例:
参考:
我正在尝试从相邻的单元格中写入一个输入日期。 即在 A1 中输入日期,B1 = A1 但以单词形式 (西班牙语).
我即将找到解决方案,但我确信会让事情变得比他们需要的更复杂。
日期列(A)
目前正在分成 3 个;
日(B)
、月(D)
、年(F)
、使用; =LEFT($A1;2)
、=MID($A1;4;2)
、=RIGHT($A1;4)
相应地。
在第 C
、E
、G
列中,我正在使用
=INDEX(IMPORTXML("https://www.buscapalabra.com/numeros-a-letras.html?cifra="&B1;"//li[1]//strong");1)
其中 B1
更改为 E1
,F1
取决于列
最后在 H
列中,我将在其中写入日期:
=trim(LOwer($C2&"de "&TEXT($D2;"mmmm")&" de "&$F2))&If(Value(Right($E2;1))=1;If(Value(MID($E2;4;1))<>1;"o";"");"")
出于某种原因,从站点返回的文本值的末尾有一个 space,并且没有正确地以 1 结尾的单词数字。因此使用 TRIM()
和嵌套的 IF()
它目前有效,我还没有完全测试它,但我很想听听人们的想法,我是表格的新手,但必须有一种更简洁的方法来做到这一点。
使用自定义函数:
您可以使用 Apps 脚本执行此操作 Custom Function。
首先,通过选择工具 > 脚本编辑器 打开一个绑定脚本,并将以下函数复制到脚本中(查看内联注释以获取更多信息):
function DATE_IN_WORDS(date) {
const day = date.getDate(); // Day of the month in numbers
const year = date.getFullYear(); // Year in numbers
const options = { month: 'long'};
const month = new Intl.DateTimeFormat('es-ES', options).format(date); // Month in words
const dayAndYear = [day, year].map(number => { // Retrieve word for day and year
const url = "https://www.buscapalabra.com/numeros-a-letras.html?cifra=" + number
const resp = UrlFetchApp.fetch(url).getContentText();
const first = "<em>Como sustantivo:</em> El <strong>";
const cut = resp.substring(resp.indexOf(first), resp.length);
let word = cut.substring(first.length, cut.indexOf("</strong>")); // Get desired section of HTML
if (number.toString().slice(-1) == "1" && number.toString().slice(-2) != "11") {
word = word.trim() + "o"; // Replace "un" with "uno"
let arrayWord = word.split(" ");
let lastWord = arrayWord.pop();
if (lastWord === "veintiúno") { // If 21, replace "ú" with "u"
lastWord = lastWord.replace("ú", "u");
arrayWord.push(lastWord);
word = arrayWord.join(" ");
}
return word;
} else return word;
});
return dayAndYear.join("de " + month + " de "); // Join day, month and year
}
此函数使用:
- Intl.DateTimeFormat 以西班牙语检索月份。
- UrlFetchApp 从
https://www.buscapalabra.com/numeros-a-letras.html
. 获取信息
定义后,您可以像使用任何工作表内置函数一样使用函数 DATE_IN_WORDS
。此函数将接受带有 Date
的单元格作为参数。