惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Webroot Blog
Webroot Blog
U
Unit 42
A
About on SuperTechFans
宝玉的分享
宝玉的分享
月光博客
月光博客
C
CERT Recently Published Vulnerability Notes
P
Privacy International News Feed
Microsoft Security Blog
Microsoft Security Blog
G
Google Developers Blog
P
Privacy & Cybersecurity Law Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
S
Securelist
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Spread Privacy
Spread Privacy
L
Lohrmann on Cybersecurity
Apple Machine Learning Research
Apple Machine Learning Research
K
Kaspersky official blog
Hugging Face - Blog
Hugging Face - Blog
B
Blog
I
Intezer
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
V
V2EX
L
LangChain Blog
AI
AI
G
GRAHAM CLULEY
T
Tor Project blog
人人都是产品经理
人人都是产品经理
D
Docker
WordPress大学
WordPress大学
Google DeepMind News
Google DeepMind News
I
InfoQ
Y
Y Combinator Blog
C
Comments on: Blog
GbyAI
GbyAI
www.infosecurity-magazine.com
www.infosecurity-magazine.com
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tailwind CSS Blog
aimingoo的专栏
aimingoo的专栏
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
腾讯CDC
N
News and Events Feed by Topic
MyScale Blog
MyScale Blog
H
Help Net Security
Vercel News
Vercel News
T
Tenable Blog
博客园 - 三生石上(FineUI控件)
爱范儿
爱范儿

博客园 - 温温恭人

