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

📄 dsofprint.cpp

📁 用于在线office文档编辑的控件。可以在线新建文档、修改文档
💻 CPP
📖 第 1 页 / 共 5 页
字号:
				spDoc->HighlightChangesOnScreen = nNewValue; 		
				spDoc.Release();		
			}
			break;
		case FILE_TYPE_PPT:
		case FILE_TYPE_PDF:
		case FILE_TYPE_UNK:
		default:
			break;
		}
	}catch(...){
		
	}
	*pbool = TRUE; 
	return S_OK;
}
/*
pPos = 0 //当前鼠标位置
1;文件开头
2;文件末尾

if nCurPos | 0x8 表示插入的是图片
					if(lPos == 1){
						spDoc->raw_Range(COleVariant((long)0) , COleVariant((long)0) ,&spRang);
						if(!spRang)
							break;
						spRang->Select();
					}else if(lPos == 2){
						hr = spDoc->get_Content(&spRang);
						if((FAILED(hr))||(!spRang))
							break;
						long lStart = spRang->End - 1;
						spRang = NULL;
						spDoc->raw_Range(COleVariant(lStart), COleVariant(vtMissing), &spRang);
						if(!spRang)
							break;
						spRang->Select();		
					}
*/
STDMETHODIMP CDsoFramerControl::InSertFile(BSTR strFieldPath, long lPos, VARIANT_BOOL* pbool)
{
	IDispatch * lDisp;
    get_ActiveDocument(&lDisp);
	if(!lDisp){
		*pbool = FALSE;
		return S_OK;
	}
	HRESULT hr;
	USES_CONVERSION;
	try{
		switch(m_nOriginalFileType){
		case FILE_TYPE_WORD:
			{					
				CComQIPtr<MSWord::_Document> spDoc(lDisp);
				if(!spDoc)
					break;
				CComPtr<MSWord::_Application> spApp(spDoc->GetApplication());
				CComPtr<MSWord::Range> pRange;
				CComPtr<MSWord::Selection> spSelection;
				spSelection = NULL;
				hr = spApp->get_Selection(&spSelection);
				if(SUCCEEDED(hr)){
					if(0x01 & lPos){
						spSelection->HomeKey(COleVariant((long)6),COleVariant((long)0));
					}else if(0x02 & lPos){
						spSelection->EndKey(COleVariant((long)6),COleVariant((long)0));
					}
					if(0x08 & lPos){
						hr = spSelection->get_Range(&pRange);
						if(FAILED(hr)||(!pRange))
							return E_UNKNOW;

						CComPtr<MSWord::InlineShapes>	spLineShapes = NULL;							
						CComPtr<MSWord::InlineShape>	spInlineShape = NULL;						
						CComPtr<MSWord::Shape>	spShape = NULL;
						CComPtr<MSWord::WrapFormat>	wrap = NULL;
						 
						hr = pRange->get_InlineShapes(&spLineShapes);
						if(FAILED(hr)||(!pRange))
							return E_UNKNOW;
						hr = spLineShapes->raw_AddPicture(strFieldPath,&vtMissing,&vtMissing,&vtMissing,&spInlineShape);
						if(pRange){
							spInlineShape->raw_ConvertToShape(&spShape);
							if(spShape){
								hr = spShape->get_WrapFormat(&wrap); 
								wrap->put_Type((MSWord::WdWrapType)5);
								wrap->put_AllowOverlap(-1);
								wrap = NULL;
							}
							spShape = NULL;
						}
 						spLineShapes = NULL;
						spInlineShape = NULL;
						return S_OK;
					}
					if(SUCCEEDED(hr)){
							if(_wcsnicmp(strFieldPath, L"HTTP", 4) == 0  || _wcsnicmp(strFieldPath, L"FTP", 3) == 0){
							char szPath[MAX_PATH];
							szPath[0] = 0;
							FILE * fp = NULL;
							char temp[1024];
							UINT nBytesRead = 0;
							::GetTempPath(MAX_PATH, szPath);
							strcat(szPath,"DSOWebOffice");
							
							
							if (CreateDirectory(szPath, NULL) || GetLastError() == ERROR_ALREADY_EXISTS)
							{
								lstrcat(szPath, "\\");
							}

							::GetTempFileName(szPath, "", 0, szPath);
							//theApp.GetTempFileName(szPath);
							CInternetSession session("DSO");
							CStdioFile * pFile = NULL;
							pFile = session.OpenURL(W2A(strFieldPath),0,
								INTERNET_FLAG_TRANSFER_BINARY|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_RELOAD|
								INTERNET_FLAG_DONT_CACHE);
							if(!pFile){
								return 0;
							}
							if((fp = fopen(szPath,"wb")) == NULL){
								pFile->Close();
								delete pFile;
								return 0;
							}
							DWORD iLen = 0;
							while(iLen = pFile->Read(temp, 1024)){
								fwrite(temp, 1, iLen, fp);
								fflush(fp);
							}
							fclose(fp);
							if(pFile){
								pFile->Close();
								delete pFile;
							}
							spSelection->InsertFile(szPath,&vtMissing,&vtMissing,&vtMissing,&vtMissing );
						}else{
							spSelection->InsertFile(strFieldPath,&vtMissing,&vtMissing,&vtMissing,&vtMissing );
						}

					}

				}
				spDoc.Release();		
			}
			break;
		case FILE_TYPE_EXCEL:
			{	
				
				
			}
			break;
		case FILE_TYPE_PPT:
		case FILE_TYPE_PDF:
		case FILE_TYPE_UNK:
		default:
			break;
		}
	}catch(...){
		
	}
	*pbool = TRUE; 
	return S_OK; 
}
STDMETHODIMP CDsoFramerControl::ClearFile()
{						
 	char szPath[MAX_PATH];
 	::GetTempPath(MAX_PATH, szPath);
	strcat(szPath,"DSOWebOffice\\");
	char pcFile[MAX_PATH];
	strcpy(pcFile, szPath);
	strcat(pcFile, "*");
	HANDLE hFindFile = NULL;
	WIN32_FIND_DATA FindFileData;
 
 	if((hFindFile = FindFirstFile(pcFile, &FindFileData))!=NULL){
		while(FindNextFile(hFindFile, &FindFileData)){
        	if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){
        		continue;
        	}else{
				strcpy(pcFile,szPath);
 				strcat(pcFile, FindFileData.cFileName);
				::DeleteFile(pcFile);
        	}
		}
		FindClose(hFindFile);
	}
	return S_OK;
}
STDMETHODIMP CDsoFramerControl::LoadOriginalFile( VARIANT strFieldPath,  VARIANT strFileType,  long* pbool)
{
	LPWSTR    pwszFileType = LPWSTR_FROM_VARIANT(strFileType);
	
	LPWSTR    pwszDocument  = LPWSTR_FROM_VARIANT(strFieldPath);
//	CreateNew(BSTR ProgIdOrTemplate)
	if(!pwszDocument || pwszDocument[0] ==0){
		if(strFileType.vt == VT_EMPTY){
			CreateNew(L"Word.Document");
			* pbool = m_nOriginalFileType;	
			return S_OK;
		}
		if(_wcsicmp(pwszFileType,L"doc") == 0 ){
			CreateNew(L"Word.Document");
		}else if(_wcsicmp(pwszFileType,L"wps") == 0 ){
			CreateNew(L"Wps.Document");
		}else if(_wcsicmp(pwszFileType,L"xls") == 0 ){
			CreateNew(L"Excel.Sheet");
		}else if(_wcsicmp(pwszFileType,L"ppt") == 0 ){
			CreateNew(L"PowerPoint.Slide");
		}else{
			CreateNew(pwszFileType);
		}
	}else{
 			Open(strFieldPath, vtMissing, strFileType, vtMissing, vtMissing);
	}

	* pbool = m_nOriginalFileType;	
 	return S_OK;
}
//Excel File Format 
/*
enum XlFileFormat
{
    xlAddIn = 18,
    xlCSV = 6,
    xlCSVMac = 22,
    xlCSVMSDOS = 24,
    xlCSVWindows = 23,
    xlDBF2 = 7,
    xlDBF3 = 8,
    xlDBF4 = 11,
    xlDIF = 9,
    xlExcel2 = 16,
    xlExcel2FarEast = 27,
    xlExcel3 = 29,
    xlExcel4 = 33,
    xlExcel5 = 39,
    xlExcel7 = 39,
    xlExcel9795 = 43,
    xlExcel4Workbook = 35,
    xlIntlAddIn = 26,
    xlIntlMacro = 25,
    xlWorkbookNormal = -4143,
    xlSYLK = 2,
    xlTemplate = 17,
    xlCurrentPlatformText = -4158,
    xlTextMac = 19,
    xlTextMSDOS = 21,
    xlTextPrinter = 36,
    xlTextWindows = 20,
    xlWJ2WD1 = 14,
    xlWK1 = 5,
    xlWK1ALL = 31,
    xlWK1FMT = 30,
    xlWK3 = 15,
    xlWK4 = 38,
    xlWK3FM3 = 32,
    xlWKS = 4,
    xlWorks2FarEast = 28,
    xlWQ1 = 34,
    xlWJ3 = 40,
    xlWJ3FJ3 = 41,
    xlUnicodeText = 42,
    xlHtml = 44
};
Word: Type
enum WdSaveFormat
{
    wdFormatDocument = 0,
    wdFormatTemplate = 1,
    wdFormatText = 2,
    wdFormatTextLineBreaks = 3,
    wdFormatDOSText = 4,
    wdFormatDOSTextLineBreaks = 5,
    wdFormatRTF = 6,
    wdFormatUnicodeText = 7,
    wdFormatEncodedText = 7,
    wdFormatHTML = 8
};
PPT:
enum PpSaveAsFileType
{
    ppSaveAsPresentation = 1,
    ppSaveAsPowerPoint7 = 2,
    ppSaveAsPowerPoint4 = 3,
    ppSaveAsPowerPoint3 = 4,
    ppSaveAsTemplate = 5,
    ppSaveAsRTF = 6,
    ppSaveAsShow = 7,
    ppSaveAsAddIn = 8,
    ppSaveAsPowerPoint4FarEast = 10,
    ppSaveAsDefault = 11,
    ppSaveAsHTML = 12,
    ppSaveAsHTMLv3 = 13,
    ppSaveAsHTMLDual = 14,
    ppSaveAsMetaFile = 15,
    ppSaveAsGIF = 16,
    ppSaveAsJPG = 17,
    ppSaveAsPNG = 18,
    ppSaveAsBMP = 19
};
  */
