Commit d6cd7c30 authored by ElenaSubbotina's avatar ElenaSubbotina

XlsFormat - support macros

x2t  - oom->oox
parent 89b384ab
......@@ -61,7 +61,7 @@ HRESULT convert_single(std::wstring fileName)
std::wstring outputDir = NSDirectory::GetFolderPath(dstPath);
std::wstring dstTempPath = NSDirectory::CreateDirectoryWithUniqueName(outputDir);
hr = ConvertXls2Xlsx(srcFileName, dstTempPath, L"password", L"C:\\Windows\\Fonts", NULL);
hr = ConvertXls2Xlsx(srcFileName, dstTempPath, L"password", L"C:\\Windows\\Fonts", NULL, true);
if (hr == S_OK)
{
......
......@@ -96,7 +96,63 @@ CompoundFile::CompoundFile(const std::wstring & file_path, const ReadWriteMode m
storage_ = NULL;
Open(file_path, mode);
}
// Opens "Workbook" stream and returns the only reference
void CompoundFile::copy_stream(std::string streamName, POLE::Storage * storageOut, bool withRoot)
{
POLE::Stream *stream = new POLE::Stream(storage_, streamName);
if (!stream) return;
stream->seek(0);
int size_stream = stream->size();
if (withRoot == false)
{
int pos = streamName.find("/");
if (pos >= 0)
streamName = streamName.substr(pos + 1);
}
POLE::Stream *streamNew = new POLE::Stream(storageOut, streamName, true, size_stream);
if (!streamNew) return;
unsigned char* data_stream = new unsigned char[size_stream];
if (data_stream)
{
stream->read(data_stream, size_stream);
streamNew->write(data_stream, size_stream);
delete []data_stream;
data_stream = NULL;
}
streamNew->flush();
delete streamNew;
delete stream;
}
void CompoundFile::copy( int indent, std::string path, POLE::Storage * storageOut, bool withRoot)
{
std::list<std::string> entries;
entries = storage_->entries( path );
std::list<std::string>::iterator it;
for( it = entries.begin(); it != entries.end(); ++it )
{
std::string name = *it;
std::string fullname = path + name;
if( storage_->isDirectory( fullname ) )
{
copy( indent + 1, fullname + "/", storageOut, withRoot );
}
else
{
copy_stream(fullname, storageOut, withRoot);
}
}
}
CFStreamPtr CompoundFile::getWorkbookStream()
{
CFStreamPtr stream = getNamedStream("Workbook");
......@@ -123,7 +179,6 @@ CFStreamPtr CompoundFile::getNamedStream(const std::string& name)
return streams[name];
}
CFStreamPtr CompoundFile::createNamedStream(const std::string& name)
{
if(!streams[name])
......
......@@ -58,11 +58,15 @@ public:
bool isError();
void copy( int indent, std::string path, POLE::Storage * storageOut, bool withRoot = true);
CFStreamPtr getWorkbookStream ();
CFStreamPtr getNamedStream (const std::string& name);
POLE::Storage *storage_;
private:
void copy_stream(std::string streamName, POLE::Storage * storageOut, bool withRoot = true);
POLE::Stream* openStream (const std::string & stream_name); // Opens a stream in the storage (shall be called not more than once per stream)
POLE::Stream* createStream (const std::string & stream_name); // Creates a new stream in the storage
......
......@@ -36,9 +36,9 @@
#include "../../../Common/OfficeFileErrorDescription.h"
long ConvertXls2Xlsx(const std::wstring & srcFile, const std::wstring & dstPath, const std::wstring & password, const std::wstring & fontsPath, const ProgressCallback* pCallBack)
long ConvertXls2Xlsx(const std::wstring & srcFile, const std::wstring & dstPath, const std::wstring & password, const std::wstring & fontsPath, const ProgressCallback* pCallBack, bool bMacros)
{
XlsConverter converter(srcFile, dstPath, password, fontsPath, pCallBack);
XlsConverter converter(srcFile, dstPath, password, fontsPath, pCallBack, bMacros);
if (converter.isError())
{
......
......@@ -33,4 +33,4 @@
struct ProgressCallback;
long ConvertXls2Xlsx(const std::wstring & srcFile, const std::wstring & dstPath, const std::wstring & password, const std::wstring& fontsPath, const ProgressCallback* CallBack);
\ No newline at end of file
long ConvertXls2Xlsx(const std::wstring & srcFile, const std::wstring & dstPath, const std::wstring & password, const std::wstring& fontsPath, const ProgressCallback* CallBack, bool bMacros);
\ No newline at end of file
......@@ -121,7 +121,7 @@ typedef struct tagBITMAPCOREHEADER {
} BITMAPCOREHEADER;
#endif
XlsConverter::XlsConverter(const std::wstring & xls_file, const std::wstring & _xlsx_path, const std::wstring & password, const std::wstring & fontsPath, const ProgressCallback* CallBack)
XlsConverter::XlsConverter(const std::wstring & xls_file, const std::wstring & _xlsx_path, const std::wstring & password, const std::wstring & fontsPath, const ProgressCallback* CallBack, bool bMacros)
{
xlsx_path = _xlsx_path;
output_document = NULL;
......@@ -131,8 +131,10 @@ XlsConverter::XlsConverter(const std::wstring & xls_file, const std::wstring & _
bUserStopConvert = false;
is_older_version = false;
is_encrypted = false;
output_document = new oox::package::xlsx_document();
try{
try
{
XLS::CompoundFile cfile(xls_file, XLS::CompoundFile::cf_ReadMode);
if (cfile.isError())
......@@ -218,6 +220,25 @@ XlsConverter::XlsConverter(const std::wstring & xls_file, const std::wstring & _
xls_global_info->mapPivotCache.insert(std::make_pair(index, pivot_cache));
}
}
if (bMacros && cfile.storage_->isDirectory("_VBA_PROJECT_CUR"))
{
std::wstring xl_path = xlsx_path + FILE_SEPARATOR_STR + L"xl";
NSDirectory::CreateDirectory(xl_path.c_str());
std::wstring sVbaProjectFile = xl_path + FILE_SEPARATOR_STR + L"vbaProject.bin";
POLE::Storage *storageVbaProject = new POLE::Storage(sVbaProjectFile.c_str());
if ((storageVbaProject) && (storageVbaProject->open(true, true)))
{
cfile.copy(0, "_VBA_PROJECT_CUR/", storageVbaProject, false);
storageVbaProject->close();
delete storageVbaProject;
output_document->get_xl_files().add_vba_project();
}
}
}
catch(...)
{
......@@ -231,7 +252,6 @@ XlsConverter::XlsConverter(const std::wstring & xls_file, const std::wstring & _
Log::error("Version xls is old !!! - " + std::string(sVer.begin(), sVer.end()));
is_older_version = true;
}
output_document = new oox::package::xlsx_document();
xlsx_context = new oox::xlsx_conversion_context(output_document);
}
......@@ -268,6 +288,7 @@ bool XlsConverter::UpdateProgress(long nComplete)
void XlsConverter::write()
{
if (!output_document)return;
output_document->write(xlsx_path);
delete output_document; output_document = NULL;
......
......@@ -93,7 +93,7 @@ namespace ODRAW
class XlsConverter
{
public:
XlsConverter(const std::wstring & xls_file, const std::wstring & xlsx_path, const std::wstring & password, const std::wstring & fontsPath, const ProgressCallback* ffCallBack);
XlsConverter(const std::wstring & xls_file, const std::wstring & xlsx_path, const std::wstring & password, const std::wstring & fontsPath, const ProgressCallback* ffCallBack, bool bMacros);
~XlsConverter() ;
oox::xlsx_conversion_context * xlsx_context;
......
......@@ -53,7 +53,6 @@ xlsx_content_types_file::xlsx_content_types_file()
content_type_.add_override(L"/_rels/.rels", L"application/vnd.openxmlformats-package.relationships+xml");
content_type_.add_override(L"/xl/_rels/workbook.xml.rels", L"application/vnd.openxmlformats-package.relationships+xml");
content_type_.add_override(L"/xl/workbook.xml", L"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml");
content_type_.add_override(L"/xl/styles.xml", L"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml");
content_type_.add_override(L"/docProps/app.xml", L"application/vnd.openxmlformats-officedocument.extended-properties+xml");
content_type_.add_override(L"/docProps/core.xml", L"application/vnd.openxmlformats-package.core-properties+xml");
......@@ -140,6 +139,7 @@ void sheets_files::write(const std::wstring & RootPath)
const std::wstring fileName = std::wstring(L"sheet") + std::to_wstring(i + 1) + L".xml";
content_type & contentTypes = this->get_main_document()->content_type().get_content_type();
static const std::wstring kWSConType = L"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml";
contentTypes.add_override(std::wstring(L"/xl/worksheets/") + fileName, kWSConType);
......@@ -168,6 +168,7 @@ void sheets_files::write(const std::wstring & RootPath)
xl_files::xl_files()
{
rels_files_.add_rel_file(rels_file::create(L"workbook.xml.rels"));
bVbaProject = false;
}
void xl_files::write(const std::wstring & RootPath)
......@@ -175,6 +176,8 @@ void xl_files::write(const std::wstring & RootPath)
std::wstring path = RootPath + FILE_SEPARATOR_STR + L"xl";
NSDirectory::CreateDirectory(path.c_str());
content_type & contentTypes = this->get_main_document()->content_type().get_content_type();
{
pivot_cache_files_.set_rels(&rels_files_);
pivot_cache_files_.set_main_document(get_main_document());
......@@ -204,7 +207,6 @@ void xl_files::write(const std::wstring & RootPath)
connections_->write(path);
rels_files_.add( relationship( L"cnId1", L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/connections", L"connections.xml" ) );
content_type & contentTypes = this->get_main_document()->content_type().get_content_type();
contentTypes.add_override(L"/xl/connections.xml", L"application/vnd.openxmlformats-officedocument.spreadsheetml.connections+xml");
}
......@@ -217,6 +219,18 @@ void xl_files::write(const std::wstring & RootPath)
if (workbook_)
{
workbook_->write(path);
if (bVbaProject)
{
rels_files_.add( relationship( L"vbId1", L"http://schemas.microsoft.com/office/2006/relationships/vbaProject", L"vbaProject.bin" ) );
contentTypes.add_override(L"/xl/vbaProject.bin", L"application/vnd.ms-office.vbaProject");
contentTypes.add_override(L"/xl/workbook.xml", L"application/vnd.ms-excel.sheet.macroEnabled.main+xml");
}
else
{
contentTypes.add_override(L"/xl/workbook.xml", L"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml");
}
}
if (theme_)
......@@ -253,6 +267,11 @@ void xl_files::write(const std::wstring & RootPath)
rels_files_.write(path);
}
void xl_files::add_vba_project()
{
bVbaProject = true;
}
void xl_files::set_workbook(element_ptr Element)
{
workbook_ = Element;
......
......@@ -226,6 +226,8 @@ public:
void add_charts (chart_content_ptr chart);
void add_pivot_cache (pivot_cache_content_ptr cache);
void add_pivot_table (pivot_table_content_ptr table);
void add_vba_project ();
private:
rels_files rels_files_;
sheets_files sheets_files_;
......@@ -244,6 +246,8 @@ private:
element_ptr vml_drawings_;
element_ptr comments_;
bool bVbaProject;
};
class xlsx_document : public document
......@@ -251,7 +255,6 @@ class xlsx_document : public document
public:
xlsx_document();
public:
virtual void write(const std::wstring & RootPath);
virtual content_types_file & content_type() { return content_type_; }
xl_files & get_xl_files() { return xl_files_; }
......
......@@ -357,47 +357,57 @@ bool COfficeFileFormatChecker::isOOXFormatFile(const std::wstring & fileName)
std::string::size_type res1 = std::string::npos;
std::string::size_type res = 0;
if ((std::string::npos != strContentTypes.find(docxFormatLine)) ||
(std::string::npos != strContentTypes.find(docmFormatLine)))
if (std::string::npos != strContentTypes.find(docxFormatLine))
{
nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX;
}
else if ((std::string::npos != strContentTypes.find(dotxFormatLine)))
else if (std::string::npos != strContentTypes.find(docmFormatLine))
{
nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCM;
}
else if (std::string::npos != strContentTypes.find(dotxFormatLine))
{
nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_DOTX;
}
else if ((std::string::npos != strContentTypes.find(dotmFormatLine)))
else if (std::string::npos != strContentTypes.find(dotmFormatLine))
{
nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_DOTM;
}
else if ((std::string::npos != strContentTypes.find(xlsxFormatLine)) ||
(std::string::npos != strContentTypes.find(xlsmFormatLine)))
else if (std::string::npos != strContentTypes.find(xlsxFormatLine))
{
nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX;
}
else if ((std::string::npos != strContentTypes.find(xltxFormatLine)))
else if (std::string::npos != strContentTypes.find(xlsmFormatLine))
{
nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSM;
}
else if (std::string::npos != strContentTypes.find(xltxFormatLine))
{
nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTX;
}
else if ((std::string::npos != strContentTypes.find(xltmFormatLine)))
else if (std::string::npos != strContentTypes.find(xltmFormatLine))
{
nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTM;
}
else if ((std::string::npos != strContentTypes.find(pptxFormatLine)) ||
(std::string::npos != strContentTypes.find(pptmFormatLine)) ||
(std::string::npos != strContentTypes.find(ppsmFormatLine)))
else if (std::string::npos != strContentTypes.find(pptxFormatLine))
{
nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX;
}
else if ((std::string::npos != strContentTypes.find(ppsxFormatLine)))
else if ((std::string::npos != strContentTypes.find(pptmFormatLine)) ||
(std::string::npos != strContentTypes.find(ppsmFormatLine)))
{
nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTM;
}
else if (std::string::npos != strContentTypes.find(ppsxFormatLine))
{
nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_PPSX;
}
else if ((std::string::npos != strContentTypes.find(potxFormatLine)))
else if (std::string::npos != strContentTypes.find(potxFormatLine))
{
nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_POTX;
}
else if ((std::string::npos != strContentTypes.find(potmFormatLine)))
else if (std::string::npos != strContentTypes.find(potmFormatLine))
{
nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_POTM;
}
......
......@@ -264,6 +264,85 @@ namespace NExtractTools
}
}
return AVS_FILEUTILS_ERROR_CONVERT;
}
// docm -> docx
int docm2docx (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
{
std::wstring sTempUnpackedDOCX = sTemp + FILE_SEPARATOR_STR + _T("docx_unpacked");
NSDirectory::CreateDirectory(sTempUnpackedDOCX);
int nRes = docm2docx_dir(sFrom, sTempUnpackedDOCX, params);
if(SUCCEEDED_X2T(nRes))
{
COfficeUtils oCOfficeUtils(NULL);
if(S_OK == oCOfficeUtils.CompressFileOrDirectory(sTempUnpackedDOCX, sTo, true))
return 0;
}
return AVS_FILEUTILS_ERROR_CONVERT;
}
int docm2docx_dir (const std::wstring &sFrom, const std::wstring &sTo, InputParams& params)
{
COfficeUtils oCOfficeUtils(NULL);
if (S_OK == oCOfficeUtils.ExtractToDirectory(sFrom, sTo, NULL, 0))
{
std::wstring sContentTypesPath = sTo + FILE_SEPARATOR_STR + _T("[Content_Types].xml");
if(NSFile::CFileBinary::Exists(sContentTypesPath))
{
std::wstring sData;
if(NSFile::CFileBinary::ReadAllTextUtf8(sContentTypesPath, sData))
{
std::wstring sCTFrom = _T("application/vnd.ms-word.document.macroEnabled.main+xml");
std::wstring sCTTo = _T("application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml");
sData = string_replaceAll(sData, sCTFrom, sCTTo);
sCTFrom = L"<Override PartName=\"/word/vbaProject.bin\" ContentType=\"application/vnd.ms-office.vbaProject\"/>";
sData = string_replaceAll(sData, sCTFrom, L"");
sCTFrom = L"<Override PartName=\"/word/vbaData.xml\" ContentType=\"application/vnd.ms-word.vbaData+xml\"/>";
sData = string_replaceAll(sData, sCTFrom, L"");
sCTFrom = L"<Default Extension=\"bin\" ContentType=\"application/vnd.ms-office.vbaProject\"/>";
sData = string_replaceAll(sData, sCTFrom, L"");
if(NSFile::CFileBinary::SaveToFile(sContentTypesPath, sData, true) == false)
{
return AVS_FILEUTILS_ERROR_CONVERT;
}
}
}
std::wstring sDocumentRelsPath = sTo + FILE_SEPARATOR_STR + L"word" + FILE_SEPARATOR_STR + L"_rels" + FILE_SEPARATOR_STR + L"document.xml.rels";
if(NSFile::CFileBinary::Exists(sDocumentRelsPath))
{
std::wstring sData;
if(NSFile::CFileBinary::ReadAllTextUtf8(sDocumentRelsPath, sData))
{
int pos = sData.find(L"vbaProject.bin");
if (pos > 0)
{
int pos1 = sData.rfind(L"<", pos);
int pos2 = sData.find(L">", pos);
if (pos1 > 0 && pos2 > 0)
{
sData.erase(sData.begin() + pos1, sData.begin() + pos2 + 1);
}
}
if(NSFile::CFileBinary::SaveToFile(sDocumentRelsPath, sData, true) == false)
{
return AVS_FILEUTILS_ERROR_CONVERT;
}
}
}
std::wstring sVbaProjectPath = sTo + FILE_SEPARATOR_STR + L"word" + FILE_SEPARATOR_STR + L"vbaProject.bin";
NSFile::CFileBinary::Remove(sVbaProjectPath);
std::wstring sVbaProjectRelsPath = sTo + FILE_SEPARATOR_STR + L"word" + FILE_SEPARATOR_STR + L"_rels" + FILE_SEPARATOR_STR + L"vbaProject.bin.rels";
NSFile::CFileBinary::Remove(sVbaProjectRelsPath);
std::wstring sVbaDataPath = sTo + FILE_SEPARATOR_STR + L"word" + FILE_SEPARATOR_STR + L"vbaData.xml";
NSFile::CFileBinary::Remove(sVbaDataPath);
}
return 0;
}
// dotm -> docm
int dotm2docm (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
......@@ -466,6 +545,76 @@ namespace NExtractTools
}
return AVS_FILEUTILS_ERROR_CONVERT;
}
// xlsm -> xlsx
int xlsm2xlsx (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
{
std::wstring sTempUnpackedXLSX = sTemp + FILE_SEPARATOR_STR + _T("xlsx_unpacked");
NSDirectory::CreateDirectory(sTempUnpackedXLSX);
int nRes = xlsm2xlsx_dir(sFrom, sTempUnpackedXLSX, params);
if(SUCCEEDED_X2T(nRes))
{
COfficeUtils oCOfficeUtils(NULL);
if(S_OK == oCOfficeUtils.CompressFileOrDirectory(sTempUnpackedXLSX, sTo, true))
return 0;
}
return AVS_FILEUTILS_ERROR_CONVERT;
}
int xlsm2xlsx_dir (const std::wstring &sFrom, const std::wstring &sTo, InputParams& params)
{
COfficeUtils oCOfficeUtils(NULL);
if (S_OK == oCOfficeUtils.ExtractToDirectory(sFrom, sTo, NULL, 0))
{
std::wstring sContentTypesPath = sTo + FILE_SEPARATOR_STR + _T("[Content_Types].xml");
if(NSFile::CFileBinary::Exists(sContentTypesPath))
{
std::wstring sData;
if(NSFile::CFileBinary::ReadAllTextUtf8(sContentTypesPath, sData))
{
std::wstring sCTFrom = L"application/vnd.ms-excel.sheet.macroEnabled.main+xml";
std::wstring sCTTo = L"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml";
sData = string_replaceAll(sData, sCTFrom, sCTTo);
sCTFrom = L"<Override PartName=\"/xl/vbaProject.bin\" ContentType=\"application/vnd.ms-office.vbaProject\"/>";
sData = string_replaceAll(sData, sCTFrom, L"");
sCTFrom = L"<Default Extension=\"bin\" ContentType=\"application/vnd.ms-office.vbaProject\"/>";
sData = string_replaceAll(sData, sCTFrom, L"");
if(NSFile::CFileBinary::SaveToFile(sContentTypesPath, sData, true) == false)
{
return AVS_FILEUTILS_ERROR_CONVERT;
}
}
}
std::wstring sWorkbookRelsPath = sTo + FILE_SEPARATOR_STR + L"xl" + FILE_SEPARATOR_STR + L"_rels" + FILE_SEPARATOR_STR + L"workbook.xml.rels";
if(NSFile::CFileBinary::Exists(sWorkbookRelsPath))
{
std::wstring sData;
if(NSFile::CFileBinary::ReadAllTextUtf8(sWorkbookRelsPath, sData))
{
int pos = sData.find(L"vbaProject.bin");
if (pos > 0)
{
int pos1 = sData.rfind(L"<", pos);
int pos2 = sData.find(L">", pos);
if (pos1 > 0 && pos2 > 0)
{
sData.erase(sData.begin() + pos1, sData.begin() + pos2 + 1);
}
}
if(NSFile::CFileBinary::SaveToFile(sWorkbookRelsPath, sData, true) == false)
{
return AVS_FILEUTILS_ERROR_CONVERT;
}
}
}
std::wstring sVbaProjectPath = sTo + FILE_SEPARATOR_STR + L"xl" + FILE_SEPARATOR_STR + L"vbaProject.bin";
NSFile::CFileBinary::Remove(sVbaProjectPath);
}
return 0;
}
// xltm -> xlsm
int xltm2xlsm (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
{
......@@ -1029,6 +1178,77 @@ namespace NExtractTools
}
}
return AVS_FILEUTILS_ERROR_CONVERT;
}
// pptm -> pptx
int pptm2pptx (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
{
std::wstring sTempUnpackedPPTX = sTemp + FILE_SEPARATOR_STR + _T("pptx_unpacked");
NSDirectory::CreateDirectory(sTempUnpackedPPTX);
int nRes = pptm2pptx_dir(sFrom, sTempUnpackedPPTX, params);
if(SUCCEEDED_X2T(nRes))
{
COfficeUtils oCOfficeUtils(NULL);
if(S_OK == oCOfficeUtils.CompressFileOrDirectory(sTempUnpackedPPTX, sTo, true))
return 0;
}
return AVS_FILEUTILS_ERROR_CONVERT;
}
int pptm2pptx_dir (const std::wstring &sFrom, const std::wstring &sTo, InputParams& params)
{
COfficeUtils oCOfficeUtils(NULL);
if (S_OK == oCOfficeUtils.ExtractToDirectory(sFrom, sTo, NULL, 0))
{
std::wstring sContentTypesPath = sTo + FILE_SEPARATOR_STR + _T("[Content_Types].xml");
if(NSFile::CFileBinary::Exists(sContentTypesPath))
{
std::wstring sData;
if(NSFile::CFileBinary::ReadAllTextUtf8(sContentTypesPath, sData))
{
std::wstring sCTFrom = _T("application/vnd.ms-powerpoint.presentation.macroEnabled.main+xml");
std::wstring sCTTo = _T("application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml");
sData = string_replaceAll(sData, sCTFrom, sCTTo);
sCTFrom = L"<Override PartName=\"/ppt/vbaProject.bin\" ContentType=\"application/vnd.ms-office.vbaProject\"/>";
sData = string_replaceAll(sData, sCTFrom, L"");
sCTFrom = L"<Default Extension=\"bin\" ContentType=\"application/vnd.ms-office.vbaProject\"/>";
sData = string_replaceAll(sData, sCTFrom, L"");
if(NSFile::CFileBinary::SaveToFile(sContentTypesPath, sData, true) == false)
{
return AVS_FILEUTILS_ERROR_CONVERT;
}
}
}
std::wstring sPresentationRelsPath = sTo + FILE_SEPARATOR_STR + L"ppt" + FILE_SEPARATOR_STR + L"_rels" + FILE_SEPARATOR_STR + L"presentation.xml.rels";
if(NSFile::CFileBinary::Exists(sPresentationRelsPath))
{
std::wstring sData;
if(NSFile::CFileBinary::ReadAllTextUtf8(sPresentationRelsPath, sData))
{
int pos = sData.find(L"vbaProject.bin");
if (pos > 0)
{
int pos1 = sData.rfind(L"<", pos);
int pos2 = sData.find(L">", pos);
if (pos1 > 0 && pos2 > 0)
{
sData.erase(sData.begin() + pos1, sData.begin() + pos2 + 1);
}
}
if(NSFile::CFileBinary::SaveToFile(sPresentationRelsPath, sData, true) == false)
{
return AVS_FILEUTILS_ERROR_CONVERT;
}
}
}
std::wstring sVbaProjectPath = sTo + FILE_SEPARATOR_STR + L"ppt" + FILE_SEPARATOR_STR + L"vbaProject.bin";
NSFile::CFileBinary::Remove(sVbaProjectPath);
}
return 0;
}
// potx -> pptx
int potx2pptx (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
......@@ -1943,10 +2163,15 @@ namespace NExtractTools
NSDoctRenderer::DoctRendererFormat::FormatFile eTypeTo;
switch(*oMailMergeSend.mailFormat)
{
case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX:eTypeTo = NSDoctRenderer::DoctRendererFormat::FormatFile::DOCT;break;
case AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_PDF:eTypeTo = NSDoctRenderer::DoctRendererFormat::FormatFile::PDF;break;
case AVS_OFFICESTUDIO_FILE_OTHER_HTMLZIP:eTypeTo = NSDoctRenderer::DoctRendererFormat::FormatFile::HTML;break;
default:eTypeTo = NSDoctRenderer::DoctRendererFormat::FormatFile::HTML;break;
case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX:
case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCM:
eTypeTo = NSDoctRenderer::DoctRendererFormat::FormatFile::DOCT; break;
case AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_PDF:
eTypeTo = NSDoctRenderer::DoctRendererFormat::FormatFile::PDF; break;
case AVS_OFFICESTUDIO_FILE_OTHER_HTMLZIP:
eTypeTo = NSDoctRenderer::DoctRendererFormat::FormatFile::HTML; break;
default:
eTypeTo = NSDoctRenderer::DoctRendererFormat::FormatFile::HTML; break;
}
std::wstring sJsonPath = sFileFromDir + FILE_SEPARATOR_STR +_T("Editor.json");
int recordTo = *oMailMergeSend.recordFrom + 4;
......@@ -2396,6 +2621,7 @@ namespace NExtractTools
{
std::wstring sDocxDir = sTemp + FILE_SEPARATOR_STR + _T("docx_unpacked");
NSDirectory::CreateDirectory(sDocxDir);
if (AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX == nFormatFrom ||
AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCM == nFormatFrom)
{
......@@ -2856,7 +3082,7 @@ namespace NExtractTools
}
int xls2xlsx_dir (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
{
long hRes = ConvertXls2Xlsx( sFrom, sTo, params.getPassword(), params.getFontPath(), NULL);
long hRes = ConvertXls2Xlsx( sFrom, sTo, params.getPassword(), params.getFontPath(), NULL, false);
if (AVS_ERROR_DRM == hRes)
{
if(!params.getDontSaveAdditional())
......@@ -2871,7 +3097,39 @@ namespace NExtractTools
}
return 0 == hRes ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
}
// xls -> xlsm
int xls2xlsm (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
{
std::wstring sResultXlsmDir = sTemp + FILE_SEPARATOR_STR + _T("xlsm_unpacked");
NSDirectory::CreateDirectory(sResultXlsmDir);
int nRes = xls2xlsm_dir(sFrom, sResultXlsmDir, sTemp, params);
if(SUCCEEDED_X2T(nRes))
{
COfficeUtils oCOfficeUtils(NULL);
if(S_OK == oCOfficeUtils.CompressFileOrDirectory(sResultXlsmDir, sTo, true))
return 0;
}
return AVS_FILEUTILS_ERROR_CONVERT;
}
int xls2xlsm_dir (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
{
long hRes = ConvertXls2Xlsx( sFrom, sTo, params.getPassword(), params.getFontPath(), NULL, true);
if (AVS_ERROR_DRM == hRes)
{
if(!params.getDontSaveAdditional())
{
copyOrigin(sFrom, *params.m_sFileTo);
}
return AVS_FILEUTILS_ERROR_CONVERT_DRM;
}
else if (AVS_ERROR_PASSWORD == hRes)
{
return AVS_FILEUTILS_ERROR_CONVERT_PASSWORD;
}
return 0 == hRes ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
}
// xls -> xlst
int xls2xlst (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
{
......@@ -2899,7 +3157,7 @@ namespace NExtractTools
NSDirectory::CreateDirectory(sResultXlsxDir);
if (ConvertXls2Xlsx( sFrom, sResultXlsxDir, params.getPassword(), params.getFontPath(), NULL)== S_OK)
if (ConvertXls2Xlsx( sFrom, sResultXlsxDir, params.getPassword(), params.getFontPath(), NULL, true)== S_OK)
{
BinXlsxRW::CXlsxSerializer m_oCXlsxSerializer;
......@@ -3064,6 +3322,10 @@ namespace NExtractTools
{
result = dotx2docx (sFileFrom, sFileTo, sTempDir, oInputParams);
}break;
case TCD_DOCM2DOCX:
{
result = docm2docx (sFileFrom, sFileTo, sTempDir, oInputParams);
}break;
case TCD_DOTM2DOCM:
{
result = dotm2docm (sFileFrom, sFileTo, sTempDir, oInputParams);
......@@ -3072,6 +3334,10 @@ namespace NExtractTools
{
result = xltx2xlsx (sFileFrom, sFileTo, sTempDir, oInputParams);
}break;
case TCD_XLSM2XLSX:
{
result = xltx2xlsx (sFileFrom, sFileTo, sTempDir, oInputParams);
}break;
case TCD_XLTM2XLSM:
{
result = xltm2xlsm (sFileFrom, sFileTo, sTempDir, oInputParams);
......@@ -3088,6 +3354,10 @@ namespace NExtractTools
{
result = potm2pptm (sFileFrom, sFileTo, sTempDir, oInputParams);
}break;
case TCD_PPTM2PPTX:
{
result = pptm2pptx (sFileFrom, sFileTo, sTempDir, oInputParams);
}break;
case TCD_ZIPDIR:
{
result = dir2zip (sFileFrom, sFileTo);
......@@ -3204,6 +3474,10 @@ namespace NExtractTools
{
result = xls2xlsx (sFileFrom, sFileTo, sTempDir, oInputParams);
}break;
case TCD_XLS2XLSM:
{
result = xls2xlsm (sFileFrom, sFileTo, sTempDir, oInputParams);
}break;
case TCD_XLS2XLST:
{
result = xls2xlst (sFileFrom, sFileTo, sTempDir, oInputParams);
......
......@@ -59,6 +59,8 @@ namespace NExtractTools
int dotx2docx_dir (const std::wstring &sFrom, const std::wstring &sTo, InputParams& params);
int dotm2docm (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
int dotm2docm_dir (const std::wstring &sFrom, const std::wstring &sTo, InputParams& params);
int docm2docx (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
int docm2docx_dir (const std::wstring &sFrom, const std::wstring &sTo, InputParams& params);
int xlsx2xlst_bin (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
int xlsx_dir2xlst_bin (const std::wstring &sFrom, const std::wstring &sTo, InputParams& params, bool bXmlOptions);
......@@ -71,6 +73,8 @@ namespace NExtractTools
int xltx2xlsx_dir (const std::wstring &sFrom, const std::wstring &sTo, InputParams& params);
int xltm2xlsm (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
int xltm2xlsm_dir (const std::wstring &sFrom, const std::wstring &sTo, InputParams& params);
int xlsm2xlsx (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
int xlsm2xlsx_dir (const std::wstring &sFrom, const std::wstring &sTo, InputParams& params);
int pptx2pptt_bin (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
int pptx_dir2pptt_bin (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
......@@ -94,6 +98,8 @@ namespace NExtractTools
int potx2pptx_dir (const std::wstring &sFrom, const std::wstring &sTo, InputParams& params);
int potm2pptm (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
int potm2pptm_dir (const std::wstring &sFrom, const std::wstring &sTo, InputParams& params);
int pptm2pptx (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
int pptm2pptx_dir (const std::wstring &sFrom, const std::wstring &sTo, InputParams& params);
int ppt2pptx (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
int ppt2pptx_dir (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
......@@ -119,6 +125,8 @@ namespace NExtractTools
int xls2xlsx_dir (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
int xls2xlst (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
int xls2xlst_bin (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
int xls2xlsm (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
int xls2xlsm_dir (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
int txt2docx (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
int txt2docx_dir (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
......
......@@ -117,7 +117,13 @@ namespace NExtractTools
else if (0 == sExt2.compare(_T(".bin"))) res = TCD_DOCX2DOCT_BIN;
else if (0 == sExt2.compare(_T(".rtf"))) res = TCD_DOCX2RTF;
else if (0 == sExt2.compare(_T(".odt"))) res = TCD_DOCX2ODT;
else if (0 == sExt2.compare(_T(".docx"))) res = TCD_DOTX2DOCX;
else if (0 == sExt2.compare(_T(".docx")))
{
if (OfficeFileFormatChecker.nFileType == AVS_OFFICESTUDIO_FILE_DOCUMENT_DOTX)
res = TCD_DOTX2DOCX;
if (OfficeFileFormatChecker.nFileType == AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCM)
res = TCD_DOCM2DOCX;
}
else if (0 == sExt2.compare(_T(".docm"))) res = TCD_DOTM2DOCM;
}break;
case AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX:
......@@ -129,7 +135,13 @@ namespace NExtractTools
else if (0 == sExt2.compare(_T(".bin"))) res = TCD_XLSX2XLST_BIN;
else if (0 == sExt2.compare(_T(".csv"))) res = TCD_XLSX2CSV;
else if (0 == sExt2.compare(_T(".ods"))) res = TCD_XLSX2ODS;
else if (0 == sExt2.compare(_T(".xlsx"))) res = TCD_XLTX2XLSX;
else if (0 == sExt2.compare(_T(".xlsx")))
{
if (OfficeFileFormatChecker.nFileType == AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTX)
res = TCD_XLTX2XLSX;
if (OfficeFileFormatChecker.nFileType == AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSM)
res = TCD_XLSM2XLSX;
}
else if (0 == sExt2.compare(_T(".xlsm"))) res = TCD_XLTM2XLSM;
}break;
case AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX:
......@@ -146,6 +158,8 @@ namespace NExtractTools
res = TCD_PPSX2PPTX;
if (OfficeFileFormatChecker.nFileType == AVS_OFFICESTUDIO_FILE_PRESENTATION_POTX)
res = TCD_POTX2PPTX;
if (OfficeFileFormatChecker.nFileType == AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTM)
res = TCD_PPTM2PPTX;
}
else if (0 == sExt2.compare(_T(".pptm"))) res = TCD_POTM2PPTM;
else if (0 == sExt2.compare(_T(".odp"))) res = TCD_PPTX2ODP;
......@@ -218,6 +232,7 @@ namespace NExtractTools
case AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLS:
{
if (0 == sExt2.compare(_T(".xlsx"))) res = TCD_XLS2XLSX;
else if (0 == sExt2.compare(_T(".xlsm"))) res = TCD_XLS2XLSM;
else if (0 == sExt2.compare(_T(".xlst"))) res = TCD_XLS2XLST;
else if (0 == sExt2.compare(_T(".bin"))) res = TCD_XLS2XLST_BIN;
}break;
......
......@@ -63,6 +63,7 @@ namespace NExtractTools
TCD_DOCX2DOCT_BIN,
TCD_DOCT_BIN2DOCX,
TCD_DOTX2DOCX,
TCD_DOCM2DOCX,
TCD_DOTM2DOCM,
TCD_XLSX2XLST,
......@@ -70,6 +71,7 @@ namespace NExtractTools
TCD_XLSX2XLST_BIN,
TCD_XLST_BIN2XLSX,
TCD_XLTX2XLSX,
TCD_XLSM2XLSX,
TCD_XLTM2XLSM,
TCD_PPTX2PPTT,
......@@ -78,6 +80,7 @@ namespace NExtractTools
TCD_PPTT_BIN2PPTX,
TCD_PPSX2PPTX,
TCD_POTX2PPTX,
TCD_PPTM2PPTX,
TCD_POTM2PPTM,
TCD_ZIPDIR,
......@@ -108,6 +111,7 @@ namespace NExtractTools
TCD_XLS2XLST,
TCD_XLS2XLST_BIN,
TCD_XLS2XLSX,
TCD_XLS2XLSM,
//rtf 2
TCD_RTF2DOCX,
TCD_RTF2DOCT,
......@@ -763,20 +767,42 @@ namespace NExtractTools
*m_nFormatFrom = formatFrom;
int toFormat = *m_nFormatTo;
if (AVS_OFFICESTUDIO_FILE_CANVAS == toFormat) {
if (AVS_OFFICESTUDIO_FILE_TEAMLAB_XLSY == formatFrom || 0 != (AVS_OFFICESTUDIO_FILE_SPREADSHEET & formatFrom)) {
if (AVS_OFFICESTUDIO_FILE_CANVAS == toFormat)
{
if ( AVS_OFFICESTUDIO_FILE_TEAMLAB_XLSY == formatFrom ||
0 != ( AVS_OFFICESTUDIO_FILE_SPREADSHEET & formatFrom))
{
toFormat = AVS_OFFICESTUDIO_FILE_CANVAS_SPREADSHEET;
} else if (AVS_OFFICESTUDIO_FILE_TEAMLAB_PPTY == formatFrom || 0 != (AVS_OFFICESTUDIO_FILE_PRESENTATION & formatFrom)) {
}
else if ( AVS_OFFICESTUDIO_FILE_TEAMLAB_PPTY == formatFrom
|| 0 != ( AVS_OFFICESTUDIO_FILE_PRESENTATION & formatFrom))
{
toFormat = AVS_OFFICESTUDIO_FILE_CANVAS_PRESENTATION;
} else if (AVS_OFFICESTUDIO_FILE_TEAMLAB_DOCY == formatFrom || 0 != (AVS_OFFICESTUDIO_FILE_DOCUMENT & formatFrom)) {
}
else if ( AVS_OFFICESTUDIO_FILE_TEAMLAB_DOCY == formatFrom ||
0 != ( AVS_OFFICESTUDIO_FILE_DOCUMENT & formatFrom))
{
toFormat = AVS_OFFICESTUDIO_FILE_CANVAS_WORD;
}
} else if (AVS_OFFICESTUDIO_FILE_OTHER_TEAMLAB_INNER == toFormat) {
if (AVS_OFFICESTUDIO_FILE_CANVAS_SPREADSHEET == formatFrom || AVS_OFFICESTUDIO_FILE_TEAMLAB_XLSY == formatFrom || 0 != (AVS_OFFICESTUDIO_FILE_SPREADSHEET & formatFrom)) {
}
else if ( AVS_OFFICESTUDIO_FILE_OTHER_TEAMLAB_INNER == toFormat)
{
if ( AVS_OFFICESTUDIO_FILE_CANVAS_SPREADSHEET == formatFrom ||
AVS_OFFICESTUDIO_FILE_TEAMLAB_XLSY == formatFrom ||
0 != ( AVS_OFFICESTUDIO_FILE_SPREADSHEET & formatFrom))
{
toFormat = AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX;
} else if (AVS_OFFICESTUDIO_FILE_CANVAS_PRESENTATION == formatFrom || AVS_OFFICESTUDIO_FILE_TEAMLAB_PPTY == formatFrom || 0 != (AVS_OFFICESTUDIO_FILE_PRESENTATION & formatFrom)) {
}
else if ( AVS_OFFICESTUDIO_FILE_CANVAS_PRESENTATION == formatFrom ||
AVS_OFFICESTUDIO_FILE_TEAMLAB_PPTY == formatFrom ||
0 != ( AVS_OFFICESTUDIO_FILE_PRESENTATION & formatFrom))
{
toFormat = AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX;
} else if (AVS_OFFICESTUDIO_FILE_CANVAS_WORD == formatFrom || AVS_OFFICESTUDIO_FILE_TEAMLAB_DOCY == formatFrom || 0 != (AVS_OFFICESTUDIO_FILE_DOCUMENT & formatFrom)) {
}
else if ( AVS_OFFICESTUDIO_FILE_CANVAS_WORD == formatFrom ||
AVS_OFFICESTUDIO_FILE_TEAMLAB_DOCY == formatFrom ||
0 != ( AVS_OFFICESTUDIO_FILE_DOCUMENT & formatFrom))
{
toFormat = AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX;
}
size_t nIndex = m_sFileTo->rfind('.');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment