word文档里插入图片后,无法改边框颜色

hexx 2020-11-20 12:05:32
我的代码如下:
vShape = vWordDoc.OlePropertyGet("Shapes").OleFunction("AddPicture", WideString(strFileName), false, true, 0, 0);
vShape.OlePropertyGet("Line").OlePropertyGet("ForeColor").OlePropertySet("RGB", 0x202020);
vShape.OlePropertyGet("Line").OlePropertySet("Visible", true);
结果边框颜色并没改变,请问应怎样写?
...全文
360 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
青蛙工作室 2020-11-24
  • 打赏
  • 举报
回复
OleFunction的返回值可能并不是你想要的图片
ooolinux 2020-11-21
  • 打赏
  • 举报
回复
一些枚举常量值可以查msdn,查对应数字。 主要就是翻译成以下4个: OlePropertyGet OlePropertySet OleFunction OleProcedure
ooolinux 2020-11-21
  • 打赏
  • 举报
回复
我用word2003录制的宏,还不会翻译成C++,你可以试试看: Sub Macro1() ' ' Macro1 Macro ' 宏在 2020/11/21 Saturday 由 AutoBVT 录制 ' Selection.TypeText Text:="标题文字" Selection.TypeParagraph Selection.InlineShapes.AddPicture FileName:= _ "C:\Users\Administrator\Desktop\a.jpg", LinkToFile:=False, _ SaveWithDocument:=True Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend With Selection.InlineShapes(1) With .Borders(wdBorderLeft) .LineStyle = wdLineStyleDashDot .LineWidth = wdLineWidth300pt .Color = wdColorSkyBlue End With With .Borders(wdBorderRight) .LineStyle = wdLineStyleDashDot .LineWidth = wdLineWidth300pt .Color = wdColorSkyBlue End With With .Borders(wdBorderTop) .LineStyle = wdLineStyleDashDot .LineWidth = wdLineWidth300pt .Color = wdColorSkyBlue End With With .Borders(wdBorderBottom) .LineStyle = wdLineStyleDashDot .LineWidth = wdLineWidth300pt .Color = wdColorSkyBlue End With .Borders.Shadow = False End With With Options .DefaultBorderLineStyle = wdLineStyleDashDot .DefaultBorderLineWidth = wdLineWidth300pt .DefaultBorderColor = wdColorSkyBlue End With End Sub
ooolinux 2020-11-21
  • 打赏
  • 举报
回复
翻译了一下,运行效果如图:
// ---------------------------------------------------------------------------

#include <vcl.h>
#include <Comobj.hpp>
#pragma hdrstop

#include "Unit1.h"
// 为方便操作建立的宏
#define   PG   OlePropertyGet
#define   PS   OlePropertySet
#define   FN   OleFunction
#define   PR   OleProcedure
// ---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

// ---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
	Label1->Caption = L"OLE操作Word插入图片、设置边框并保存doc文档";
}

