mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-07-11 03:42:47 +08:00
git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@63606 954022d7-b5bf-4e40-9824-e11837661b57
140 lines
3.6 KiB
C++
140 lines
3.6 KiB
C++
// OfficeXlsFile.cpp : Implementation of COfficeXlsFile
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include <string>
|
|
#include <iostream>
|
|
|
|
#include <boost/algorithm/string/case_conv.hpp>
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
#include "../../Common/DocxFormat/Source/Base/Base.h"
|
|
#include "../../Common/DocxFormat/Source/SystemUtility/FileSystem/Directory.h"
|
|
|
|
#include "../source/XlsXlsxConverter/ConvertXls2Xlsx.h"
|
|
#include "../source/XlsXlsxConverter/progressCallback.h"
|
|
|
|
#include "../Common/XmlUtils.h"
|
|
|
|
#include "../../ASCOfficeUtils/ASCOfficeUtilsLib/OfficeUtils.h"
|
|
#include "../../Common/ASCATLError.h"
|
|
|
|
#include "OfficeXlsFile.h"
|
|
|
|
// ÂÍÈÌÀÍÈÅ: çíà÷åíèå 1 èñïîëüçóåòñÿ äëÿ òåñòèðîâàíèÿ, íà âûõîäå ïîëó÷àåì çààðõèâèðîâàííûé ôàéë xlsx èëè docx
|
|
// çíà÷åíèå 0 èñïîëüçóåòñÿ äëÿ ðåëèçà, òàê êàê íà âûõîäå ïî ñïåöèôèêàöèè íàì òðåáóåòñÿ ðàñïàêîâàííûé package
|
|
#ifndef STANDALONE_USE
|
|
#define STANDALONE_USE 0// ÷òî ïîëó÷àåì íà âûõîäå: ôàéë (1) èëè ïàïêó (0)
|
|
#endif
|
|
|
|
|
|
|
|
std::wstring bstr2wstring(BSTR str)
|
|
{
|
|
return str ? std::wstring(&str[0], &str[::SysStringLen(str)]) : L"";
|
|
}
|
|
|
|
///------------------------------------------------------------------------------------
|
|
|
|
// COfficeXlsFile
|
|
COfficeXlsFile::COfficeXlsFile()
|
|
{
|
|
}
|
|
|
|
HRESULT COfficeXlsFile::SaveToFile(BSTR sDstFileName, BSTR sSrcPath, BSTR sXMLOptions)
|
|
{
|
|
return E_NOTIMPL;
|
|
}
|
|
|
|
HRESULT COfficeXlsFile::LoadFromFile(BSTR sSrcFileName, BSTR sDstPath, BSTR sXMLOptions)
|
|
{
|
|
HRESULT hr = AVS_ERROR_UNEXPECTED;
|
|
|
|
if (!sDstPath)
|
|
{
|
|
_ASSERTE(!!sDstPath);
|
|
return E_FAIL;
|
|
}
|
|
|
|
#if defined(STANDALONE_USE) && (STANDALONE_USE == 1)
|
|
std::wstring outputDir = FileSystem::Directory::GetFolderPath(std::wstring(sDstPath));
|
|
#else
|
|
std::wstring outputDir = sDstPath;
|
|
#endif
|
|
|
|
#if defined(STANDALONE_USE) && (STANDALONE_USE == 1)
|
|
std::wstring dstTempPath = FileSystem::Directory::CreateDirectoryWithUniqueName(outputDir);
|
|
#else
|
|
std::wstring dstTempPath = outputDir;
|
|
#endif
|
|
|
|
try
|
|
{
|
|
|
|
hr = LoadFromFileImpl(bstr2wstring(sSrcFileName), dstTempPath, bstr2wstring(sDstPath));
|
|
|
|
}
|
|
catch(...)
|
|
{
|
|
hr = E_FAIL;
|
|
}
|
|
|
|
|
|
|
|
#if defined(STANDALONE_USE) && (STANDALONE_USE == 1)
|
|
// â ñëó÷àå åñëè íà âûõîäå ôàéë — ñòèðàåì âðåìåííóþ äèðåêòîðèþ (ìû ñàìè åå ñîçäàëè)
|
|
try
|
|
{
|
|
FileSystem::Directory::DeleteDirectory(dstTempPath);
|
|
}
|
|
catch(...)
|
|
{
|
|
}
|
|
#endif
|
|
|
|
return hr;
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
void COfficeXlsFile::OnProgressFunc (LPVOID lpParam, long nID, long nPercent)
|
|
{
|
|
COfficeXlsFile* pXlsFile = reinterpret_cast<COfficeXlsFile*>(lpParam);
|
|
if (pXlsFile != NULL)
|
|
{
|
|
pXlsFile->OnProgress(nID, nPercent);
|
|
}
|
|
}
|
|
|
|
void COfficeXlsFile::OnProgressExFunc (LPVOID lpParam, long nID, long nPercent, short* pStop)
|
|
{
|
|
COfficeXlsFile* pXlsFile = reinterpret_cast<COfficeXlsFile*>(lpParam);
|
|
if (pXlsFile != NULL)
|
|
{
|
|
pXlsFile->OnProgressEx(nID, nPercent, pStop);
|
|
}
|
|
}
|