如何在 MS Word 中自定义引用样式? [英] How to make custom citation style in MS Word?

查看:96
本文介绍了如何在 MS Word 中自定义引用样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要在 MS Word 中创建自定义引文样式,我按照此网页中的说明进行操作 https://msdn.microsoft.com/en-us/vba/word-vba/articles/create-custom-bibliography-styles

to make a custom citation style in MS Word I followed the instructions in this webpage https://msdn.microsoft.com/en-us/vba/word-vba/articles/create-custom-bibliography-styles

并按照此页面中的步骤操作:https://blogs.office.com/en-us/2009/04/29/bibliography-citations-102-building-custom-styles/

and also followed the steps in this page: https://blogs.office.com/en-us/2009/04/29/bibliography-citations-102-building-custom-styles/

两种方法都不起作用,新样式没有出现在Word的样式列表中,我有word 2016.如果有另一种方法可以在不使用xsl的情况下创建自定义样式,我想知道如何.

both method didn't work, the new style don't show up in Style list in Word, I have word 2016. If there is another way to create custom style without using xsl I would like to know how.

推荐答案

我也研究了自定义样式,但放弃了这个想法,正如您所说,该方法不起作用(甚至在每页的结尾).

I looked into the custom styles as well but abandoned the idea as, just like you said, the method didn't work (not even the final code samples at the end of each page).

我最终使用了 Visual Basic,因为您实际上可以通过这种方式访问​​书目数据,因此您可以使用 VBA 和内容控件重现引用行为.(我没有复制引文而是参考书目)

I ended up using visual basic, as you can actually access the bibliography data this way, so you may be able to reproduce the citation behavior using VBA and content controls. (I didn't reproduce the citations but the bibliography)

要使用内容控件,您需要在设置中启用开发者工具.现在,您插入内容控件,而不是实际引用,其标题和标签与您要引用的来源相对应.(例如,给它一个像 cit_auto 这样的标题和一个与你的源标签相对应的标签)您需要在开发者工具中启用编辑模式"(?) 才能访问控件的属性.

To use the content controls you need to enable the developer tools in the settings. Now, instead of actual citations, you insert content controls with titles and tags that correspond to the source you want to refer to. (E.g. give it a title like cit_auto and a tag corresponding to your source tag) You need to enable the 'edit mode'(?) in the developer tools to access the properties of the controls.

现在,要访问当前文档的来源,您可以使用 ActiveDocument.Bibliography.Sources.要获取所有来源,您可以使用 Application.Bibliography.Sources.

Now, to access the Sources of the current document you can use ActiveDocument.Bibliography.Sources. To get ALL Sources you can use Application.Bibliography.Sources.

请注意,Bibliography.Sources 是一个 Sources 对象,而不是一个 Source 数组.

Note that Bibliography.Sources is a Sources object, and not a Source array.

类似的问题发生在内容控件上.函数 ActiveDocument.SelectContentControlsByTitle 返回一个 ContentControls 对象,而不是一个 ContentControl 数组.

A similar issue happens with the content controls. The function ActiveDocument.SelectContentControlsByTitle returns a ContentControls object instead of a ContentControl array.

两者都可以使用它们的索引进行迭代和访问,但是您不能将它们作为其对应数组的参数传递,以防您想模块化代码.

Both can be iterated and accessed using their indices, however you cannot pass them as parameter for their corresponding array, in case you want to modularize the code.

可以在For Each中迭代ContentControls,通过匹配ContentControl.Tag选择对应的Source> 使用 Source.Field("Tag") 并将 ContentControl.Range.Text 设置为您想要的格式:

You can iterate the ContentControls in a For Each, select the corresponding Source by matching the ContentControl.Tag with the Source.Field("Tag") and set the ContentControl.Range.Text to the format you desire:

Public Sub FillSources()
    'assign variable types to get some form of autocomplete
    Dim cc As ContentControl
    Dim src As Source
    Dim srcs As Sources

    'get sources
    Set srcs = ActiveDocument.Bibliography.Sources

    'iterate through the 'cit-auto' controls
    For Each cc In ActiveDocument.SelectContentControlsByTitle("cit_auto")
        On Error GoTo catch 'pseudo Try
        For Each src In srcs 'look for the source of the citation
            If (src.field("Tag") = cc.Tag) Then
                cc.Range.text = _ 'results in: lastname, firstname: title (day.month.year)
                    src.field("Author/b:Author/b:NameList/b:Person:b/Last") & ", " & _
                    src.field("Author/b:Author/b:NameList/b:Person:b/First") & ": " & _
                    src.field("Title") & " (" & _
                    src.field("Day") & "." & _
                    src.field("Month") & "." & _
                    src.field("Year") & ")"
                End For 'source found, skip to next control
            End If
        Next
        GoTo finally
catch:  'pseudo Catch
        Debug.Print "source " & cc.Tag & " not found"
finally:'pseudo Finally
    Next
    Debug.Print "done"
End Sub

请注意,我没有对此进行测试,它可能会做得更好.

Note that i didn't test this and it can probably be done better.

如果缺少字段,Source.Field() 方法将抛出错误并被跳过.您可以为该方法制作一个包装器,以便在出现错误时插入默认值并使用它来构建您的样式.

If the fields are missing, the Source.Field() method will throw an error and it will be skipped. You can probably make a wrapper for the method to insert a default value in case of an error and use that to build your style.

如果您需要访问源的其他字段,您可以查看它的 .XML 属性,其中包含所有可用数据.您不需要在 xml 的第一层的名称上添加 b:-前缀,因为 .field() 方法会在它丢失时自动添加它.

If you need to access other fields of the source, you can look at it's .XML property, which contains all available data. You don't need to add the b:-prefix on the names of first layer of the xml, as the .field() method adds it automatically if it's missing.

我也不知道如何处理多个作者,但也许其他人知道.

Also i have no clue how to handle multiple authors, but maybe someone else knows.

这篇关于如何在 MS Word 中自定义引用样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