[导入]:创建单色画笔 (Visual C#) [导入]在运行时创建位图 (Visual C#) [导入]创建笔 (Visual C#) [导入]。net图形操作(MSDN) [导入]如何动态生成table(javascript) [导入]javascript分页 [导入]贡献一个新浪的幻灯片(javascript) [导入]解析XML并生成表格 [导入]css控制div居中 [导入]精典的一句 [导入]通过简易的前台代码实现无限二级域名转向(来自无忧 biyuan老矣) [导入]巧妙的让web来执行“计划任务”(转 biyuan老矣 ) [导入]由浅到深了解JavaScript类 - 温温恭人 [导入]DHTML中重要的属性方法 - 温温恭人 [导入](转贴)正则表达式学习心得体会(5) [导入](转贴)正则表达式学习心得体会(4) [导入]正则表达式学习心得体会(3)(转) [导入]正则表达式学习心得体会(2) [导入](转贴)正则表达式学习心得体会(1) - 温温恭人 [导入]使用透明叠加法美化文件上传界面 (http://www.script8.com/bbs/thread.asp?tid=6) [导入]用Javascript实现interface的类似功能 [导入]javascript总结 [导入]input高级限制级用法 [导入] js实现的动态多文件上传 (来自http://cms.bmw.net.cn) [导入]js用FileSystemObject 对象实现文件控制
[导入]将程序集链接到 Word 或 Excel 文件
温温恭人 · 2007-06-19 · via 博客园 - 温温恭人

如何:将程序集链接到 Word 或 Excel 文件

包含托管代码扩展的 Microsoft Office 2003 文档需要具有指向它的关联程序集的路径。此路径及程序集名称存储于文档的自定义属性 _AssemblyLocation0_AssemblyName0 中。路径必须具有以下格式之一:

  • 绝对路径 (C:\Assemblies\)
  • 相对路径 (\Assemblies\)
  • HTTP (http://www.contoso.com/assemblies/)
  • UNC (\\AssemblyServer\Assemblies\)

有关有效路径的更多信息,请参见“程序集链接位置”属性

如果程序集名称或位置的长度超过 255 个字符,将按编号顺序在 Office 文档中添加更多的自定义属性以包含超出的字符。例如,如果程序集位置包含 300 个字符,则需要两个属性:_AssemblyLocation0_AssemblyLocation1

在 Word 或 Excel 文件中设置程序集名称和位置

可在 Word 或 Excel 文件的自定义属性中设置程序集名称和位置,有以下三种方法:

  • 在 Visual Studio .NET 中使用“属性”窗口(建议)。
  • 运行用于设置属性的脚本。
  • 在文档中手动设置属性,既可以在 Windows 资源管理器中也可在应用程序自身中进行设置。

不是所有文档格式都支持自定义属性。例如,如果将文档保存为文本文件 (.txt),则不保存程序集信息。

在 Visual Studio .NET 中使用“属性”窗口将程序集链接到文件

  • 在生成解决方案之前,在“属性”窗口中将“程序集链接位置”项目属性设置为程序集的位置。

在 Visual Studio .net 项目中使用“属性”窗口有助于在项目与部署的解决方案之间保持同步。

使用脚本将程序集链接到文件

通过脚本使用 Persistence Control 更改文档中的 _AssemblyLocation0 自定义属性。

  1. 创建一个脚本,以实例化该控件并调用希望使用的方法。有关方法的详细信息,请参见 Persistence Control 方法

    例如,使用 JScript:

    // JScript
        if (WScript.Arguments.Length < 3)
        {
        print("Usage: SetAssemblyNameAndLocation <document> <assembly> <location>")
        print("")
        print("  <document> is the name of a Word document or Excel spreadsheet")
        print("  <assembly> is the name of the assembly, without the extension")
        print("  <location> can be a relative path, and should end in a slash")
        WScript.Quit(1)
        }
        var doc = WScript.Arguments(0)
        var asm = WScript.Arguments(1)
        var loc = WScript.Arguments(2)
        print("Updating '" + doc + "', setting assembly='" + asm + "' and location='" + loc + "'")
        try
        {
        var control = new ActiveXObject("OfficeToolkit.Persistence")
        control.SetAssemblyNameAndLocation(doc, asm, loc)
        print("Success!")
        }
        catch(e)
        {
        print("Error:")
        print(e.number + ": " + e.description)
        WScript.Quit(2)
        }
        function print(s)
        {
        WScript.Echo(s)
        }

    以下代码使用 VBScript 演示同一个示例:

    ' VBScript
        If (WScript.Arguments.Length < 3) Then
        print "Usage: SetAssemblyNameAndLocation <document> <assembly> <location>"
        print ""
        print "  <document> is the name of a Word document or Excel spreadsheet"
        print "  <assembly> is the name of the assembly, without the extension"
        print "  <location> can be a relative path, and should end in a slash"
        WScript.Quit 1
        End If
        Dim doc
        Dim asm
        Dim loc
        doc = WScript.Arguments(0)
        asm = WScript.Arguments(1)
        loc = WScript.Arguments(2)
        print "Updating '" & doc & "', setting assembly='" & asm & _
        "' and location='" & loc & "'"
        On Error Resume Next
        Dim control
        Set control = CreateObject("OfficeToolkit.Persistence")
        control.SetAssemblyNameAndLocation doc, asm, loc
        If (Err.Number <> 0) Then
        print "Error:"
        print Err.Number & ": " & Err.Description
        WScript.Quit 2
        End If
        On Error Goto 0
        print "Success!"
        Sub print(s)
        WScript.Echo s
        End Sub
  2. 使用有具体含义的名称保存文件,并在文件名末尾添加扩展名 .js(使用 JScript)或 .vbs(使用 VBScript)。
  3. 打开命令提示。
  4. 将目录更改为保存脚本文件的位置。
  5. 键入脚本文件的名称(不带扩展名),后跟三个参数(按以下顺序):
    <script file> <document name> <assembly name> <deployment location>
  6. ENTER 键。

此示例脚本对加密的工作簿或非本机文件类型(如 HTML 或 MHT)无效。有关更多信息,请参见安全部署中的“部署加密的 Excel 工作簿”。

通过在 Word 或 Excel 中手动更改属性来链接程序集

  1. 在 Word 或 Excel 中打开文档。
  2. 打开“文件”菜单,单击“属性”。

    文档或工作簿的“属性”对话框随即打开。

  3. 单击“自定义”选项卡。
  4. 在“属性”列表中,选择 _AssemblyLocation0

    用该属性的数据填充位于对话框顶部的字段。

  5. 将包含程序集的目录的路径添加到“值”字段。
    注意   Windows 资源管理器在“属性”对话框的“值”字段中不接受长度超过 255 个字符的值。
  6. 在“属性”列表中选择 _AssemblyName0
  7. 将程序集的名称(不带文件扩展名)添加到“值”字段。
  8. 单击“确定”。

通过使用 Windows 资源管理器手动更改属性来链接程序集

  1. 打开 Windows 资源管理器,浏览至文档或工作簿,然后选中它。
  2. 打开“文件”菜单,单击“属性”。

    文档或工作簿的“属性”对话框随即打开。

  3. 单击“自定义”选项卡。

    “自定义”选项卡上的“属性”列表中不显示自定义文档属性,但您仍可通过手动键入名称和值来更改属性值。

    注意   如果打开了没有自定义属性的文档或工作簿,“自定义”选项卡不会显示在任何文档或工作簿的“属性”对话框中。如果在“属性”对话框中看不到“自定义”选项卡,请关闭所有打开的文档或工作簿,然后重新启动此过程。
  4. 在“名称”字段中,键入 _AssemblyLocation0
  5. 在“值”字段中键入包含程序集的目录的路径。
    注意   Windows 资源管理器在“属性”对话框的“值”字段中不接受长度超过 255 个字符的值。
  6. 在“名称”字段中键入 _AssemblyName0
  7. 在“值”字段中键入程序集的名称(不带文件扩展名)。
  8. 单击“确定”。

文章来源:http://www.cnblogs.com/suiqirui19872005/archive/2007/06/03/769674.html