⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 makewordsdoc.cpp

📁 VC++和ACCESS使用ADO连接
💻 CPP
字号:
// MakeWordsDoc.cpp : implementation file
//

#include "stdafx.h"
#include "ministryperson.h"
#include "MakeWordsDoc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#include "msword9.h"

/////////////////////////////////////////////////////////////////////////////
// MakeWordsDoc dialog

MakeWordsDoc::MakeWordsDoc(CWnd* pParent /*=NULL*/)
	: CDialog(MakeWordsDoc::IDD, pParent)
{
	//{{AFX_DATA_INIT(MakeWordsDoc)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void MakeWordsDoc::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(MakeWordsDoc)
	DDX_Control(pDX, IDC_MK_PROGRESS, m_CtrlProgress);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(MakeWordsDoc, CDialog)
	//{{AFX_MSG_MAP(MakeWordsDoc)
	ON_BN_CLICKED(IDOK_MK, OnMk)
	ON_BN_CLICKED(IDC_BTN_MK_SURE, OnBtnMkSure)
	ON_BN_CLICKED(IDC_BTN_MK_EXIT, OnBtnMkExit)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// MakeWordsDoc message handlers

void MakeWordsDoc::OnMk() 
{
	CDialog::OnOK();
}

BOOL MakeWordsDoc::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	CString strMsg;
	strMsg.Format("确定生成【%s】的3份入职管理文档吗?", m_strName);
	SetDlgItemText(IDC_STATIC_MSG, strMsg);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

/*********************************************************************
函数说明:	  确定生成
函数参数:	  
*********************************************************************/
void MakeWordsDoc::OnBtnMkSure() 
{
	GetDlgItem(IDC_MK_PROGRESS)->ShowWindow(TRUE);
	GetDlgItem(IDC_BTN_MK_SURE)->ShowWindow(FALSE);
	GetDlgItem(IDC_BTN_MK_EXIT)->ShowWindow(FALSE);
	MakeAllWords();
}

/*********************************************************************
函数说明:	  取消
函数参数:	  
*********************************************************************/
void MakeWordsDoc::OnBtnMkExit() 
{
	CDialog::OnCancel();
}

/*********************************************************************
函数说明:	  控制生成过程
函数参数:	  
*********************************************************************/
void MakeWordsDoc::MakeAllWords()
{
	CString strMsg;
	strMsg.Format("正在生成文档,请稍后…", m_strName);
	SetDlgItemText(IDC_STATIC_MSG, strMsg);

	m_CtrlProgress.SetRange(0, (short)3);
	
	m_CtrlProgress.SetPos(0);	
	MakeWordDocment1();
	m_CtrlProgress.SetPos(1);
	MakeWordDocment2();
	m_CtrlProgress.SetPos(2);
	MakeWordDocment3();
	m_CtrlProgress.SetPos(3);

	strMsg.Format("【%s】的文档生成成功!", m_strName);
	SetDlgItemText(IDC_STATIC_MSG, strMsg);
	GetDlgItem(IDOK_MK)->ShowWindow(TRUE);

	CADOOperation ADOdbo;
	CString SQL;
	SQL.Format("update CheckType_Table set IsTypeThree = '%s' \
				where employee_ID = %d and employee_IDCard = '%s' and employee_Name = '%s'",
				"已打印3", m_nID, m_strIDCard, m_strName);
	ADOdbo.OpenRecordset(SQL);
	ADOdbo.CloseRecorset();	
}

/*********************************************************************
函数说明:	  生成Word文档——报到通知单
函数参数:	  
*********************************************************************/
void MakeWordsDoc::MakeWordDocment1()
{
	BeginWaitCursor();
	
	COleVariant vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);

	_Application_Word m_Application;		// 应用程序对象
	Documents_Word    m_Documents;			// 文档对象
	Selection_Word    m_Selection;			// 选择对象
	CFuncOper FunOper;

	m_Documents.ReleaseDispatch();
	m_Selection.ReleaseDispatch();
	m_Application.m_bAutoRelease = TRUE;
	if(!m_Application.CreateDispatch("Word.Application"))
	{
		MessageBox("创建 Word 服务失败!请确认您的系操中已安装了 Microsoft Office 组件\t", "失败", 
					MB_OK | MB_ICONEXCLAMATION);
		exit(1);
	}
	
	CString strFile;
	strFile = FunOper.GetProgramPath() + "\\DocsWord\\报到通知单(空).doc";

	// 下面是定义 Variant 变量
	COleVariant varFilePath(strFile);
	COleVariant vTrue( (short)TRUE);
	COleVariant vFalse((short)FALSE);
	COleVariant varstrNull("");
	COleVariant varZero((short)0);
	COleVariant varTrue( short(1),  VT_BOOL);
	COleVariant varFalse(short(0), VT_BOOL);
	m_Documents.AttachDispatch(m_Application.GetDocuments());	
	m_Documents.Open(varFilePath, varFalse, varFalse, varFalse, varstrNull, varstrNull, 
		varFalse, varstrNull, varstrNull,varTrue,varTrue,varTrue);
	
	// 打开 word 文档
	m_Selection.AttachDispatch(m_Application.GetSelection());

	// Unit   Count   Extend
	m_Selection.MoveDown(COleVariant((short)wdLine), COleVariant((short)3), COleVariant((short)0));
	m_Selection.TypeText((LPCTSTR)m_strCompany);

	m_Selection.HomeKey(COleVariant((short)wdLine), COleVariant((short)0));
	m_Selection.MoveDown (COleVariant((short)wdLine), COleVariant((short)1), COleVariant((short)0));
	m_Selection.MoveRight(COleVariant((short)wdCharacter), COleVariant((short)3), COleVariant((short)0));
	m_Selection.TypeText((LPCTSTR)m_strName);

	m_Selection.HomeKey(COleVariant((short)wdLine), COleVariant((short)0));
	m_Selection.MoveDown(COleVariant((short)wdLine), COleVariant((short)3), COleVariant((short)0));
	m_Selection.MoveRight(COleVariant((short)wdCharacter), COleVariant((short)1), COleVariant((short)0));
	m_Selection.TypeText((LPCTSTR)m_strName);

	m_Selection.MoveDown(COleVariant((short)wdLine), COleVariant((short)1), COleVariant((short)0));
    m_Selection.TypeText((LPCTSTR)m_strSex);

	CString JoinTime1;
	JoinTime1 = FunOper.FormatDataToShow(m_strJoinTime);
    m_Selection.MoveDown(COleVariant((short)wdLine), COleVariant((short)1), COleVariant((short)0));
	m_Selection.TypeText((LPCTSTR)JoinTime1);
	
	m_Selection.MoveDown(COleVariant((short)wdLine), COleVariant((short)1), COleVariant((short)0));
    m_Selection.TypeText((LPCTSTR)m_strCompany);

	m_Selection.MoveDown(COleVariant((short)wdLine), COleVariant((short)1), COleVariant((short)0));
    m_Selection.TypeText((LPCTSTR)m_strDuty);

	CString Data1;
	Data1 = FunOper.FormatDataToShow(m_strData);
	m_Selection.MoveDown(COleVariant((short)wdLine), COleVariant((short)7), COleVariant((short)0));
    m_Selection.TypeText((LPCTSTR)Data1);

	// 保存文档
	_Document_Word oActiveDoc;
	oActiveDoc = m_Application.GetActiveDocument();
	
	CString strSavePath;
	strSavePath.Format(m_strSPath + "\\报到通知单_%s.doc", m_strName);
	oActiveDoc.SaveAs(COleVariant(strSavePath), COleVariant((short)0), vFalse, COleVariant(""), 
						vTrue, COleVariant(""), vFalse, vFalse, vFalse, vFalse, vFalse);	
	m_Documents.ReleaseDispatch();	// 断开连接
	m_Selection.ReleaseDispatch();

	// 退出 word
	m_Application.Quit(vOpt, vOpt, vOpt);
	m_Application.Quit(vOpt, vOpt, vOpt);
	m_Application.ReleaseDispatch();
	EndWaitCursor();
}

