请问如何用VC操作PowerPoint,读写PowerPoint页面的备注页中的文本?自己写了一段读写代码,但是有问题,没有完成备注页文本的读写。
首先感谢您以前给我解答了问题,现在又要麻烦您了。
开发工具是:VC6.0
应用方向是:读写Office PowerPoint 2003备注页中的文本
采用您以前给我的建议,参考了VBA帮助中的实现步骤。
VBA中往备注页中写入字符串的代码如下:
ActivePresentation.Slides(1).NotesPage.Shapes.Placeholders(2).TextFrame.TextRange.InsertAfter "My first Nodes Page"
我参考VBA的过程,用VC写的读写备注页的代码如下:
// 相关变量定义
_Application app;
Presentations Presentations;
_Presentation Presentation;
Slides slides;
_Slide slide;
// 启动PowerPoint
app.CreateDispatch("Powerpoint.Application"))
app.SetVisible(TRUE);
// 打开PowerPoint
static char BASED_CODE szFilter[] = "PowerPoint Files (*.ppt)|*.ppt||";
CFileDialog FileDlg(TRUE,"PPT",NULL,OFN_FILEMUSTEXIST|OFN_NONETWORKBUTTON
|OFN_PATHMUSTEXIST,szFilter);
FileDlg.DoModal();
CString strFileName;
strFileName = FileDlg.GetPathName();
Presentations = app.GetPresentations();
Presentation = Presentations.Open(strFileName,0,0,1);
// 写备注页,在第一页的备注页中写入字符串“My first Nodes Page”
Presentation = app.GetActivePresentation();
slides = Presentation.GetSlides();
slide = slides.Range(COleVariant((long)1));
//slide = slides.Item(COleVariant((long)1)); // 注释掉上句,启用这句出现的情况是一样的
Shapes shapes = slide.GetNotesPage();
Shape shape= shapes.GetPlaceholders();
TextFrame textFrame(shape.GetTextFrame());
// 程序执行到此弹出异常:TextFrame.TextRange:Invalid request. Nothing appropriate is currently selected.
TextRange textRange(textFrame.GetTextRange());
textRange.SetText("My first Nodes Page");
// 读备注页,读取第一页的备注页中的字符串“My first Nodes Page”
CString strText = _T("");
Presentation = app.GetActivePresentation();
slides = Presentation.GetSlides();
slide = slides.Range(COleVariant((long)1));
//slide = slides.Item(COleVariant((long)1)); // 注释掉上句,启用这句出现的情况是一样的
Shapes shapes = slide.GetNotesPage();
Shape shape= shapes.GetPlaceholders();
TextFrame textFrame(shape.GetTextFrame());
// 程序执行到此弹出异常:TextFrame.TextRange:Invalid request. Nothing appropriate is currently selected.
TextRange textRange(textFrame.GetTextRange());
strText = textRange.GetText();
为了让代码更加简洁我省略了异常处理和退出的代码。
上面的代码执行就会出现异常:
TextFrame.TextRange:Invalid request. Nothing appropriate is currently selected.
并且无法读写备注页中的文本。
问题:请问问题出在哪儿,应该如何改写才能实现读写备注页的功能?
谢谢!
如果分不够可以再加。
再次感谢!