操作 WORD 画线


#import "office/MSO.DLL" rename("RGB", "msRGB")
#import "office/VBE6EXT.OLB" no_namespace  
#import "office/MSWORD.OLB" \
  rename("FindText", "msFindText")\
  rename("ExitWindows","ExitWindowsEx")

void DumpComError(_com_error &e) 
{
  _bstr_t bstrSource(e.Source());
  _bstr_t bstrDescription(e.Description());

  TCHAR szBuff[1024] = {0};
  _stprintf_s(szBuff, 
    _T("Oops - hit an error!\n")
    _T("\a\tCode = %08lx\n")
    _T("\a\tCode meaning = %s\n")
    _T("\a\tSource = %s\n")
    _T("\a\tDescription = %s\n"),
    e.Error(), 
    e.ErrorMessage(), 
    (LPCTSTR) bstrSource,
    (LPCTSTR) bstrDescription );
  TRACE(szBuff);
  AfxMessageBox(szBuff);
  ASSERT(0);
}

void TestWord()
{
  using namespace Office;
  using namespace Word;
  _ApplicationPtr pApp;
  _DocumentPtr pDoc;

  try
  {
    do
    {
      if(OleInitialize(NULL) != S_OK)
        break;

      if(pApp.CreateInstance(L"Word.Application") != S_OK)
        break;
      pApp->Visible = true;

      pDoc = pApp->GetDocuments()->Add();
      
      Word::LineFormatPtr pLine = pDoc->Shapes->AddLine(100, 100, 100, 200)->Line; //画线
      pLine->PutStyle(msoLineSingle); //Selection.ShapeRange.Line.Style = msoLineSingle //单根线
      pLine->PutWeight(6); //Selection.ShapeRange.Line.Weight = 6# //6磅
      pLine->PutDashStyle(msoLineLongDash); //Selection.ShapeRange.Line.DashStyle = msoLineLongDash //点画线
      pLine->ForeColor->PutRGB( RGB(51, 102, 255) ); // Selection.ShapeRange.Line.ForeColor.RGB = RGB(51, 102, 255) //线颜色

      //两段箭头
      pLine->put_BeginArrowheadStyle(msoArrowheadTriangle); //Selection.ShapeRange.Line.BeginArrowheadStyle = msoArrowheadTriangle
      pLine->put_EndArrowheadStyle(msoArrowheadTriangle); // Selection.ShapeRange.Line.EndArrowheadStyle = msoArrowheadTriangle
      pLine->put_BeginArrowheadWidth(msoArrowheadWidthMedium); //Selection.ShapeRange.Line.BeginArrowheadWidth = msoArrowheadWidthMedium
      pLine->put_BeginArrowheadLength(msoArrowheadLengthMedium); //Selection.ShapeRange.Line.BeginArrowheadLength = msoArrowheadLengthMedium

      //可见
      pLine->PutVisible(msoTrue); //Selection.ShapeRange.Line.Visible = msoTrue

      pDoc->Close();

      Sleep(1000);
      pApp->Quit();

      OleUninitialize();

    }while(0);
  }
  catch(_com_error &e) 
  {
    DumpComError(e); 
  }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值