/*********************************************************************
函数说明:	  生成Word文档——入职通知
函数参数:	  
*********************************************************************/
void MakeWordsDoc::MakeWordDocment2()
{
	BeginWaitCursor();
	
	COleVariant vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);

	_Application_Word m_Application;		// 应用程序对象
	Documents_Word    m_Documents;			// 文档对象
	Selection_Word    m_Selection;			// 选择对象
	CFuncOper FunOper;

	m_Documents.ReleaseDispatch();
	m_Selection.ReleaseDispatch();
	m_Application.m_bAutoRelease = TRUE;
	if(!m_Application.CreateDispatch("Word.Application"))
	{
		MessageBox("创建 Word 服务失败!请确认您的系操中已安装了 Microsoft Office 组件\t", "失败", 
					MB_OK | MB_ICONEXCLAMATION);
		exit(1);
	}
	
	CString strFile;
	strFile = FunOper.GetProgramPath() + "\\DocsWord\\入职通知单(空).doc";

	// 下面是定义 Variant 变量
	COleVariant varFilePath(strFile);
	COleVariant vTrue( (short)TRUE);
	COleVariant vFalse((short)FALSE);
	COleVariant varstrNull("");
	COleVariant varZero((short)0);
	COleVariant varTrue( short(1),  VT_BOOL);
	COleVariant varFalse(short(0), VT_BOOL);
	m_Documents.AttachDispatch(m_Application.GetDocuments());	
	m_Documents.Open(varFilePath, varFalse, varFalse, varFalse, varstrNull, varstrNull, 
		varFalse, varstrNull, varstrNull,varTrue,varTrue,varTrue);
	
	// 打开 word 文档
	m_Selection.AttachDispatch(m_Application.GetSelection());
	
	// Unit   Count   Extend
	m_Selection.MoveDown(COleVariant((short)wdLine), COleVariant((short)1), COleVariant((short)0));
	m_Selection.MoveLeft(COleVariant((short)wdCharacter), COleVariant((short)4), COleVariant((short)0));
	m_Selection.TypeText((LPCTSTR)m_strName);

	m_Selection.HomeKey(COleVariant((short)wdLine), COleVariant((short)0));
	m_Selection.MoveDown(COleVariant((short)wdLine), COleVariant((short)2), COleVariant((short)0));
	m_Selection.MoveRight(COleVariant((short)wdCharacter), COleVariant((short)16), COleVariant((short)0));
	m_Selection.TypeText((LPCTSTR)m_strCompany);

	m_Selection.HomeKey(COleVariant((short)wdLine), COleVariant((short)0));
	m_Selection.MoveDown(COleVariant((short)wdLine), COleVariant((short)4), COleVariant((short)0));
	m_Selection.MoveRight(COleVariant((short)wdCharacter), COleVariant((short)9), COleVariant((short)0));
	m_Selection.TypeText((LPCTSTR)m_strJoinTime);

	m_Selection.HomeKey(COleVariant((short)wdLine), COleVariant((short)0));
	m_Selection.MoveDown(COleVariant((short)wdLine), COleVariant((short)17), COleVariant((short)0));
	m_Selection.TypeText((LPCTSTR)m_strData);

	// 保存文档
	_Document_Word oActiveDoc;
	oActiveDoc = m_Application.GetActiveDocument();
	
	CString strSavePath;
	strSavePath.Format(m_strSPath + "\\入职通知单_%s.doc", m_strName);
	oActiveDoc.SaveAs(COleVariant(strSavePath), COleVariant((short)0), vFalse, COleVariant(""), 
						vTrue, COleVariant(""), vFalse, vFalse, vFalse, vFalse, vFalse);	
	m_Documents.ReleaseDispatch();	// 断开连接
	m_Selection.ReleaseDispatch();

	// 退出 word
	m_Application.Quit(vOpt, vOpt, vOpt);
	m_Application.Quit(vOpt, vOpt, vOpt);
	m_Application.ReleaseDispatch();
	EndWaitCursor();
}

