“MMMM yy”-Google 电子表格中的日期

发布于 2024-12-17 07:03:32 字数 231 浏览 0 评论 0原文

我有一个 Google 电子表格,其中我想要一个仅包含月份和年份名称的日期,例如 2011 年 9 月,而且我还希望月份和年份能够轻松更改。 有没有办法获得自定义日期格式来做到这一点?

我想我可以这样做:

=TEXT(40295; "MMMM yy")

但是日期选择器不能再使用并且更改日期变得异常困难.. 有什么好的办法解决这个问题吗?

I have a google spreadsheet in which I want a date with only the name of the month and the year, like September 2011, and I also want the month and year to be easily changeable.
Is there any way of getting custom date formats to do this?

I figured out I could do like this:

=TEXT(40295; "MMMM yy")

But then the datepicker can't be used anymore and changing the date is made impossibly hard..
Is there any good way of solving this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

浊酒尽余欢 2024-12-24 07:03:32

您可以使用 Google Apps 脚本为单元格设置自定义格式。
打开脚本编辑器(菜单“工具”>“脚本编辑器”),粘贴此内容,保存并运行> onOpen。

function onOpen() {
  SpreadsheetApp.getActive().addMenu(
    'Format', [{name:'Custom', functionName:'customFormat'}]);
}

function customFormat() {
  var format = Browser.inputBox('Write the format to be applied on the seleted cells');
  if( format !== 'cancel' )
    SpreadsheetApp.getActiveRange().setNumberFormat(format);
}

在电子表格上,最后应该会出现一个新菜单,您可以在其中选择自定义条目来输入所选单元格的自定义格式。

You can set a custom format to a cell using Google Apps Script.
Open the script editor (menu Tools > Script editor), paste this, save and Run > onOpen.

function onOpen() {
  SpreadsheetApp.getActive().addMenu(
    'Format', [{name:'Custom', functionName:'customFormat'}]);
}

function customFormat() {
  var format = Browser.inputBox('Write the format to be applied on the seleted cells');
  if( format !== 'cancel' )
    SpreadsheetApp.getActiveRange().setNumberFormat(format);
}

On your spreadsheet a new menu should appear in the end where you can pick the Custom entry to enter your custom format for the selected cells.

情栀口红 2024-12-24 07:03:32

Google 电子表格尚不允许您将自定义数字格式应用于单元格。

您当然可以在一个单元格中输入日期,然后在第二个单元格中引用该日期:

A1:4/27/2010, A2=TEXT(A1;"MMMM yy")

这将满足您的要求:它将按照您想要的方式显示日期,并允许轻松更改日期。

但它有一个不良的副作用,即日期在工作表上出现两次。我经常通过打印或导出一个范围而不是整个工作表来解决这样的副作用。因此,也许您的情况还有一个实用的解决方法。

Google Spreadsheet does not yet permit you to apply a custom number format to a cell.

You can of course enter the date into a cell, and then reference that date in a second cell:

A1:4/27/2010, A2=TEXT(A1;"MMMM yy")

This would meet your requirements: it would display the date the way you wanted, and allow the date to be easily changeable.

But it has the undesirable side effect of having the date appearing twice on the sheet. I often work around side effects like this by printing or exporting a range instead of the entire sheet. So maybe there is also a practical workaround in your case.

柠檬 2024-12-24 07:03:32

我以为 yy 只给出两位数的年份。

我使用了以下内容:

=text(E2,"MMMM YYYY")

E2 是我使用的特定单元格,但您可以使用任何单元格。

I thought yy just gives the 2 digit year.

I used the following:

=text(E2,"MMMM YYYY")

E2 was the specific cell I used, but you could use any cell.

无悔心 2024-12-24 07:03:32

您可以输入任何格式(日期或其他格式)作为自定义数字格式。

突出显示单元格范围并转到“格式”>“数量>更多格式>>自定义数字格式。然后输入

mmmm" "yyyy

“September 2011”

或任何其他格式

ddd" "mm"/"dd"/"yyyy

将给出“Mon 09/11/2011”,

注意开头和结尾缺少的引号。
它显示了当您进行实验时它将如何显示。
开头或结尾的引号会导致格式无效
节省您的两个字段(数据和 text() 格式化字段)

它不直观(无论是格式还是放置位置)。但比导入 xls 效果更好。

You can enter any format (for dates or others) as a Custom Number Format.

Highlight the cell range and Go to Format > Number > More Formats > Custom Number Format. Then enter

mmmm" "yyyy

gives "September 2011"

or any other format

ddd" "mm"/"dd"/"yyyy

would give "Mon 09/11/2011"

note the missing quote at the beginning and the end.
it shows how it will display as you experiment.
Quotes in the beginning or end give you invalid format
Saves you having two fields (the data, and the text() formatted one)

Its not intuitive (either the format, or where to put it). But works better than importing an xls.

日暮斜阳 2024-12-24 07:03:32

我意外地找到了自定义日期格式的解决方法。我使用 Excel 自定义了日期格式。上传 Excel 文件时,日期格式 (mm/dd/yyyy hh:mm am/pm) 保持该格式,即使这不是受支持的 Google 表格格式。然后使用格式刷,我能够将该格式复制到 Google 表格中的其他单元格。我知道这不是一个理想的解决方案,但似乎可行。我还没有尝试过可以在 Excel 中创建多少其他自定义格式,转换为 Google Sheet,然后使用格式刷与其他单元格一起使用。

I accidentally found a workaround for a custom date format. I had a custom date format using Excel. When uploading the Excel file, the date format (mm/dd/yyyy hh:mm am/pm) stayed in that format even though that was not a supported Google Sheet format. Then using the format painter, I was able to copy that format to other cells within Google Sheet. I know this is not an ideal solution, but seems to work. I have not played with how many other custom formats I could create in Excel, convert to Google Sheet and then use format painter to use with other cells.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文