示例#1
0
int _tmain(int argc, _TCHAR* argv[])
{
	if (argc < 3) return 3;

	std::wstring sSrcPpt	= argv[1];
    std::wstring sDstPptx	= argv[2];

	std::wstring outputDir		= FileSystem::Directory::GetFolderPath(sDstPptx);
	std::wstring dstTempPath	= FileSystem::Directory::CreateDirectoryWithUniqueName(outputDir);

	std::wstring tempPath	= FileSystem::Directory::CreateDirectoryWithUniqueName(outputDir);
	// Ppt->Pptx
		COfficePPTFile pptFile;
		
		pptFile.put_TempDirectory(tempPath);

		HRESULT hRes = pptFile.LoadFromFile(sSrcPpt, dstTempPath);
	
	if (hRes != S_OK)return 2;
	
	COfficeUtils oCOfficeUtils(NULL);
	if (S_OK != oCOfficeUtils.CompressFileOrDirectory(dstTempPath.c_str(), sDstPptx, -1))
        return 1;
	
	FileSystem::Directory::DeleteDirectory(dstTempPath);
	FileSystem::Directory::DeleteDirectory(tempPath);
	return 0;
}
示例#2
0
HRESULT convert_single(std::wstring srcFileName)
{
	COfficeFileFormatChecker fileChecker(srcFileName);

	std::wstring dstPath = srcFileName;// + ....

	std::wstring type;
	switch(fileChecker.nFileType)
	{
		case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX:
		case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCM:		dstPath += L"-my.odt"; type = L"text";		break;
		
		case AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX:
		case AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSM:	dstPath += L"-my.ods"; type = L"spreadsheet";	break;
		
		case AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX:
		case AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTM:	dstPath += L"-my.odp"; type = L"presentation";	break;

		default:
			return S_FALSE;
	}

//------------------------------------------------------------------------------------------
	HRESULT hr = S_OK;

	std::wstring outputDir		= NSDirectory::GetFolderPath(dstPath);
	
	std::wstring srcTempPath	= NSDirectory::CreateDirectoryWithUniqueName(outputDir);
	std::wstring dstTempPath	= NSDirectory::CreateDirectoryWithUniqueName(outputDir);

    // распаковываем исходник во временную директорию
	COfficeUtils oCOfficeUtils(NULL);
    if (S_OK != oCOfficeUtils.ExtractToDirectory(srcFileName.c_str(), srcTempPath.c_str(), NULL, 0))
		return S_FALSE;

	Oox2Odf::Converter converter(srcTempPath, type, L"C:\\Windows\\Fonts", NULL);

	converter.convert();
	converter.write(dstTempPath);

	NSDirectory::DeleteDirectory(srcTempPath);

	if (hr != S_OK)  return hr;
   
	if (S_OK != oCOfficeUtils.CompressFileOrDirectory(dstTempPath.c_str(), dstPath.c_str(), -1))
        return hr;
	
	NSDirectory::DeleteDirectory(dstTempPath);

	return 0;
}
示例#3
0
HRESULT convert_single(std::wstring srcFileName)
{
	//COfficeFileFormatChecker checker;

	//if (false == checker.isOfficeFile(srcFileName)) return S_FALSE;	
	//
	//if (AVS_OFFICESTUDIO_FILE_PRESENTATION_PPT != checker.nFileType) return S_FALSE;
	
	HRESULT hr = S_OK;

	std::wstring outputDir		= NSDirectory::GetFolderPath(srcFileName);	
	std::wstring dstTempPath	= NSDirectory::CreateDirectoryWithUniqueName(outputDir);
	std::wstring dstPath;

	std::wstring tempPath	= NSDirectory::CreateDirectoryWithUniqueName(outputDir);

	COfficePPTFile pptFile;
	
	pptFile.put_TempDirectory(tempPath);

	bool bMacros = true;
	
	HRESULT hRes = pptFile.LoadFromFile(srcFileName, dstTempPath, L"password", bMacros);
	
	if (bMacros)
	{
		dstPath = srcFileName + L"-my.pptm";
	}
	else
	{
		dstPath = srcFileName + L"-my.pptx";

	}
	if (hRes == S_OK)
	{
		COfficeUtils oCOfficeUtils(NULL);
		hRes = oCOfficeUtils.CompressFileOrDirectory(dstTempPath.c_str(), dstPath, true);
	}
	
	NSDirectory::DeleteDirectory(dstTempPath);
	NSDirectory::DeleteDirectory(tempPath);

	return hRes;
}
示例#4
0
HRESULT COfficeOdfFileW::SaveToFileImpl(const std::wstring & srcPath,
                                        const std::wstring & srcTempPath,
                                        const std::wstring & dstTempPath,
										const std::wstring & fontPath,
                                        const std::wstring & dstFileName)
{
    HRESULT hr = E_FAIL;
	COfficeUtils oCOfficeUtils(NULL);  

    // распаковываем исходник (если он файл) во временную директорию
#if defined(STANDALONE_USE) && (STANDALONE_USE == 1)
        if (S_OK != oCOfficeUtils.ExtractToDirectory(srcPath.c_str(), srcTempPath.c_str(), NULL, 0))
            return hr;
#endif

	try
	{
		std::wstring type = DetectTypeDocument(srcTempPath);

		ProgressCallback ffCallBack;

		ffCallBack.OnProgress	=	OnProgressFunc;
		ffCallBack.OnProgressEx	=	OnProgressExFunc;
		ffCallBack.caller		=	this;
		
		Oox2Odf::Converter converter(srcTempPath, type, fontPath, &ffCallBack);
		

		converter.convert();
		converter.write(dstTempPath);
	} 
	catch(...)
	{
	}

	if (S_OK != oCOfficeUtils.CompressFileOrDirectory(dstTempPath.c_str(), dstFileName.c_str(), -1))
        return hr;


    return S_OK;
}
示例#5
0
HRESULT COfficeXlsFile::LoadFromFileImpl(const std::wstring & srcFileName, const std::wstring & dstTempPath, const std::wstring & dstPath)
{
	HRESULT hr = AVS_ERROR_UNEXPECTED;  

	ProgressCallback ffCallBack;

	ffCallBack.OnProgress	=	OnProgressFunc;
	ffCallBack.OnProgressEx	=	OnProgressExFunc;
	ffCallBack.caller		=	this;

	hr = ConvertXls2Xlsx(srcFileName, dstTempPath, &ffCallBack);

	if (hr != S_OK)  return hr;
   
#if defined(STANDALONE_USE) && (STANDALONE_USE == 1)
	COfficeUtils oCOfficeUtils(NULL);
	if (S_OK != oCOfficeUtils.CompressFileOrDirectory(dstTempPath.c_str(), dstPath.c_str(), -1))
        return hr;
#endif

    return S_OK;
}