delphi OleContainer 预览操作word 并隐藏菜单栏

 uses  activex;

delphi 操作OleContainer  显示word   并隐藏菜单栏,xe10  测试通过

var
  lsql,ldocname: string;
  lWord :Variant;
  lDoc :Variant;
  i,lcount: Integer;
  ioip: IOleInPlaceObject;

begin
  try
    lWord := CreateOleObject('Word.Application');
    lWord.Visible := false;
  except
    messagebox(0,'创建word对象失败,请安装office!','警告',MB_OK+MB_ICONINFORMATION);
    exit;
  end;
  try
    lDOC := lWord.Documents.Add;
{对于Word的新页面}
    lWord.Selection.Font.Name := '微软雅黑';
    lWord.Selection.Font.Size := 20;
    lWord.Selection.Font.Bold := 2;
    lWord.Selection.paragraphs.Alignment := wdAlignParagraphCenter;
    lWord.Selection.TypeText(' 客户信息 ');
    lWord.Selection.Typeparagraph; //换行
    lWord.Selection.Typeparagraph; //换行
    lWord.Selection.paragraphs.Alignment := wdAlignParagraphLeft;
    lWord.Selection.Font.Size := 12;
    lWord.Selection.Font.Bold := 2;
    lWord.Selection.TypeText(' 基本信息:');
    lWord.Selection.Typeparagraph;
    lWord.Selection.TypeText('团计划发出,各地请按下列行程做接待,并及早落实' + '团队计划和选派优秀导游员。各地代订住宿、火车票、机票务必安排好接待,日程' + '如有变更,及时与下站接待社或本社联系,各地接团时请举【xxxx欢迎你】接站牌。');
    lWord.Selection.Typeparagraph; //换行
    lWord.Selection.Typeparagraph; //换行
    lWord.Selection.TypeText('请速回传真确认,谢谢合作!');
    lWord.Selection.Typeparagraph; //换行
    lWord.Selection.Typeparagraph; //换行

    lWord.Selection.TypeText('人数:');
    lWord.Selection.TypeText('0');
    lWord.Selection.TypeText('国籍:');
    lWord.Selection.TypeText('I DO NOT KNOW');
    lWord.Selection.TypeText('等级:');
    lWord.Selection.TypeText('8星级');
    lWord.Selection.Typeparagraph; //换行
    lWord.Selection.TypeText('这里是团队安排');
    lWord.Selection.Typeparagraph; //换行
    lWord.Selection.TypeText('早上:起床 然后 饿一顿--->减肥');
    lWord.Selection.Typeparagraph; //换行
    lWord.Selection.TypeText('中午:运动完毕 然后 饿一顿--->减肥');
    lWord.Selection.Typeparagraph; //换行
    lWord.Selection.TypeText('晚上:自己搭车回家 然后 请 饿一顿--->未饿死的减肥成功!');
    lWord.Selection.Typeparagraph; //换行
    lWord.Selection.TypeText('TO: ');
    lWord.Selection.TypeText('12345678901234567890');
    lWord.Selection.Typeparagraph; //换行
    lWord.Selection.TypeText('TEL: ');
    lWord.Selection.TypeText('12345678901234567890');
    lWord.Selection.Typeparagraph; //换行
    lWord.Selection.TypeText('FAX: ');
    lWord.Selection.TypeText('12345678901234567890');
    lWord.Selection.Typeparagraph; //换行
    lWord.Selection.Typeparagraph; //换行
    lWord.Selection.TypeText('______________________________________________');
    lWord.Selection.Typeparagraph; //换行
    lWord.Selection.Typeparagraph; //换行
    lWord.Selection.TypeText('FROM: ');
    lWord.Selection.TypeText('中国XXXX地');
    lWord.Selection.Typeparagraph; //换行
    lWord.Selection.TypeText('TEL: ');
    lWord.Selection.TypeText('久动久动久不动');
    lWord.Selection.Typeparagraph; //换行
    lWord.Selection.TypeText('FAX: ');
    lWord.Selection.TypeText('你猜你猜你猜猜猜');
    lWord.Selection.Typeparagraph; //换行

  except
    on e: Exception do
      Messagebox(0, Pchar(e.Message), '警告', MB_OK + MB_ICONINFORMATION);
  end;
//保存文档
  ldocname := ExtractFilePath(application.ExeName) + 'Report\temp.doc';
  lWord.Caption := '组团计划保存在: ' + ldocname;
  lDOC.SaveAS(ldocname);
  lWord.Quit;
  lWord := Unassigned;
  lolec.CreateObjectFromFile(ldocname, false);
  lolec.DoVerb(ovShow);

//隐藏菜单栏 (找了N种方法,这种成功了)
  if (lolec.State = osUIActive) then
  begin

    if (SUCCEEDED(lolec.OleObjectInterface.QueryInterface(IOleInPlaceObject, ioip))) then
    begin
      ioip.UIDeactivate();
    end
  end;

 

    原文作者:黑贝是条狗
    原文地址: https://blog.csdn.net/y281252548/article/details/87863183
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