STDMETHODIMP CDsoFramerControl::SaveAs( VARIANT strFileName,  VARIANT dwFileFormat, long* pbool)
{
	
 	IDispatch * lDisp;
    get_ActiveDocument(&lDisp);
	if(!lDisp){
		*pbool = FALSE;
		return S_OK;
	}
	HRESULT hr;
	USES_CONVERSION;
	* pbool = 1;
	try{
		switch(m_nOriginalFileType){
		case FILE_TYPE_WORD:
			{					
				CComQIPtr<MSWord::_Document> spDoc(lDisp);
				if(!spDoc)
					break;
 				spDoc->SaveAs(COleVariant(strFileName),COleVariant(dwFileFormat));
				spDoc.Release();		
			}
			break;
		case FILE_TYPE_EXCEL:
			{	
				CComQIPtr<MSExcel::_Workbook> spDoc(lDisp);	
				if(!spDoc)
					break;
				spDoc->SaveAs(COleVariant(strFileName),COleVariant(dwFileFormat), 
					COleVariant(m_cPassWord), COleVariant(m_cPWWrite), vtMissing, vtMissing, xlNoChange);
			}
			break;
		case FILE_TYPE_PPT:
			{
				CComQIPtr<MSPPT::_Presentation> spDoc(lDisp);
 				if(!spDoc)
				break;
				spDoc->SaveAs(_bstr_t(strFileName), ppSaveAsPresentation, msoTrue);
			}
			break;
		case FILE_TYPE_PDF:
		case FILE_TYPE_UNK:
		default:
				Save(strFileName, vtMissing, vtMissing, vtMissing);
			break;
		}
	}catch(...){
		* pbool = 0;	
	}
 	return S_OK;
}
STDMETHODIMP CDsoFramerControl::DeleteLocalFile(BSTR strFilePath)
{
	USES_CONVERSION;

	::DeleteFile(W2A(strFilePath));
	return S_OK;
}
STDMETHODIMP CDsoFramerControl::GetTempFilePath(BSTR* strValue)
{
	CString strResult;
	// TODO: Add your dispatch handler code here
	char strTempFile[MAX_PATH];
	if(::GetTempPath(MAX_PATH,strTempFile)){
		if(::GetTempFileName(strTempFile,"~dso",0,strTempFile))
			strResult = strTempFile;
	}

	*strValue =  strResult.AllocSysString();
	return S_OK;
}

