Commit ac959e32 authored by konovalovsergey's avatar konovalovsergey

open/save ole object in a14 format xlsx

parent 1c2524f5
......@@ -1366,7 +1366,18 @@ rIns=\"91440\" bIns=\"45720\" numCol=\"1\" spcCol=\"0\" rtlCol=\"0\" fromWordArt
break;
}
else if (strName == L"AlternateContent")
else if (strName == L"oleObj")
{
nullable<PPTX::Logic::Pic> pic = oParseNode.ReadNode(_T("p:pic"));
if (pic.is_init())
{
pic->fromXMLOle(oParseNode);
m_pBinaryWriter->WriteRecord2(1, pic);
}
break;
}
else if (strName == L"AlternateContent")
{
XmlUtils::CXmlNode oNodeDr;
if (oParseNode.GetNode(L"w:drawing", oNodeDr))
......@@ -4304,7 +4315,26 @@ HRESULT CDrawingConverter::SaveObject(LONG lStart, LONG lLength, const CString&
m_pReader->Seek(_e);
return S_OK;
}
void CDrawingConverter::SaveObjectExWriterInit(NSBinPptxRW::CXmlWriter& oXmlWriter, LONG lDocType)
{
oXmlWriter.m_lObjectIdVML = m_pXmlWriter->m_lObjectIdVML;
oXmlWriter.m_lObjectIdOle = m_pXmlWriter->m_lObjectIdOle;
oXmlWriter.m_lDocType = (BYTE)lDocType;
oXmlWriter.m_bIsUseOffice2007 = false;
oXmlWriter.m_bIsTop = (1 == m_nCurrentIndexObject) ? true : false;
#if defined(BUILD_CONFIG_FULL_VERSION) && defined(AVS_USE_CONVERT_PPTX_TOCUSTOM_VML)
if (NULL == m_pOOXToVMLRenderer)
m_pOOXToVMLRenderer = new COOXToVMLGeometry();
oXmlWriter.m_pOOXToVMLRenderer = m_pOOXToVMLRenderer;
#endif
}
void CDrawingConverter::SaveObjectExWriterRelease(NSBinPptxRW::CXmlWriter& oXmlWriter)
{
m_pXmlWriter->m_lObjectIdVML = oXmlWriter.m_lObjectIdVML;
m_pXmlWriter->m_lObjectIdOle = oXmlWriter.m_lObjectIdOle;
}
HRESULT CDrawingConverter::SaveObjectEx(LONG lStart, LONG lLength, const CString& bsMainProps, LONG lDocType, CString** bsXml)
{
if (XMLWRITER_DOC_TYPE_DOCX == lDocType)
......@@ -4353,18 +4383,7 @@ HRESULT CDrawingConverter::SaveObjectEx(LONG lStart, LONG lLength, const CString
m_pReader->m_lDocumentType = XMLWRITER_DOC_TYPE_PPTX;
NSBinPptxRW::CXmlWriter oXmlWriter;
oXmlWriter.m_lObjectIdVML = m_pXmlWriter->m_lObjectIdVML;
oXmlWriter.m_lObjectIdOle = m_pXmlWriter->m_lObjectIdOle;
oXmlWriter.m_lDocType = (BYTE)lDocType;
oXmlWriter.m_bIsUseOffice2007 = false;
oXmlWriter.m_bIsTop = (1 == m_nCurrentIndexObject) ? true : false;
#if defined(BUILD_CONFIG_FULL_VERSION) && defined(AVS_USE_CONVERT_PPTX_TOCUSTOM_VML)
if (NULL == m_pOOXToVMLRenderer)
m_pOOXToVMLRenderer = new COOXToVMLGeometry();
oXmlWriter.m_pOOXToVMLRenderer = m_pOOXToVMLRenderer;
#endif
SaveObjectExWriterInit(oXmlWriter, lDocType);
if(bOle)
{
......@@ -4377,11 +4396,15 @@ HRESULT CDrawingConverter::SaveObjectEx(LONG lStart, LONG lLength, const CString
--m_nCurrentIndexObject;
m_pXmlWriter->m_lObjectIdVML = oXmlWriter.m_lObjectIdVML;
m_pXmlWriter->m_lObjectIdOle = oXmlWriter.m_lObjectIdOle;
SaveObjectExWriterRelease(oXmlWriter);
if (XMLWRITER_DOC_TYPE_XLSX == lDocType)
{
m_pXmlWriter->m_strOleXlsx = oXmlWriter.m_strOleXlsx;
NSBinPptxRW::CXmlWriter oXmlWriterXlsx;
SaveObjectExWriterInit(oXmlWriterXlsx, lDocType);
oElem.toXmlWriter(&oXmlWriterXlsx);
m_pXmlWriter->m_strOleDrawing = oXmlWriterXlsx.GetXmlString();
SaveObjectExWriterRelease(oXmlWriterXlsx);
}
CString ret = oXmlWriter.GetXmlString();
......@@ -5093,6 +5116,10 @@ std::wstring CDrawingConverter::GetOleXlsx()
{
return m_pXmlWriter->m_strOleXlsx;
}
std::wstring CDrawingConverter::GetOleDrawing()
{
return m_pXmlWriter->m_strOleDrawing;
}
void CDrawingConverter::SetSourceFileDir(std::wstring path, int type)
{
......
......@@ -219,6 +219,8 @@ namespace NSBinPptxRW
HRESULT SaveThemeXml (long lStart, long lLength, const CString& bsThemePath);
HRESULT SaveObject (long lStart, long lLength, const CString& bsMainProps, CString** bsXml);
HRESULT SaveObjectEx (long lStart, long lLength, const CString& bsMainProps, long lDocType, CString** bsXml);
void SaveObjectExWriterInit(NSBinPptxRW::CXmlWriter& oXmlWriter, LONG lDocType);
void SaveObjectExWriterRelease(NSBinPptxRW::CXmlWriter& oXmlWriter);
HRESULT GetRecordBinary (long lRecordType, const CString& bsXml);
HRESULT GetRecordXml (long lStart, long lLength, long lRecType, long lDocType, CString** bsXml);
......@@ -249,6 +251,7 @@ namespace NSBinPptxRW
std::wstring GetContentTypes();
std::wstring GetOleXlsx();
std::wstring GetOleDrawing();
protected:
nullable<PPTX::Logic::Xfrm> m_oxfrm_override;
......
......@@ -272,6 +272,7 @@ namespace NSBinPptxRW
std::wstring m_strAttributesMain;
std::wstring m_strNodes;
std::wstring m_strOleXlsx;
std::wstring m_strOleDrawing;
IRenderer* m_pOOXToVMLRenderer;
......
......@@ -100,7 +100,7 @@ namespace PPTX
oWriter.WriteNodeEnd(_T("Relationship"));
CDirectory::SaveToFile(file.GetPath(), oWriter.GetXmlString());
NSFile::CFileBinary::SaveToFile(file.GetPath(), oWriter.GetXmlString());
}
}
const bool isValid() const
......
......@@ -93,12 +93,12 @@ namespace PPTX
XmlUtils::CXmlNode oNode2 = oNodeData.ReadNodeNoNS(_T("oleObj"));
if (oNode2.IsValid())
{
fromXMLOle(oNode2);
oNode2.ReadAttributeBase(L"spid", spid);
pic = oNode2.ReadNode(_T("p:pic"));
if (pic.is_init())
{
pic->fromXMLOle(oNode2);
xfrm.Merge(pic->spPr.xfrm);
}
}
......@@ -121,11 +121,11 @@ namespace PPTX
XmlUtils::CXmlNode oNodeO;
if (oNodeFallback.GetNode(_T("p:oleObj"), oNodeO))
{
fromXMLOle(oNodeO);
pic = oNodeO.ReadNode(_T("p:pic"));
if (pic.is_init())
{
pic->fromXMLOle(oNode2);
xfrm.Merge(pic->spPr.xfrm);
}
}
......@@ -150,30 +150,9 @@ namespace PPTX
}
}
}
if(pic.IsInit() && oleObject.IsInit())
{
pic->oleObject = oleObject;
pic->blipFill.blip->oleRid = oleObject->m_oId.get().ToString();
}
FillParentPointersForChilds();
}
void GraphicFrame::fromXMLOle(XmlUtils::CXmlNode& node)
{
oleObject.Init();
node.ReadAttributeBase(L"progId", oleObject->m_sProgId);
node.ReadAttributeBase(L"r:id", oleObject->m_oId);
int imgW = node.GetAttributeInt(CString(L"imgW"), 0);
if(imgW > 0)
{
oleObject->m_oDxaOrig = Emu_To_Twips(imgW);
}
int imgH = node.GetAttributeInt(CString(L"imgH"), 0);
if(imgH > 0)
{
oleObject->m_oDyaOrig = Emu_To_Twips(imgH);
}
}
void GraphicFrame::toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const
{
......
......@@ -57,7 +57,6 @@ namespace PPTX
public:
virtual void fromXML(XmlUtils::CXmlNode& node);
void fromXMLOle(XmlUtils::CXmlNode& node);
virtual CString toXML() const;
virtual void GetRect(Aggplus::RECT& pRect)const;
......@@ -79,7 +78,6 @@ namespace PPTX
nullable<SmartArt> smartArt;
nullable<ChartRec> chartRec;
nullable<Pic> pic;
nullable<COLEObject> oleObject;
CString GetVmlXmlBySpid(CString & rels) const;
protected:
......
......@@ -780,5 +780,25 @@ namespace PPTX
pWriter->EndNode(sOleNodeName);
}
}
void Pic::fromXMLOle(XmlUtils::CXmlNode& node)
{
oleObject.Init();
node.ReadAttributeBase(L"progId", oleObject->m_sProgId);
node.ReadAttributeBase(L"r:id", oleObject->m_oId);
int imgW = node.GetAttributeInt(CString(L"imgW"), 0);
if(imgW > 0)
{
oleObject->m_oDxaOrig = Emu_To_Twips(imgW);
}
int imgH = node.GetAttributeInt(CString(L"imgH"), 0);
if(imgH > 0)
{
oleObject->m_oDyaOrig = Emu_To_Twips(imgH);
}
if(oleObject->m_oId.IsInit())
{
blipFill.blip->oleRid = oleObject->m_oId.get().ToString();
}
}
} // namespace Logic
} // namespace PPTX
......@@ -400,7 +400,7 @@ namespace PPTX
}
void toXmlWriterVML(NSBinPptxRW::CXmlWriter* pWriter, smart_ptr<PPTX::WrapperFile>& oTheme, smart_ptr<PPTX::WrapperWritingElement>& oClrMap);
void fromXMLOle(XmlUtils::CXmlNode& node);
public:
NvPicPr nvPicPr;
......
......@@ -43,6 +43,8 @@
#include "../Base/SmartPtr.h"
#include "../SystemUtility/SystemUtility.h"
#include "../../../../DesktopEditor/common/File.h"
#include <boost/algorithm/string.hpp>
namespace OOX
......@@ -269,7 +271,7 @@ namespace OOX
oWriter.WriteNodeEnd(_T("Relationships") );
CDirectory::SaveToFile( oFile.GetPath(), oWriter.GetXmlString() );
NSFile::CFileBinary::SaveToFile(oFile.GetPath(), oWriter.GetXmlString());
}
}
......
......@@ -65,6 +65,10 @@ namespace OOX
{
if(isValid())
{
if(m_oAlternateContent.IsInit() && m_oAlternateContent->ToBool())
{
writer.WriteString(L"<mc:AlternateContent xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\"><mc:Choice xmlns:a14=\"http://schemas.microsoft.com/office/drawing/2010/main\" Requires=\"a14\">");
}
std::wstring sStart;
std::wstring sEnd;
if(m_oFrom.IsInit() && m_oTo.IsInit())
......@@ -88,7 +92,7 @@ namespace OOX
if(m_oExt.IsInit())
m_oExt->toXML(writer);
}
else if(m_oPos.IsInit() && m_oExt.IsInit())
else
{
sStart.append(_T("<xdr:absoluteAnchor>"));
sEnd = _T("</xdr:absoluteAnchor>");
......@@ -98,13 +102,16 @@ namespace OOX
if(m_oExt.IsInit())
m_oExt->toXML(writer);
}
else
return;
if(m_oXml.IsInit())
writer.WriteString(m_oXml.get());
if(m_oGraphicFrame.IsInit())
m_oGraphicFrame->toXML(writer);
writer.WriteString(sEnd);
writer.WriteString(sEnd);
if(m_oAlternateContent.IsInit() && m_oAlternateContent->ToBool())
{
writer.WriteString(L"</mc:Choice><mc:Fallback/></mc:AlternateContent>");
}
}
}
virtual void fromXML(XmlUtils::CXmlLiteReader& oReader)
......@@ -292,6 +299,7 @@ namespace OOX
// для pptx:ObjectDrawingConverter
nullable<std::wstring> m_oXml;
nullable<SimpleTypes::COnOff<>> m_oAlternateContent;
//для удобства
nullable<std::wstring> m_sSpId;
......
......@@ -34,11 +34,194 @@
#define OOX_OLEOBJECTS_FILE_INCLUDE_H_
#include "../CommonInclude.h"
#include "../Drawing/FromTo.h"
namespace OOX
{
namespace Spreadsheet
{
class COleObjectAnchor : public WritingElement
{
public:
WritingElementSpreadsheet_AdditionConstructors(COleObjectAnchor)
COleObjectAnchor()
{
}
virtual ~COleObjectAnchor()
{
}
public:
virtual CString toXML() const
{
return _T("");
}
virtual void toXML(NSStringUtils::CStringBuilder& writer) const
{
writer.WriteString(L"<anchor");
WritingStringNullableAttrBool(L"moveWithCells", m_oMoveWithCells);
WritingStringNullableAttrBool(L"sizeWithCells", m_oSizeWithCells);
WritingStringNullableAttrInt(L"z-order", m_oZOrder, m_oZOrder->GetValue());
writer.WriteString(L">");
if (m_oFrom.IsInit())
{
m_oFrom->toXML2(writer, L"from");
}
if (m_oTo.IsInit())
{
m_oTo->toXML2(writer, L"to");
}
writer.WriteString(L"</anchor>");
}
virtual void fromXML(XmlUtils::CXmlLiteReader& oReader)
{
ReadAttributes( oReader );
if ( oReader.IsEmptyNode() )
return;
int nCurDepth = oReader.GetDepth();
while( oReader.ReadNextSiblingNode( nCurDepth ) )
{
std::wstring sName = XmlUtils::GetNameNoNS(oReader.GetName());
if ( _T("from") == sName )
{
m_oFrom = oReader;
}
else if ( _T("to") == sName )
{
m_oTo = oReader;
}
}
}
virtual EElementType getType () const
{
return et_OleObjectAnchor;
}
private:
void ReadAttributes(XmlUtils::CXmlLiteReader& oReader)
{
// Читаем атрибуты
WritingElement_ReadAttributes_Start( oReader )
WritingElement_ReadAttributes_Read_if ( oReader, _T("moveWithCells"), m_oMoveWithCells )
WritingElement_ReadAttributes_Read_else_if ( oReader, _T("sizeWithCells"), m_oSizeWithCells )
WritingElement_ReadAttributes_Read_else_if ( oReader, _T("z-order"), m_oZOrder )
WritingElement_ReadAttributes_End( oReader )
}
public:
nullable<SimpleTypes::COnOff<> > m_oMoveWithCells;
nullable<SimpleTypes::COnOff<> > m_oSizeWithCells;
nullable<SimpleTypes::CUnsignedDecimalNumber<> > m_oZOrder;
nullable<CFromTo > m_oFrom;
nullable<CFromTo > m_oTo;
};
class COleObjectPr : public WritingElement
{
public:
WritingElementSpreadsheet_AdditionConstructors(COleObjectPr)
COleObjectPr()
{
}
virtual ~COleObjectPr()
{
}
public:
virtual CString toXML() const
{
return _T("");
}
virtual void toXML(NSStringUtils::CStringBuilder& writer) const
{
writer.WriteString(L"<objectPr");
WritingStringNullableAttrEncodeXmlString(L"altText", m_oAltText, m_oAltText.get());
WritingStringNullableAttrBool(L"autoFill", m_oAutoFill);
WritingStringNullableAttrBool(L"autoLine", m_oAutoLine);
WritingStringNullableAttrBool(L"autoPict", m_oAutoPict);
WritingStringNullableAttrBool(L"dde", m_oDde);
WritingStringNullableAttrBool(L"defaultSize", m_oDefaultSize);
WritingStringNullableAttrBool(L"disabled", m_oDisabled);
WritingStringNullableAttrString(L"r:id", m_oRid, m_oRid->ToString2());
WritingStringNullableAttrBool(L"locked", m_oLocked);
WritingStringNullableAttrEncodeXmlString(L"macro", m_oMacro, m_oMacro.get());
WritingStringNullableAttrBool(L"print", m_oPrint);
WritingStringNullableAttrBool(L"uiObject", m_oUiObject);
writer.WriteString(L">");
if (m_oAnchor.IsInit())
{
m_oAnchor->toXML(writer);
}
writer.WriteString(L"</objectPr>");
}
virtual void fromXML(XmlUtils::CXmlLiteReader& oReader)
{
ReadAttributes( oReader );
if ( oReader.IsEmptyNode() )
return;
int nCurDepth = oReader.GetDepth();
while( oReader.ReadNextSiblingNode( nCurDepth ) )
{
std::wstring sName = XmlUtils::GetNameNoNS(oReader.GetName());
if ( _T("anchor") == sName )
{
m_oAnchor = oReader;
}
}
}
virtual EElementType getType () const
{
return et_OleObjectPr;
}
private:
void ReadAttributes(XmlUtils::CXmlLiteReader& oReader)
{
// Читаем атрибуты
WritingElement_ReadAttributes_Start( oReader )
WritingElement_ReadAttributes_Read_if ( oReader, _T("altText"), m_oAltText )
WritingElement_ReadAttributes_Read_else_if ( oReader, _T("autoFill"), m_oAutoFill )
WritingElement_ReadAttributes_Read_else_if ( oReader, _T("autoLine"), m_oAutoLine )
WritingElement_ReadAttributes_Read_else_if ( oReader, _T("autoPict"), m_oAutoPict )
WritingElement_ReadAttributes_Read_else_if ( oReader, _T("dde"), m_oDde )
WritingElement_ReadAttributes_Read_else_if ( oReader, _T("defaultSize"), m_oDefaultSize )
WritingElement_ReadAttributes_Read_else_if ( oReader, _T("disabled"), m_oDisabled )
WritingElement_ReadAttributes_Read_else_if ( oReader, _T("r:id"), m_oRid )
WritingElement_ReadAttributes_Read_else_if ( oReader, _T("locked"), m_oLocked )
WritingElement_ReadAttributes_Read_else_if ( oReader, _T("macro"), m_oMacro )
WritingElement_ReadAttributes_Read_else_if ( oReader, _T("print"), m_oPrint )
WritingElement_ReadAttributes_Read_else_if ( oReader, _T("uiObject"), m_oUiObject )
WritingElement_ReadAttributes_End( oReader )
}
public:
nullable<std::wstring > m_oAltText;
nullable<SimpleTypes::COnOff<> > m_oAutoFill;
nullable<SimpleTypes::COnOff<> > m_oAutoLine;
nullable<SimpleTypes::COnOff<> > m_oAutoPict;
nullable<SimpleTypes::COnOff<> > m_oDde;
nullable<SimpleTypes::COnOff<> > m_oDefaultSize;
nullable<SimpleTypes::COnOff<> > m_oDisabled;
nullable<SimpleTypes::CRelationshipId > m_oRid;
nullable<SimpleTypes::COnOff<> > m_oLocked;
nullable<std::wstring > m_oMacro;
nullable<SimpleTypes::COnOff<> > m_oPrint;
nullable<SimpleTypes::COnOff<> > m_oUiObject;
nullable<COleObjectAnchor > m_oAnchor;
};
class COleObject : public WritingElement
{
public:
......@@ -57,7 +240,22 @@ namespace OOX
}
virtual void toXML(NSStringUtils::CStringBuilder& writer) const
{
CString sRoot;
bool bAlternateContent = m_oObjectPr.IsInit();
if (bAlternateContent)
{
writer.WriteString(L"<mc:AlternateContent xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\"><mc:Choice Requires=\"x14\">");
toXML2(writer, true);
writer.WriteString(L"</mc:Choice><mc:Fallback>");
toXML2(writer, false);
writer.WriteString(L"</mc:Fallback></mc:AlternateContent>");
}
else
{
toXML2(writer, true);
}
}
virtual void toXML2(NSStringUtils::CStringBuilder& writer, bool ObjectPr) const
{
writer.WriteString(L"<oleObject");
WritingStringNullableAttrEncodeXmlString(L"progId", m_oProgId, m_oProgId.get());
WritingStringNullableAttrString(L"dvAspect", m_oDvAspect, m_oDvAspect->ToString());
......@@ -66,7 +264,16 @@ namespace OOX
WritingStringNullableAttrBool(L"autoLoad", m_oAutoLoad);
WritingStringNullableAttrInt(L"shapeId", m_oShapeId, m_oShapeId->GetValue());
WritingStringNullableAttrString(L"r:id", m_oRid, m_oRid->ToString2());
writer.WriteString(L"/>");
if (ObjectPr && m_oObjectPr.IsInit())
{
writer.WriteString(L">");
m_oObjectPr->toXML(writer);
writer.WriteString(L"</oleObject>");
}
else
{
writer.WriteString(L"/>");
}
}
void toXMLPptx(NSStringUtils::CStringBuilder& writer, CString qqq) const
{
......@@ -107,8 +314,16 @@ namespace OOX
if ( oReader.IsEmptyNode() )
return;
//todo objectPr
oReader.ReadTillEnd();
int nCurDepth = oReader.GetDepth();
while( oReader.ReadNextSiblingNode( nCurDepth ) )
{
std::wstring sName = XmlUtils::GetNameNoNS(oReader.GetName());
if ( _T("objectPr") == sName )
{
m_oObjectPr = oReader;
}
}
}
virtual EElementType getType () const
......@@ -143,6 +358,7 @@ namespace OOX
nullable<SimpleTypes::COnOff<> > m_oAutoLoad;
nullable<SimpleTypes::CUnsignedDecimalNumber<> > m_oShapeId;
nullable<SimpleTypes::CRelationshipId > m_oRid;
nullable<COleObjectPr > m_oObjectPr;
//internal
nullable<std::wstring > m_oFilepathBin;
nullable<std::wstring > m_oFilepathImg;
......@@ -214,6 +430,7 @@ namespace OOX
std::wstring sSubName = XmlUtils::GetNameNoNS(oReader.GetName());
if ( _T("Fallback") == sSubName || _T("Choice") == sSubName )
{
bool bFound = false;
int nSubSubDepth = oReader.GetDepth();
while( oReader.ReadNextSiblingNode( nSubSubDepth ) )
{
......@@ -224,6 +441,8 @@ namespace OOX
if(pOleObject->m_oShapeId.IsInit())
{
m_mapOleObjects[pOleObject->m_oShapeId->GetValue()] = pOleObject;
bFound = true;
break;
}
else
{
......@@ -231,6 +450,10 @@ namespace OOX
}
}
}
if (bFound)
{
break;
}
}
}
}
......
......@@ -336,7 +336,7 @@ namespace OOX
virtual void write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const
{
NSStringUtils::CStringBuilder sXml;
sXml.WriteString(_T("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" mc:Ignorable=\"x14ac\" xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\">"));
sXml.WriteString(_T("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:xdr=\"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing\" xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\" mc:Ignorable=\"x14ac\">"));
if(m_oSheetPr.IsInit())
m_oSheetPr->toXML(sXml);
if(m_oSheetViews.IsInit())
......
......@@ -377,6 +377,8 @@ namespace Spreadsheet
et_xdr_GraphicData,
et_OleObjects,
et_OleObject,
et_OleObjectPr,
et_OleObjectAnchor,
et_TableParts,
et_TablePart,
et_Table,
......
......@@ -2558,7 +2558,7 @@ namespace BinXlsxRW {
for(int i = 0, length = pDrawing->m_arrItems.size(); i < length ; ++i)
{
OOX::Spreadsheet::CCellAnchor& pCellAnchor = *pDrawing->m_arrItems[i];
//OleObject пишутся в новом drawing и старом legacyDrawing, мы используем legacyDrawing, поэтому пропускаем shape из drawing
//we use legacyDrawing or objectPr in OleObject so skip shape in drawing
bool bShapeOle = false;
if(oWorksheet.m_oOleObjects.IsInit() && pCellAnchor.m_oShape.IsInit() && pCellAnchor.m_oShape->m_oNvSpPr.IsInit() &&
pCellAnchor.m_oShape->m_oNvSpPr->m_oCNvPr.IsInit() && pCellAnchor.m_oShape->m_oNvSpPr->m_oCNvPr->m_oId.IsInit() )
......@@ -2579,12 +2579,63 @@ namespace BinXlsxRW {
}
}
//OleObjects
if(NULL != pVmlDrawing && oWorksheet.m_oOleObjects.IsInit())
if(oWorksheet.m_oOleObjects.IsInit())
{
for (std::map<int, COleObject*>::const_iterator it = oWorksheet.m_oOleObjects->m_mapOleObjects.begin(); it != oWorksheet.m_oOleObjects->m_mapOleObjects.end(); ++it)
{
OOX::Spreadsheet::COleObject* pOleObject = it->second;
if(pOleObject->m_oShapeId.IsInit())
if (pOleObject->m_oObjectPr.IsInit() && pOleObject->m_oObjectPr->m_oAnchor.IsInit() && pOleObject->m_oObjectPr->m_oRid.IsInit())
{
const OOX::Spreadsheet::COleObjectAnchor& oAnchor = pOleObject->m_oObjectPr->m_oAnchor.get();
if (oAnchor.m_oFrom.IsInit() && oAnchor.m_oTo.IsInit())
{
SimpleTypes::Spreadsheet::CCellAnchorType<> eAnchorType;
if(oAnchor.m_oMoveWithCells.IsInit() && oAnchor.m_oMoveWithCells->ToBool())
{
eAnchorType.SetValue(SimpleTypes::Spreadsheet::cellanchorOneCell);
}
else if(oAnchor.m_oSizeWithCells.IsInit() && oAnchor.m_oSizeWithCells->ToBool())
{
eAnchorType.SetValue(SimpleTypes::Spreadsheet::cellanchorTwoCell);
}
else
{
eAnchorType.SetValue(SimpleTypes::Spreadsheet::cellanchorAbsolute);
}
OOX::Spreadsheet::CCellAnchor oCellAnchor = OOX::Spreadsheet::CCellAnchor(eAnchorType);
oCellAnchor.m_oFrom = oAnchor.m_oFrom.get();
oCellAnchor.m_oTo = oAnchor.m_oTo.get();
oCellAnchor.m_oXml.Init();
oCellAnchor.m_oXml->append(L"<p:oleObj");
if (pOleObject->m_oRid.IsInit())
{
oCellAnchor.m_oXml->append(L" r:id=\"");
oCellAnchor.m_oXml->append(pOleObject->m_oRid->ToString2());
oCellAnchor.m_oXml->append(L"\"");
}
if (pOleObject->m_oProgId.IsInit())
{
oCellAnchor.m_oXml->append(L" progId=\"");
oCellAnchor.m_oXml->append(pOleObject->m_oProgId.get());
oCellAnchor.m_oXml->append(L"\"");
}
oCellAnchor.m_oXml->append(L"><p:embed/><p:pic><p:nvPicPr><p:cNvPicPr/><p:nvPr/></p:nvPicPr><p:blipFill><a:blip r:embed=\"");
oCellAnchor.m_oXml->append(pOleObject->m_oObjectPr->m_oRid->ToString2());
oCellAnchor.m_oXml->append(L"\"/><a:stretch><a:fillRect/></a:stretch></p:blipFill><p:spPr><a:prstGeom prst=\"rect\"><a:avLst/></a:prstGeom></p:spPr></p:pic></p:oleObj>");
CString keepRels = m_pOfficeDrawingConverter->GetRelsPath();
m_pOfficeDrawingConverter->SetRelsPath(oWorksheet.GetReadPath().GetPath());
nCurPos = m_oBcw.WriteItemStart(c_oSerWorksheetsTypes::Drawing);
WriteDrawing(oWorksheet, pDrawing, oCellAnchor, sDrawingRelsPath, pVmlDrawing, pOleObject);
m_oBcw.WriteItemEnd(nCurPos);
m_pOfficeDrawingConverter->SetRelsPath(keepRels);
}
}
else if (NULL != pVmlDrawing && pOleObject->m_oShapeId.IsInit())
{
CString sShapeId = _T("");
sShapeId.Format(_T("_x0000_s%04d"), pOleObject->m_oShapeId->GetValue());
......@@ -2647,10 +2698,8 @@ namespace BinXlsxRW {
}
}
}
}
}
}
}
};
......
......@@ -2588,7 +2588,8 @@ namespace BinXlsxRW {
res = Read1(length, &BinaryWorksheetsTableReader::ReadDrawing, this, &oTransport);
if(oTransport.m_nPos > 0 && oTransport.m_nLength > 0)
{
CString sOleXlsx;
std::wstring sOleXlsx;
std::wstring sOleDrawing;
if(NULL != m_pCurDrawing)
{
m_pOfficeDrawingConverter->SetDocumentChartsCount(m_pCurDrawing->GetGlobalNumberByType(OOX::Spreadsheet::FileTypes::Charts.OverrideType()));
......@@ -2605,14 +2606,14 @@ namespace BinXlsxRW {
m_pCurVmlDrawing->m_lObjectIdVML = m_pOfficeDrawingConverter->GetObjectIdVML();
sOleXlsx = m_pOfficeDrawingConverter->GetOleXlsx();
sOleDrawing = m_pOfficeDrawingConverter->GetOleDrawing();
}
if(S_OK == hRes && NULL != bstrXml)
{
if(!sOleXlsx.IsEmpty() && pCellAnchor->m_oFrom.IsInit() && pCellAnchor->m_oTo.IsInit())
if(!sOleXlsx.empty() && pCellAnchor->m_oFrom.IsInit() && pCellAnchor->m_oTo.IsInit())
{
XmlUtils::CXmlLiteReader oXmlReader;
oXmlReader.FromString(sOleXlsx.GetBuffer());
sOleXlsx.ReleaseBuffer();
oXmlReader.FromString(sOleXlsx);
oXmlReader.ReadNextNode();
OOX::Spreadsheet::COleObject* pOleObject = new OOX::Spreadsheet::COleObject(oXmlReader);
if(pOleObject->m_oShapeId.IsInit() && pOleObject->m_oFilepathBin.IsInit() && pOleObject->m_oFilepathImg.IsInit() && pOleObject->m_oRidImg.IsInit())
......@@ -2646,11 +2647,17 @@ namespace BinXlsxRW {
bstrXml->Insert(nIndex, oClientData.toXML());
m_pCurVmlDrawing->m_aXml.push_back(*bstrXml);
//add image rels
NSCommon::smart_ptr<OOX::File> pImageFile(new OOX::Spreadsheet::Image());
m_pCurVmlDrawing->Add(OOX::RId(pOleObject->m_oRidImg->GetValue()), pImageFile);
//add image rels to VmlDrawing
NSCommon::smart_ptr<OOX::File> pImageFileVml(new OOX::Spreadsheet::Image());
m_pCurVmlDrawing->Add(OOX::RId(pOleObject->m_oRidImg->GetValue()), pImageFileVml);
//меняем имя на полученное из pptx
pImageFile->m_sOutputFilename = pImageFile->DefaultDirectory().GetPath() + FILE_SEPARATOR_STR + OOX::CPath(pOleObject->m_oFilepathImg->c_str()).GetFilename();
pImageFileVml->m_sOutputFilename = OOX::CPath(pOleObject->m_oFilepathImg->c_str()).GetFilename();
//add image rels to Worksheet
NSCommon::smart_ptr<OOX::File> pImageFileWorksheet(new OOX::Spreadsheet::Image());
const OOX::RId oRIdImg = m_pCurWorksheet->Add(pImageFileWorksheet);
//меняем имя на полученное из pptx
pImageFileWorksheet->m_sOutputFilename = OOX::CPath(pOleObject->m_oFilepathImg->c_str()).GetFilename();
//add oleObject rels
if(!m_pCurWorksheet->m_oOleObjects.IsInit())
......@@ -2658,14 +2665,46 @@ namespace BinXlsxRW {
m_pCurWorksheet->m_oOleObjects.Init();
}
NSCommon::smart_ptr<OOX::File> pOleObjectFile(new OOX::OleObject(true));
const OOX::RId oRId = m_pCurWorksheet->Add(pOleObjectFile);
const OOX::RId oRIdBin = m_pCurWorksheet->Add(pOleObjectFile);
//меняем имя на полученное из pptx
pOleObjectFile->m_sOutputFilename = pOleObjectFile->DefaultDirectory().GetPath() + FILE_SEPARATOR_STR + OOX::CPath(pOleObject->m_oFilepathBin->c_str()).GetFilename();
pOleObjectFile->m_sOutputFilename = OOX::CPath(pOleObject->m_oFilepathBin->c_str()).GetFilename();
if(!pOleObject->m_oRid.IsInit())
{
pOleObject->m_oRid.Init();
}
pOleObject->m_oRid->SetValue(oRId.get());
pOleObject->m_oRid->SetValue(oRIdBin.get());
//ObjectPr
pOleObject->m_oObjectPr.Init();
pOleObject->m_oObjectPr->m_oDefaultSize.Init();
pOleObject->m_oObjectPr->m_oDefaultSize->FromBool(false);
pOleObject->m_oObjectPr->m_oRid.Init();
pOleObject->m_oObjectPr->m_oRid->SetValue(oRIdImg.get());
pOleObject->m_oObjectPr->m_oAnchor.Init();
SimpleTypes::Spreadsheet::ECellAnchorType eAnchorType = pCellAnchor->m_oAnchorType.GetValue();
if(SimpleTypes::Spreadsheet::cellanchorOneCell == eAnchorType)
{
pOleObject->m_oObjectPr->m_oAnchor->m_oMoveWithCells.Init();
pOleObject->m_oObjectPr->m_oAnchor->m_oMoveWithCells->FromBool(true);
}
else if(SimpleTypes::Spreadsheet::cellanchorTwoCell == eAnchorType)
{
pOleObject->m_oObjectPr->m_oAnchor->m_oSizeWithCells.Init();
pOleObject->m_oObjectPr->m_oAnchor->m_oSizeWithCells->FromBool(true);
}
pOleObject->m_oObjectPr->m_oAnchor->m_oFrom = pCellAnchor->m_oFrom;
pOleObject->m_oObjectPr->m_oAnchor->m_oTo = pCellAnchor->m_oTo;
//AlternateContent Drawing
if (!sOleDrawing.empty())
{
pCellAnchor->m_oXml.Init();
pCellAnchor->m_oXml->append(sOleDrawing);
pCellAnchor->m_oXml->append(_T("<xdr:clientData/>"));
pCellAnchor->m_oAlternateContent.Init();
pCellAnchor->m_oAlternateContent->FromBool(true);
pDrawing->m_arrItems.push_back(pCellAnchor);
}
m_pCurWorksheet->m_oOleObjects->m_mapOleObjects[pOleObject->m_oShapeId->GetValue()] = pOleObject;
}
......@@ -2674,7 +2713,7 @@ namespace BinXlsxRW {
delete pOleObject;
}
}
else if(sOleXlsx.IsEmpty())//если sOleXlsx не пустой, то в bstrXml старый shape
else if(sOleXlsx.empty())//если sOleXlsx не пустой, то в bstrXml старый shape
{
pCellAnchor->m_oXml.Init();
pCellAnchor->m_oXml->append(*bstrXml);
......
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