/*********************************************************************
函数说明:	  生成Word文档——引导检查表
函数参数:	  
*********************************************************************/
void MakeWordsDoc::MakeWordDocment3()
{
	BeginWaitCursor();
	
	COleVariant vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);

	_Application_Word m_Application;		// 应用程序对象
	Documents_Word    m_Documents;			// 文档对象
	Selection_Word    m_Selection;			// 选择对象
	CFuncOper FunOper;

	m_Documents.ReleaseDispatch();
	m_Selection.ReleaseDispatch();
	m_Application.m_bAutoRelease = TRUE;
	if(!m_Application.CreateDispatch("Word.Application"))
	{
		MessageBox("创建 Word 服务失败!请确认您的系操中已安装了 Microsoft Office 组件\t", "失败", 
					MB_OK | MB_ICONEXCLAMATION);
		exit(1);
	}
	
	CString strFile;
	strFile = FunOper.GetProgramPath() + "\\DocsWord\\新员工入职引导检查表(空).doc";

	// 下面是定义 Variant 变量
	COleVariant varFilePath(strFile);
	COleVariant vTrue( (short)TRUE);
	COleVariant vFalse((short)FALSE);
	COleVariant varstrNull("");
	COleVariant varZero((short)0);
	COleVariant varTrue( short(1),  VT_BOOL);
	COleVariant varFalse(short(0), VT_BOOL);
	m_Documents.AttachDispatch(m_Application.GetDocuments());	
	m_Documents.Open(varFilePath, varFalse, varFalse, varFalse, varstrNull, varstrNull, 
		varFalse, varstrNull, varstrNull,varTrue,varTrue,varTrue);
	
	// 打开 word 文档
	m_Selection.AttachDispatch(m_Application.GetSelection());

	// Unit   Count   Extend
	m_Selection.MoveDown(COleVariant((short)wdLine), COleVariant((short)1), COleVariant((short)0));
	m_Selection.MoveLeft(COleVariant((short)wdCharacter), COleVariant((short)1), COleVariant((short)0));
	m_Selection.TypeText((LPCTSTR)m_strName);

	m_Selection.MoveDown(COleVariant((short)wdLine), COleVariant((short)1), COleVariant((short)0));
	m_Selection.TypeText((LPCTSTR)m_strJoinTime);

	m_Selection.MoveRight(COleVariant((short)wdCharacter), COleVariant((short)6), COleVariant((short)0));
	m_Selection.MoveUp(COleVariant((short)wdLine), COleVariant((short)1), COleVariant((short)0));
	m_Selection.TypeText((LPCTSTR)m_strSex);

	m_Selection.MoveRight(COleVariant((short)wdCharacter), COleVariant((short)6), COleVariant((short)0));
	m_Selection.TypeText((LPCTSTR)m_strCompany);

	
	m_Selection.MoveDown(COleVariant((short)wdLine), COleVariant((short)1), COleVariant((short)0));
	m_Selection.TypeText((LPCTSTR)m_strDuty);

	// 保存文档
	_Document_Word oActiveDoc;
	oActiveDoc = m_Application.GetActiveDocument();
	
	CString strSavePath;
	strSavePath.Format(m_strSPath + "\\引导检查表_%s.doc", m_strName);
	oActiveDoc.SaveAs(COleVariant(strSavePath), COleVariant((short)0), vFalse, COleVariant(""), 
						vTrue, COleVariant(""), vFalse, vFalse, vFalse, vFalse, vFalse);	
	m_Documents.ReleaseDispatch();	// 断开连接
	m_Selection.ReleaseDispatch();

	// 退出 word
	m_Application.Quit(vOpt, vOpt, vOpt);
	m_Application.Quit(vOpt, vOpt, vOpt);
	m_Application.ReleaseDispatch();
	EndWaitCursor();
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -