mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
.
This commit is contained in:
@ -242,8 +242,8 @@ namespace OOX
|
||||
}
|
||||
std::wstring CPath::GetExtention(bool bIsPoint) const
|
||||
{
|
||||
int nFind = (int)m_strFilename.rfind('.');
|
||||
if (-1 == nFind)
|
||||
size_t nFind = m_strFilename.rfind('.');
|
||||
if (std::wstring::npos == nFind)
|
||||
return L"";
|
||||
|
||||
if (!bIsPoint)
|
||||
@ -251,6 +251,19 @@ namespace OOX
|
||||
|
||||
return m_strFilename.substr(nFind);
|
||||
}
|
||||
void CPath::SetExtention(const std::wstring& ext)
|
||||
{
|
||||
size_t nFind = m_strFilename.rfind('.');
|
||||
if (std::wstring::npos == nFind)
|
||||
{
|
||||
m_strFilename += L"." + ext;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_strFilename = m_strFilename.substr(nFind + 1) + ext;
|
||||
}
|
||||
|
||||
}
|
||||
std::wstring CPath::GetDirectory(bool bIsSlash) const
|
||||
{
|
||||
int nPos = (int)m_strFilename.rfind(FILE_SEPARATOR_CHAR);
|
||||
|
||||
@ -42,7 +42,6 @@ namespace OOX
|
||||
//флаг введен, чтобы отличать относительные и абсолютные пути в rels
|
||||
bool m_bIsRoot;
|
||||
|
||||
public:
|
||||
CPath();
|
||||
CPath(const std::wstring& sName, bool bIsNorm = true);
|
||||
CPath(const char*& sName, bool bIsNorm = true);
|
||||
@ -70,6 +69,8 @@ namespace OOX
|
||||
std::wstring GetPath() const;
|
||||
std::wstring GetFilename() const;
|
||||
|
||||
void SetExtention(const std::wstring & ext);
|
||||
|
||||
void Normalize();
|
||||
|
||||
void SetName(std::wstring sName, bool bNormalize);
|
||||
|
||||
@ -30,6 +30,8 @@
|
||||
*
|
||||
*/
|
||||
#include "Xlsb.h"
|
||||
#include "../DocxFormat/App.h"
|
||||
#include "../DocxFormat/Core.h"
|
||||
|
||||
#include "../XlsxFormat/Workbook/Workbook.h"
|
||||
#include "../XlsxFormat/SharedStrings/SharedStrings.h"
|
||||
@ -93,7 +95,17 @@ bool OOX::Spreadsheet::CXlsb::ReadBin(const CPath& oFilePath, XLS::BaseObject* o
|
||||
|
||||
return true;
|
||||
}
|
||||
bool OOX::Spreadsheet::CXlsb::WriteBin(const CPath& oDirPath, OOX::CContentTypes& oContentTypes)
|
||||
{
|
||||
if (NULL == m_pWorkbook)
|
||||
return false;
|
||||
|
||||
m_bWriteToXlsb = true;
|
||||
IFileContainer::Write(oDirPath / L"", OOX::CPath(_T("")), oContentTypes);
|
||||
|
||||
oContentTypes.Write(oDirPath);
|
||||
return true;
|
||||
}
|
||||
bool OOX::Spreadsheet::CXlsb::WriteBin(const CPath& oFilePath, XLS::BaseObject* objStream)
|
||||
{
|
||||
if (m_binaryWriter->CreateFileW(oFilePath.GetPath()) == false)
|
||||
@ -102,7 +114,8 @@ bool OOX::Spreadsheet::CXlsb::WriteBin(const CPath& oFilePath, XLS::BaseObject*
|
||||
XLS::StreamCacheWriterPtr writer(new XLS::BinaryStreamCacheWriter(m_binaryWriter, xls_global_info));
|
||||
XLS::BinWriterProcessor proc(writer, objStream);
|
||||
proc.mandatory(*objStream);
|
||||
m_binaryWriter->WriteFile(m_binaryWriter->GetBuffer(), (static_cast<NSBinPptxRW::CBinaryFileWriter*>(m_binaryWriter.get()))->GetPosition());
|
||||
|
||||
m_binaryWriter->WriteFile(m_binaryWriter->GetBuffer(), (static_cast<NSBinPptxRW::CBinaryFileWriter*>(m_binaryWriter.get()))->GetPosition());
|
||||
m_binaryWriter->CloseFile();
|
||||
|
||||
return true;
|
||||
|
||||
@ -60,9 +60,12 @@ namespace OOX
|
||||
init();
|
||||
}
|
||||
~CXlsb();
|
||||
|
||||
|
||||
bool ReadBin(const CPath& oFilePath, XLS::BaseObject* objStream);
|
||||
bool WriteBin(const CPath& oFilePath, XLS::BaseObject* objStream);
|
||||
|
||||
bool WriteBin(const CPath& oDirPath, OOX::CContentTypes& oContentTypes);
|
||||
|
||||
XLS::GlobalWorkbookInfo* GetGlobalinfo();
|
||||
void PrepareSi();
|
||||
void PrepareTableFormula();
|
||||
@ -72,8 +75,10 @@ namespace OOX
|
||||
|
||||
bool IsWriteToXlsx();
|
||||
void WriteToXlsx(bool isXlsx);
|
||||
|
||||
|
||||
std::unordered_map<std::wstring, _UINT32> m_mapSheetNameSheetData;
|
||||
|
||||
bool m_bWriteToXlsb = false;
|
||||
private:
|
||||
|
||||
void init();
|
||||
@ -85,8 +90,7 @@ namespace OOX
|
||||
std::wstring m_sPath;
|
||||
OOX::CContentTypes m_oContentTypes;
|
||||
|
||||
bool m_bWriteToXlsx;
|
||||
|
||||
bool m_bWriteToXlsx = false;
|
||||
};
|
||||
|
||||
} //Spreadsheet
|
||||
|
||||
@ -32,6 +32,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Workbook.h"
|
||||
#include "../../XlsbFormat/Xlsb.h"
|
||||
|
||||
#include "../../XlsbFormat/WorkBookStream.h"
|
||||
|
||||
@ -273,7 +274,7 @@ namespace OOX
|
||||
}
|
||||
}
|
||||
|
||||
XLS::BaseObjectPtr CWorkbook::WriteBin()
|
||||
XLS::BaseObjectPtr CWorkbook::WriteBin() const
|
||||
{
|
||||
XLSB::WorkBookStreamPtr workBookStream(new XLSB::WorkBookStream);
|
||||
|
||||
@ -464,15 +465,23 @@ xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">
|
||||
}
|
||||
void CWorkbook::write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const
|
||||
{
|
||||
NSStringUtils::CStringBuilder sXml;
|
||||
CXlsb* xlsb = dynamic_cast<CXlsb*>(File::m_pMainDocument);
|
||||
if ((xlsb) && (xlsb->m_bWriteToXlsb))
|
||||
{
|
||||
XLS::BaseObjectPtr object = WriteBin();
|
||||
xlsb->WriteBin(oPath, object.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
NSStringUtils::CStringBuilder sXml;
|
||||
|
||||
sXml.WriteString(L"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
|
||||
sXml.WriteString(L"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
|
||||
|
||||
toXML(sXml);
|
||||
|
||||
std::wstring sPath = oPath.GetPath();
|
||||
NSFile::CFileBinary::SaveToFile(sPath.c_str(), sXml.GetData());
|
||||
toXML(sXml);
|
||||
|
||||
std::wstring sPath = oPath.GetPath();
|
||||
NSFile::CFileBinary::SaveToFile(sPath.c_str(), sXml.GetData());
|
||||
}
|
||||
oContent.Registration(type().OverrideType(), oDirectory, oPath.GetFilename());
|
||||
IFileContainer::Write(oPath, oDirectory, oContent);
|
||||
}
|
||||
@ -487,7 +496,17 @@ xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">
|
||||
}
|
||||
const CPath CWorkbook::DefaultFileName() const
|
||||
{
|
||||
return type().DefaultFileName();
|
||||
CXlsb* xlsb = dynamic_cast<CXlsb*>(File::m_pMainDocument);
|
||||
if ((xlsb) && (xlsb->m_bWriteToXlsb))
|
||||
{
|
||||
CPath name = type().DefaultFileName();
|
||||
name.SetExtention(L"bin");
|
||||
return name;
|
||||
}
|
||||
else
|
||||
{
|
||||
return type().DefaultFileName();
|
||||
}
|
||||
}
|
||||
EElementType CWorkbook::getType () const
|
||||
{
|
||||
|
||||
@ -122,7 +122,7 @@ namespace OOX
|
||||
virtual ~CWorkbook();
|
||||
|
||||
void readBin(const CPath& oPath);
|
||||
XLS::BaseObjectPtr WriteBin();
|
||||
XLS::BaseObjectPtr WriteBin() const;
|
||||
virtual void read(const CPath& oPath);
|
||||
virtual void read(const CPath& oRootPath, const CPath& oPath);
|
||||
virtual void fromXML(XmlUtils::CXmlNode& node);
|
||||
|
||||
@ -1155,11 +1155,12 @@ namespace NExtractTools
|
||||
//---------------------------------------------------------------------
|
||||
const OOX::CPath oox_path(sFrom);
|
||||
|
||||
OOX::Spreadsheet::CXlsx xlsx(oox_path);
|
||||
OOX::Spreadsheet::CXlsb xlsb;
|
||||
OOX::Spreadsheet::CXlsb oXlsb;
|
||||
oXlsb.Read(oox_path);
|
||||
|
||||
OOX::CContentTypes oContentTypes;
|
||||
nRes = oXlsb.WriteBin(sTo, oContentTypes) ? S_OK : AVS_FILEUTILS_ERROR_CONVERT;
|
||||
|
||||
//XLS::BaseObjectPtr object = xlsx.toBin();
|
||||
//xlsb.WriteBin(sTempUnpackedXLSB, object.get());
|
||||
//---------------------------------------------------------------------
|
||||
if (SUCCEEDED_X2T(nRes))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user