简体   繁体   English

MS Word:将30天添加到当前日期字段

[英]MS Word: Add 30 days to current date field

I am trying to create a field that when the Word file is opened automatically displays the current date + 30 days in the format 11/04/2016. 我正在尝试创建一个字段,当打开Word文件时,该字段会自动以11/04/2016格式显示当前日期+ 30天。

I have looked into the non-trivial field format but it doesn't display anything: 我研究了非平凡的字段格式,但没有显示任何内容:

{ QUOTE "{ SET " Delay" "30" }
{  SET "DaysInMonth" { IF { CreateDate \@ "MM" } <> 2 
{  = ROUND(30.575*{ CreateDate \@ "MM" },0)-
ROUND(30.575*{ = { CreateDate \@ "MM" } -1 },0) }
{  IF {  = MOD( { CreateDate \@"yy" } , 4 ) } > 0 "28" "29" } } }
{ SET "NextMonth" {  IF {  CreateDate \@ "MM" } = 12 "1/97" 
"{ = {  CreateDate \@ "MM" } + 1 }/97 } }
{  IF {   = {  REF "Delay" } + { CreateDate \@ "dd" } } <= { REF"DaysInMonth" }
{ CreateDate \@ "MMMM { = {  REF "Delay" } + { CreateDate \@ "dd" } }, yyyy"}{ QUOTE { NextMonth \@ "MMMM" } 
{ = { REF "Delay" } + { CreateDate \@ "dd" } - { REF"DaysInMonth" } }, 
{ IF { CreateDate \@ "MM" } <> 12 { CreateDate \@ "yyyy" }
{ CreateDate \@ "{ = 1 + { CreateDate \@ "yyyy" } \# "xxxx" }" } } } }" }

I am trying this in Word 2007. 我正在Word 2007中尝试此操作。

I add an image here with the correct formatting to make sure that you can see the right formatting as this sometimes gets corrupted pasting it in. 我在此处添加了具有正确格式的图像 ,以确保您可以看到正确的格式,因为有时粘贴时会损坏。

在此处输入图片说明

This will give (today when I wrote this): 11/6/2016 这将给(今天当我写这篇文章时):11/6/2016

Remember that the braces {} cannot be simply typed in from the keyboard, you have to get Word to insert them using Ctrl-F9 or some other method. 请记住,括号{}不能简单地从键盘上输入,您必须让Word使用Ctrl-F9或其他方法将其插入。 Alt-F9 toggles display of all field codes. Alt-F9切换所有域代码的显示。 F9 updates field codes F9更新域代码

Also keep in mind that Regional Formatting is an important part to keep track off. 还请记住,区域格式是保持跟踪的重要部分。 In my case above, the Round function takes the comma as decimal separator and semi-colon as list separator. 在上面的例子中,Round函数将逗号作为小数点分隔符,将分号作为列表分隔符。 This might be different in your location! 您所在的位置可能有所不同! Another thing to check is the double quotes, make sure these are the real double-quotes not the 'Word' double quotes: “” 要检查的另一件事是双引号,请确保这些是真正的双引号,而不是'Word'双引号: “”

I can't paste in the code as Word Field formatting is not just clear text. 我无法粘贴代码,因为Word字段格式不仅是纯文本。 You need to type it over (with exception of the braces, use Ctrl-F9 for that!) to make it work properly. 您需要将其键入(大括号除外,请使用Ctrl-F9!)以使其正常工作。 A lot of work and you need to check everything very carefully. 大量的工作,您需要非常仔细地检查所有内容。 It took me quite some time to get it right myself! 我花了一些时间自己搞定!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM