用MFC做个Dialog Dialog里面有EDITControl里面的内容是从数据库中读取出来的 想将按一定格式其导入到WORD文档里 请问:如何操作。请给出一个简单的例子 谢谢~~~~
解决方案 »
- 写了一个本机通信的小代码在vc6.0上没有问题,一直vc.net上就出现这么多错误,朋友们看看是那里设置的不对吗,有代码与错误!
- vector 向int类型转化
- 如何在FORMVIEW中生成CBitmpButton 按钮
- ●●我的程序一运行就显示一个错误信息框“序数977从动态连接库MFCD42D.DLL里没有找到”,究竟是什么意思?●●
- 我的com组件中涉及到数据库的操作在asp不可用,而在vb下一直运行正常,其他不涉及数据库的操作在asp下均工作正常,
- 兄弟们啊,我的站有情连结太少了,那位兄弟的网站和我做友情连结?-------------〉〉In
- 关于创建进程的问题
- 如何在propertysheet中增加按钮?
- 请问如何完美的清除掉直接在桌面上显示的透明背景文字?好像透明背景文字比较难清除。要求不能闪烁,一定重奖。
- 如何获得本机的IP地址?
- 急急急急 vc6.0或vc.net 如何做com组件(上传组件) 在线等待 进者都有分 贡献出我所有分
- mfc 基于对话框,在window mobile 6.0平台下 怎么调用windows media player?
#include "msword9.h"
#include <AtlBase.h>void CStep4Dlg::OnOK()
{
_Application app;
app.CreateDispatch(_T("Word.Application"));
app.SetVisible(TRUE); Documents docs=app.GetDocuments();
CComVariant Template(_T(""));
CComVariant NewTemplate(false),DocumentType(0),Visible;
docs.Add(&Template,&NewTemplate,&DocumentType,&Visible); Selection sel=app.GetSelection();
sel.TypeText(_T("HELLO\r\n大家好呀")); AfxMessageBox(_T("好了,我要保存到c:\\hello.doc中了"));
/**************** 这是在WORD中录制的新建文档直到另存的宏 *************
Documents.Add Template:= _
"C:\Documents and Settings\Administrator\Application Data\Microsoft\Templates\Normal.dot" _
, NewTemplate:=False, DocumentType:=0
Selection.TypeText Text:="Hello"
Selection.TypeParagraph
Selection.TypeText Text:="大家好"
ChangeFileOpenDirectory "C:\"
ActiveDocument.SaveAs FileName:="Hello.doc", FileFormat:=wdFormatDocument _
, LockComments:=False, Password:="", AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
*********************************************************************//**************** 程序思路 ******************************************
另存为的函数是ActiveDocument.SaveAs,显然表示的是对当前活跃的文档进行保存,
在我们的类中没有ActiveDocument,其实它对应的是_Document,而这个可以由
_Application 的GetActiveDocument()得到。你一定会提问:“你怎么知道的?”
呵呵,怎么说那,我怎么知道的那?答案是:猜。其实如果使用的多了,分析、猜
查找都是办法。如果想得到确切的方法,其实可以在VBA的书或微软的网站中搜索
*********************************************************************/ _Document doc=app.GetActiveDocument(); //得到ActiveDocument
CComVariant FileName(_T("c:\\Hello.doc")); //文件名
CComVariant FileFormat(0); //重点,看下面的说明
CComVariant LockComments(false),Password(_T(""));
CComVariant AddToRecentFiles(true),WritePassword(_T(""));
CComVariant ReadOnlyRecommended(false),EmbedTrueTypeFonts(false);
CComVariant SaveNativePictureFormat(false),SaveFormsData(false);
CComVariant SaveAsAOCELetter(false);
/*************** FileFormat 文件格式说明 ****************************
参数FileFormat,在WORD的宏中,使用的是 wdFormatDocument,这是什么那?
其实这是WORD宏中所使用的常量,由匈牙利命名可以知道wd其实是DWORD的意思
知道了是一个正数,那么它到底是多少那?其实有一个办法可以知道,那就是在
WORD宏程序中,加一条语句:MsgBox wdFormatDocument 这样你再运行宏程序,
就能看到这个常量是多少了。呵呵,这个常量是0,我够聪明吧^_^
*********************************************************************/ doc.SaveAs(&FileName,&FileFormat,&LockComments,&Password,
&AddToRecentFiles,&WritePassword,&ReadOnlyRecommended,
&EmbedTrueTypeFonts,&SaveNativePictureFormat,&SaveFormsData,
&SaveAsAOCELetter);
sel.ReleaseDispatch();
doc.ReleaseDispatch();
docs.ReleaseDispatch(); CComVariant SaveChanges(false),OriginalFormat,RouteDocument;
app.Quit(&SaveChanges,&OriginalFormat,&RouteDocument);
app.ReleaseDispatch();
AfxMessageBox(_T("请检查c:\\hello.doc是否正常产生了。下面该学习Setp5了"));