/*
wdMasterView、wdNormalView、wdOutlineView、wdPrintPreview、wdPrintView 或 wdWebView。Long 类型,可读写 */
STDMETHODIMP CDsoFramerControl::ShowView(long dwViewType, long * pbool)
{
	*pbool = FALSE;
	IDispatch * lDisp;
    get_ActiveDocument(&lDisp);
	if(!lDisp){
		return S_OK;
	}
	HRESULT hr;
	try{
		switch(m_nOriginalFileType){
		case FILE_TYPE_WORD:
			{					
				CComQIPtr<MSWord::_Document> spDoc(lDisp);
				if(!spDoc)
					break;
//				CComPtr<MSWord::_Application> app(spDoc->GetApplication()); 
				CComPtr<MSWord::Window> win;//app(spDoc->GetApplication()); 
				CComPtr<MSWord::Pane> pane;
				CComPtr<MSWord::View> view;
				win = spDoc->GetActiveWindow();
				if(!win)
					break;
				pane = win->GetActivePane();
				if(!pane)
					break;
				view = pane->GetView();
				if(!view)
					break;
				view->put_Type((enum MSWord::WdViewType)dwViewType);
				*pbool = TRUE;
			}
			break;
		case FILE_TYPE_EXCEL:
			{	
				
				
			}
			break;
		case FILE_TYPE_PPT:
		case FILE_TYPE_PDF:
		case FILE_TYPE_UNK:
		default:
			break;
		}
	}catch(...){
		
	}
 

	return S_OK; 
}
/*
if strLocalFile == NULL then Create Temp File and return TempFile's Path
*/
STDMETHODIMP CDsoFramerControl::DownloadFile( BSTR strRemoteFile, BSTR strLocalFile, BSTR* strValue)
{
	CString strRet = "OK";
	if(!LooksLikeHTTP(strRemoteFile) && !LooksLikeFTP(strRemoteFile)){
		strRet = "RemoteFile Error";
		* strValue = strRet.AllocSysString();
		return S_OK;
	}	
	if(strLocalFile && 0 != strLocalFile[0] && !LooksLikeLocalFile(strLocalFile)){
		strRet = "LocalFile Error";
		* strValue = strRet.AllocSysString();
		return S_OK;
	}	
	if(!strLocalFile || 0 == strLocalFile[0] ){
		CString strLoFile;
		char cPath[MAX_PATH];
		::GetTempPath(MAX_PATH, cPath);
		strcat(cPath,"DSOWebOffice");
		if (CreateDirectory(cPath, NULL) || GetLastError() == ERROR_ALREADY_EXISTS)
		{
			lstrcat(cPath, "\\");
		}
		::GetTempFileName(cPath, "", 0, cPath);
		strcat(cPath,"test001.doc");
		strLoFile = cPath;
		BSTR strTemp = strLoFile.AllocSysString();
		URLDownloadFile(NULL,strRemoteFile,strTemp);
		strRet = cPath;
		::SysFreeString(strTemp);
	}else{
		URLDownloadFile(NULL,strRemoteFile,strLocalFile);
	}
	* strValue = strRet.AllocSysString();
	return S_OK;
}

STDMETHODIMP CDsoFramerControl::GetRevCount(long * pbool)
{	
 	IDispatch * lDisp;
    get_ActiveDocument(&lDisp);
	if(!lDisp){
		*pbool = FALSE;
		return S_OK;
	}
	HRESULT hr;
	USES_CONVERSION;

⌨️ 快捷键说明

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