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

📄 wordview.cpp

📁 word编程
💻 CPP
📖 第 1 页 / 共 2 页
字号:

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a18");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a19");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a20");

		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a21");

		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a22");

		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a23");

		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a24");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a25");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a26");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a27");

		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a28");

		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a29");

		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a30");

		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a31");

		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a32");	
	}
	
	//save word file
	CComVariant FileFormats(0);	
	
	if(Vertion2000)
	{
		_DDocument oActiveDoc9;
		oActiveDoc9 = m_App9.GetActiveDocument();
		oActiveDoc9.SaveAs(varFilePath,&FileFormats,covFalse,varstrNull,
			covTrue,varstrNull,covFalse,covFalse,
			covFalse,covFalse,covFalse);
		
		m_Docs9.ReleaseDispatch();
		m_Sel9.ReleaseDispatch();		
		CComVariant SaveChanges2000(false),OriginalFormat2000,RouteDocument2000;		
		m_App9.Quit(&SaveChanges2000,&OriginalFormat2000,&RouteDocument2000);
		m_App9.ReleaseDispatch();
	}
	
	if(Vertion2003)
	{
		_Document oActiveDoc;
		oActiveDoc = m_App.GetActiveDocument();
		oActiveDoc.SaveAs(varFilePath,&FileFormats,covFalse,varstrNull,
			covTrue,varstrNull,covFalse,covFalse,
			covFalse,covFalse,covFalse,covFalse,
			covFalse,covFalse,covFalse,covFalse);	
		m_Docs.ReleaseDispatch();	
		m_Sel.ReleaseDispatch();
		
		CComVariant SaveChanges2003(false),OriginalFormat2003,RouteDocument2003;
		m_App.Quit(&SaveChanges2003,&OriginalFormat2003,&RouteDocument2003);	
		m_App.ReleaseDispatch();
	}

	MessageBox("I Love Y");			
}

void CWordView::OnPoint() 
{
	// TODO: Add your command handler code here
	BeginWaitCursor();

	COleVariant vTrue((short)TRUE), vFalse((short)FALSE),vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
	
	_Application m_App;
	_AApplication m_App9;
	Documents m_Docs;
	DDocuments m_Docs9;
	Selection m_Sel;
	SSelection m_Sel9;
	
	BOOL Vertion2000=TRUE;
	BOOL Vertion2003=FALSE;	
	
	// 输出路径
	COleVariant varFilePath("C:\\4.doc");

	COleVariant varstrNull("");
	COleVariant varZero((short)0);
	COleVariant covTrue((short)TRUE),covFalse((short)FALSE);
	COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
	
	if(!m_App9.CreateDispatch("Word.Application.9",NULL))
	{ 
		//MessageBox("创建Word2000服务失败"); 
		Vertion2000=FALSE;
		Vertion2003=TRUE;
	}

	if((!m_App.CreateDispatch("Word.Application", NULL))&&(!Vertion2000))
	{
		//AfxMessageBox("创建Word2003失败"); 
		Vertion2003=FALSE;
	}	
	
	if((!Vertion2003)&&(!Vertion2000))
	{			
		MessageBox("创建Word失败"); 
	}	
	
	//AfxMessageBox("创建Word2000!");
	if(Vertion2000)
	{ 	
		m_App9.SetVisible(TRUE);
		m_Docs9.AttachDispatch(m_App9.GetDocuments());
		m_Docs9.Open(varFilePath,covFalse,covFalse,covFalse,
			varstrNull,varstrNull,covFalse,varstrNull,
			varstrNull,varZero,covOptional,covTrue);
		m_Sel9.AttachDispatch(m_App9.GetSelection());

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)3),COleVariant((short)0));
		m_Sel9.TypeText("a1");

		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a2");

		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a3");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a4");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a5");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a6");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a7");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a8");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a9");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a10");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a11");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a12");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a13");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a14");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a15");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a16");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a17");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a18");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a19");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a20");

		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a21");

		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a22");

		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a23");

		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a24");
	}
	
	//AfxMessageBox("创建Word2003!");	
	if(Vertion2003)
	{	
		
		m_App.SetVisible(FALSE);
		m_Docs.AttachDispatch(m_App.GetDocuments());
		m_Docs.Open(varFilePath,covFalse,covFalse,covFalse,
			varstrNull,varstrNull,covFalse,varstrNull,
			varstrNull,varZero,covOptional,covTrue,
			covOptional, // OpenConflictDocument
			covOptional, // OpenAndRepair
			covFalse,     // DocumentDirection wdDocumentDirection LeftToRight
			varstrNull);  // NoEncodingDialo
		m_Sel.AttachDispatch(m_App.GetSelection());	
		
		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)3),COleVariant((short)0));
		m_Sel.TypeText("a1");

		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a2");

		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a3");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a4");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a5");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a6");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a7");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a8");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a9");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a10");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a11");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a12");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a13");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a14");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a15");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a16");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a17");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a18");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a19");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a20");

		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a21");

		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a22");

		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a23");

		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a24");
	}
	
	//save word file
	CComVariant FileFormats(0);	
	
	if(Vertion2000)
	{
		_DDocument oActiveDoc9;
		oActiveDoc9 = m_App9.GetActiveDocument();
		oActiveDoc9.SaveAs(varFilePath,&FileFormats,covFalse,varstrNull,
			covTrue,varstrNull,covFalse,covFalse,
			covFalse,covFalse,covFalse);
		
		m_Docs9.ReleaseDispatch();
		m_Sel9.ReleaseDispatch();		
		CComVariant SaveChanges2000(false),OriginalFormat2000,RouteDocument2000;		
		m_App9.Quit(&SaveChanges2000,&OriginalFormat2000,&RouteDocument2000);
		m_App9.ReleaseDispatch();
	}
	
	if(Vertion2003)
	{
		_Document oActiveDoc;
		oActiveDoc = m_App.GetActiveDocument();
		oActiveDoc.SaveAs(varFilePath,&FileFormats,covFalse,varstrNull,
			covTrue,varstrNull,covFalse,covFalse,
			covFalse,covFalse,covFalse,covFalse,
			covFalse,covFalse,covFalse,covFalse);	
		m_Docs.ReleaseDispatch();	
		m_Sel.ReleaseDispatch();
		
		CComVariant SaveChanges2003(false),OriginalFormat2003,RouteDocument2003;
		m_App.Quit(&SaveChanges2003,&OriginalFormat2003,&RouteDocument2003);	
		m_App.ReleaseDispatch();
	}

	MessageBox("I Love Y Too");		
}

⌨️ 快捷键说明

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