// ---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	Variant WordApp; // WordApplication

	try
	{
		WordApp = Variant::CreateObject(L"Word.Application");
	}
	catch (...)
	{
		Application->MessageBox(L"无法启动Word,请检查Word程序是否安装了。", L"操作Word",
			MB_OK | MB_ICONWARNING);
		return;
	}

	WordApp.PG(L"Documents").FN(L"Add"); // 新建一个文档
	Variant Selection = WordApp.PG(L"Selection");
	Selection.FN(L"TypeText", WideString(L"插入图片并设置边框")); // 输入文字
	Selection.PR(L"TypeParagraph"); // 输入回车
	UnicodeString exePath = ExtractFilePath(Application->ExeName); // EXE路径
	UnicodeString picPath = exePath + L"a.jpg";
	Selection.PG(L"InlineShapes").FN(L"AddPicture", WideString(picPath),
		0, 1); // 插入图片

	// 设置图片边框,从Word操作录制的宏VBA代码翻译,枚举值可查MSDN
	// Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
	Selection.FN(L"MoveLeft", 1, 1, 1);
	// With Selection.InlineShapes(1)
	Variant Shape1 = Selection.PG(L"InlineShapes").FN(L"Item", 1);
	// With .Borders(wdBorderLeft)
	Variant Border1 = Shape1.PG(L"Borders").FN(L"Item", -2);
	// .LineStyle = wdLineStyleDashDot
	Border1.PS(L"LineStyle", 6);
	// .LineWidth = wdLineWidth300pt
	Border1.PS(L"LineWidth", 24);
	// .Color = wdColorSkyBlue
	Border1.PS(L"Color", 16763904);
	// End With
	// With .Borders(wdBorderRight)
	Border1 = Shape1.PG(L"Borders").FN(L"Item", -4);
	// .LineStyle = wdLineStyleDashDot
	Border1.PS(L"LineStyle", 6);
	// .LineWidth = wdLineWidth300pt
	Border1.PS(L"LineWidth", 24);
	// .Color = wdColorSkyBlue
	Border1.PS(L"Color", 16763904);
	// End With
	// With .Borders(wdBorderTop)
	Border1 = Shape1.PG(L"Borders").FN(L"Item", -1);
	// .LineStyle = wdLineStyleDashDot
	Border1.PS(L"LineStyle", 6);
	// .LineWidth = wdLineWidth300pt
	Border1.PS(L"LineWidth", 24);
	// .Color = wdColorSkyBlue
	Border1.PS(L"Color", 16763904);
	// End With
	// With .Borders(wdBorderBottom)
	Border1 = Shape1.PG(L"Borders").FN(L"Item", -3);
	// .LineStyle = wdLineStyleDashDot
	Border1.PS(L"LineStyle", 6);
	// .LineWidth = wdLineWidth300pt
	Border1.PS(L"LineWidth", 24);
	// .Color = wdColorSkyBlue
	Border1.PS(L"Color", 16763904);
	// End With
	// .Borders.Shadow = False
	// End With
	// With Options
	// .DefaultBorderLineStyle = wdLineStyleDashDot
	// .DefaultBorderLineWidth = wdLineWidth300pt
	// .DefaultBorderColor = wdColorSkyBlue
	// End With

	// 保存Word文档并退出
	UnicodeString docPath = exePath + L"Doc1.doc";
	WordApp.PG(L"ActiveDocument").FN(L"SaveAs", WideString(docPath));
	WordApp.PG(L"ActiveDocument").PR(L"Close");
	WordApp.PR(L"Quit");
	WordApp = Unassigned;

	Application->MessageBox((L"已保存为 " + docPath).c_str(), L"保存Word文档",
		MB_OK | MB_ICONINFORMATION);
}
// ---------------------------------------------------------------------------
适用人群Word初学者、办公文秘、写作者、各行各业与Word打交道的人课程概述特别说明:本课程隶属于“365天个人职场技能成长训练营”,如果已经购买该课程,则不必购买本课程,请勿重复购买。课程目标通过全程实战案例快速掌握Word文字排版精髓,妙用样式、快捷键和通用模板实现一劳永逸适用人群Word初学者、办公文秘、写作者、各行各业与Word打交道的人课程简介本课程通过一个完整的实战案例,教你快速掌握使用Word进行文字样式定制、快捷键指定、将样式与通用模板绑定的全套方法,让你在以后的工作中,只需要输入文字后按快捷键就可以快速应用常用的样式,不必再每次输入后一一调整格式。特别适合经常跟Word文档打交道的人,例如长篇论文、产品手册、各种书籍排版等,用这种方法可以让你提高不止10倍工作效率。东东老师是微软认证Office办公软件讲师,策划出版过多本相关书籍,具有10年以上Office办公软件使用与培训经验,同时也是使用Word进行长文档(书籍)排版的日常实践者,对于长文档排版中样式与模板的使用具有非常丰富的经验。希望这次分享的经验能够帮助到更多需要的人。如果在学习时有对Word其它方面技巧的需求,也请在评论区留言,东东老师将根据留言设计更多实用的课程。祝您学习愉快!!!

703

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder ActiveX/COM/DCOM
社区管理员
  • ActiveX/COM/DCOM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