今天时间晚了,给你个思路
在COM接口里,DELPHI自带的TTWordDocument下面有一个CustomProperties,利用它就可以实现了
你可以参考以下代码:
procedure TWordDoc.SetBuiltInProperty(Index : TOleEnum;
Const Value: Variant);
var
do
cumentProperties : OLEVariant;
do
cumentProperty : OLEVariant;
ovValue : OLEVariant;
begin
try
ovValue := Value;
do
cumentProperties := FComDoc.BuiltInDocumentProperties;
do
cumentProperty :=do
cumentProperties.Item [Index];
do
cumentProperty.Value := ovValue;
except
raise Exception.CreateFmt ('无法设置文档属性: "%d"', [Index]);
end;
end;
function TWordDoc.GetBuiltInProperty(Index : TOleEnum) : Variant;
var
do
cumentProperties : OLEVariant;
do
cumentProperty : OLEVariant;
begin
try
do
cumentProperties := FComDoc.BuiltInDocumentProperties;
do
cumentProperty :=do
cumentProperties.Item [Index];
Result :=do
cumentProperty.Value;
except
raise Exception.CreateFmt ('无法得到文档属性: "%d"', [Index]);
end;
end;
procedure TWordDoc.SetCustomProperty(Index : String;
Const Value : Variant);
var
CustomProperties : OLEVariant;
CustomProperty : OLEVariant;
ovValue : OLEVariant;
begin
try
CustomProperties := FComDoc.CustomDocumentProperties;
CustomProperty := CustomProperties.Item [Index];
ovValue := Value;
CustomProperty.Value := ovValue;
except
raise Exception.CreateFmt ('无法设置自定义属性: "%s"', [Index]);
end;
end;
function TWordDoc.GetCustomProperty(Index : String) : Variant;
//added by BDP 05/08/1999
var
CustomProperties : OLEVariant;
CustomProperty : OLEVariant;
begin
try
CustomProperties := FComDoc.CustomDocumentProperties;
CustomProperty := CustomProperties.Item [Index];
Result := CustomProperty.Value;
except
raise Exception.CreateFmt ('无法定位自定义属性: "%s"', [Index]);
end;
end;
procedure TWordDoc.AddCustomProperty(Index: String;
Value : Variant;
oePropertyType : TOleEnum);
var
CustomProperties : OLEVariant;
ovValue : OLEVariant;
begin
try
CustomProperties := FComDoc.CustomDocumentProperties;
ovValue := Value;
CustomProperties.Add(Index, wdFalse, oePropertyType, ovValue);
except
raise Exception.CreateFmt ('创建自定义属性: "%s"出错', [Index]);
end;
end;
procedure TWordDoc.AddCustomProperty(Index: String;
Value : String);
begin
AddCustomProperty (Index, Value, msoPropertyTypeString);
end;
procedure TWordDoc.AddCustomProperty(Index: String;
Value : Integer);
begin
AddCustomProperty (Index, Value, msoPropertyTypeNumber);
end;
procedure TWordDoc.AddCustomProperty(Index: String;
Value :do
uble);
begin
AddCustomProperty (Index, Value, msoPropertyTypeFloat);
end;
procedure TWordDoc.AddCustomProperty(Index: String;
Value : TDateTime);
begin
AddCustomProperty (Index, Value, msoPropertyTypeDate);
end;
procedure TWordDoc.AddCustomProperty(Index: String;
Value : Boolean);
begin
AddCustomProperty (Index, Value, msoPropertyTypeBoolean);
end;
procedure TWordDoc.DeleteCustomProperty(Index: String);
var
CustomProperties : OLEVariant;
CustomProperty : OLEVariant;
begin
try
CustomProperties := FComDoc.CustomDocumentProperties;
CustomProperty := CustomProperties.Item [Index];
if not VarIsNull (CustomProperty) then
CustomProperty.Delete;
except
raise Exception.CreateFmt ('删除自定义属性: "%s"出错', [Index]);
end;
end;
把FComDoc用TTWordDocument代替,我明天去学习,要不可以给你一个例子,不过相信你可以做出来