有谁知道修改Word文档的属性值(例如 标题 作者等)的属性名是什么? (200分)

  • 主题发起人 主题发起人 hejiesi
  • 开始时间 开始时间
H

hejiesi

Unregistered / Unconfirmed
GUEST, unregistred user!
有谁知道修改Word文档的属性值(例如 标题 作者等)的属性名是什么? 还有怎样增加自定义
属性值?
 
分不够可以加的
 
你可以用宏做
 
详细怎样做, 主要是我想在Word文档里面加一些自己的属性, 然后可以在Word里面可以编辑那些
增加了的属性.
 
CommandBar:Office2000.CommandBar;
CommandBars:Office2000.CommandBars;
CommandBar_Control:Office2000.CommandBarControl;
CommandBars:=WordApplication.CommandBars;
CommandBar:=Nil;
Try
CommandBar:=CommandBars.Item[Name];
//如果有的话,先删除,再创建
CommandBar.Delete
CommandBar:=WordApplication.CommandBars.Add(Name,Position,Menubar,Temporary);
WordApplication.CommandBars.Item[Name].Set_Visible(True);
Except //如果没有的话,直接创建
CommandBar:=WordApplication.CommandBars.Add(Name,Position,Menubar,Temporary);
end;

以上只是在word上加了个下拉框,如果要加按扭只要改一点东西就可以了
 
To sword_liu,hjb_dydd
不好意思修改了帖子, 但分我会给的
 
今天时间晚了,给你个思路

在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代替,我明天去学习,要不可以给你一个例子,不过相信你可以做出来
 
看到上面的代码, 我还是不知道那些属性名, 能不能详细一点

to wk_knife:
可不可以把例子给我。
 
根据你的情况 uses office97 or office2000

然后打开.../Demos/Activex/Oleauto/SrvComp/Word的例子,在
procedure TMainForm.BtnInsertRecordClick(Sender: TObject);


var Template,NewTemplate,ItemIndex:OleVariant;
CustomProperties,ovValue : OLEVariant;
///////////////////////Add

procedure setfont;
begin

WordFont.ConnectTo(WordDocument.Sentences.Get_Last.Font);
if ChkBoxUnderline.checked then
WordFont.Underline := 2;
if ChkBoxBold.checked then
WordFont.Bold := 1;
if ChkBoxItalic.Checked then
WordFont.Italic := 1;
if ChkBoxEmboss.Checked then
WordFont.Emboss := 1;
if ChkBoxEngrave.checked then
WordFont.Engrave := 1;
if ChkBoxShadow.checked then
WordFont.shadow := 1;
if ChkBoxDoublestrike.checked then
WordFont.DoubleStrikeThrough := 1;
if ChkBoxStrike.checked then
WordFont.StrikeThrough := 1;
WordFont.Size := StrToInt(Size.text);
if Fonttype.Itemindex >= 0 then

WordFont.Name := FontType.Items[FontType.Itemindex];
end;


begin

try
Template := EmptyParam;
NewTemplate := True;
ItemIndex := 1;
try
Wordapplication.Connect;
except
MessageDlg('Word may not be installed', mtError, [mbOk], 0);
Abort;
end;

Wordapplication.Visible := True;
WordApplication.Caption := 'Delphi automation';
{Create newdo
cument}
Template := EmptyParam;
NewTemplate := False;
if ChkBoxNewDoc.Checked then

begin

WordApplication.Documents.Add(Template, NewTemplate);
{Assign WordDocument component}
WordDocument.ConnectTo(WordApplication.Documents.Item(ItemIndex));
end;

{Turn Spell checking of because it takes a long time if enabled and slowsdo
wn Winword}
WordApplication.Options.CheckSpellingAsYouType := False;
WordApplication.Options.CheckGrammarAsYouType := False;
{Insert data}
DBImgFishImg.CopyToClipboard;
WordDocument.Sentences.Last.Paste;
WordDocument.Range.InsertAfter('Common Name: ' + Table.Fields.Fields[2].AsString + #13);
SetFont;
WordDocument.Range.InsertAfter('Species Name:' + Table.Fields.Fields[3].AsString + #13);
WordDocument.Range.InsertAfter('Length: ' + Table.Fields.Fields[4].AsString + #13);
WordDocument.Range.InsertAfter(' ' + #13);
WordDocument.Range.InsertAfter(' ' + #13);
WordDocument.Range.InsertAfter(' ' + #13);
CustomProperties:=WordDocument.CustomDocumentProperties;////////////////////
ovValue :='abcdefg';////////////////////////////////////////////
CustomProperties.Add('abc', 0,msoPropertyTypeString, ovValue);//////////////////////这个msoPropertyTypeString定义在office97 or office2000中
BtnCloseWord.Enabled := True;
BtnPrint.Enabled := True;
BtnPreview.Enabled := True;
except
on E: Exceptiondo

begin

ShowMessage(E.Message);
WordApplication.Disconnect;
end;

end;

end;
 
多人接受答案了。
 
后退
顶部