























包含托管代码扩展的 Microsoft Office 2003 文档需要具有指向它的关联程序集的路径。此路径及程序集名称存储于文档的自定义属性 _AssemblyLocation0 和 _AssemblyName0 中。路径必须具有以下格式之一:
C:\Assemblies\)
\Assemblies\)
http://www.contoso.com/assemblies/)
\\AssemblyServer\Assemblies\) 有关有效路径的更多信息,请参见“程序集链接位置”属性。
如果程序集名称或位置的长度超过 255 个字符,将按编号顺序在 Office 文档中添加更多的自定义属性以包含超出的字符。例如,如果程序集位置包含 300 个字符,则需要两个属性:_AssemblyLocation0 和 _AssemblyLocation1。
可在 Word 或 Excel 文件的自定义属性中设置程序集名称和位置,有以下三种方法:
不是所有文档格式都支持自定义属性。例如,如果将文档保存为文本文件 (.txt),则不保存程序集信息。
在 Visual Studio .NET 中使用“属性”窗口将程序集链接到文件
在 Visual Studio .net 项目中使用“属性”窗口有助于在项目与部署的解决方案之间保持同步。
使用脚本将程序集链接到文件
通过脚本使用 Persistence Control 更改文档中的 _AssemblyLocation0 自定义属性。
例如,使用 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
<script file> <document name> <assembly name> <deployment location>
此示例脚本对加密的工作簿或非本机文件类型(如 HTML 或 MHT)无效。有关更多信息,请参见安全部署中的“部署加密的 Excel 工作簿”。
通过在 Word 或 Excel 中手动更改属性来链接程序集
文档或工作簿的“属性”对话框随即打开。
用该属性的数据填充位于对话框顶部的字段。
注意 Windows 资源管理器在“属性”对话框的“值”字段中不接受长度超过 255 个字符的值。
通过使用 Windows 资源管理器手动更改属性来链接程序集
文档或工作簿的“属性”对话框随即打开。
“自定义”选项卡上的“属性”列表中不显示自定义文档属性,但您仍可通过手动键入名称和值来更改属性值。
注意 如果打开了没有自定义属性的文档或工作簿,“自定义”选项卡不会显示在任何文档或工作簿的“属性”对话框中。如果在“属性”对话框中看不到“自定义”选项卡,请关闭所有打开的文档或工作簿,然后重新启动此过程。
注意 Windows 资源管理器在“属性”对话框的“值”字段中不接受长度超过 255 个字符的值。
文章来源:http://www.cnblogs.com/suiqirui19872005/archive/2007/06/03/769674.html
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。