chart2/qa/extras/chart2export.cxx | 54 ++++++++++++ chart2/qa/extras/data/docx/testMultipleChart.docx |binary chart2/qa/extras/data/docx/testMultiplechartembeddings.docx |binary include/oox/export/chartexport.hxx | 2 oox/source/export/chartexport.cxx | 51 +++++++++++ 5 files changed, 107 insertions(+)
New commits: commit bcf116b7734d5111833189a4ce1cc1d3867fd492 Author: Markus Mohrhard <markus.mohrh...@googlemail.com> Date: Thu Jan 16 14:39:38 2014 +0100 fix element order in OOXML export Change-Id: Id6f9e1d142d8c8aedff76ff3d964bcf58c7f1815 diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx index ede7ff9..8bbf222 100644 --- a/oox/source/export/chartexport.cxx +++ b/oox/source/export/chartexport.cxx @@ -747,8 +747,6 @@ void ChartExport::exportChartSpace( Reference< ::com::sun::star::chart::XChartDo //XML_chart exportChart(rChartDoc); - exportExternalData(rChartDoc); - // TODO: printSettings // TODO: style // TODO: text properties @@ -756,6 +754,10 @@ void ChartExport::exportChartSpace( Reference< ::com::sun::star::chart::XChartDo Reference< XPropertySet > xPropSet( rChartDoc->getArea(), uno::UNO_QUERY ); if( xPropSet.is() ) exportShapeProps( xPropSet ); + + //XML_externalData + exportExternalData(rChartDoc); + pFS->endElement( FSNS( XML_c, XML_chartSpace ) ); } commit b1e6269d1c0b312a2990324f0334527d2c04414a Author: sushil_shinde <sushil.shi...@synerzip.com> Date: Fri Dec 27 14:38:53 2013 +0530 fdo#72520 : Exporting sheet external data for chart for docx files. - Adding external data path relationship for chart[n].xml for docx files. - Added Unit Test. Change-Id: If48ed21237433ddf6659454dda95d720aabdb300 diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx index eee9161..6cef73b 100644 --- a/chart2/qa/extras/chart2export.cxx +++ b/chart2/qa/extras/chart2export.cxx @@ -13,6 +13,7 @@ #include <com/sun/star/chart2/XRegressionCurveContainer.hpp> #include <com/sun/star/lang/XServiceName.hpp> #include <com/sun/star/packages/zip/ZipFileAccess.hpp> +#include <com/sun/star/text/XTextDocument.hpp> #include <unotools/ucbstreamhelper.hxx> #include <rtl/strbuf.hxx> @@ -36,6 +37,8 @@ public: void testBarChart(); void testCrosses(); void testChartDataTable(); + void testChartExternalData(); + void testEmbeddingsGrabBag(); CPPUNIT_TEST_SUITE(Chart2ExportTest); CPPUNIT_TEST(test); @@ -45,6 +48,8 @@ public: CPPUNIT_TEST(testBarChart); CPPUNIT_TEST(testCrosses); CPPUNIT_TEST(testChartDataTable); + CPPUNIT_TEST(testChartExternalData); + CPPUNIT_TEST(testEmbeddingsGrabBag); CPPUNIT_TEST_SUITE_END(); protected: @@ -446,6 +451,55 @@ void Chart2ExportTest::testChartDataTable() assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:dTable/c:showOutline", "val", "1"); } +void Chart2ExportTest::testChartExternalData() +{ + load("/chart2/qa/extras/data/docx/", "testMultipleChart.docx"); + + xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text"); + CPPUNIT_ASSERT(pXmlDoc); + xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, "/c:chartSpace/c:externalData"); + CPPUNIT_ASSERT(pXmlNodes); +} + +void Chart2ExportTest::testEmbeddingsGrabBag() +{ + // The problem was that .xlsx files were missing from docx file from embeddings folder + // after saving file. + // This test case tests whether embeddings files grabbagged properly in correct object. + + load("/chart2/qa/extras/data/docx/", "testMultiplechartembeddings.docx" ); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xTextDocumentPropertySet(xTextDocument, uno::UNO_QUERY); + uno::Sequence<beans::PropertyValue> aGrabBag(0); + xTextDocumentPropertySet->getPropertyValue(OUString("InteropGrabBag")) >>= aGrabBag; + CPPUNIT_ASSERT(aGrabBag.hasElements()); // Grab Bag not empty + bool bEmbeddings = sal_False; + const char* testEmbeddedFileNames[3] = {"word/embeddings/Microsoft_Excel_Worksheet3.xlsx", + "word/embeddings/Microsoft_Excel_Worksheet2.xlsx", + "word/embeddings/Microsoft_Excel_Worksheet1.xlsx"}; + for(int i = 0; i < aGrabBag.getLength(); ++i) + { + if (aGrabBag[i].Name == "OOXEmbeddings") + { + bEmbeddings = sal_True; + uno::Sequence<beans::PropertyValue> aEmbeddingsList(0); + uno::Reference<io::XInputStream> aEmbeddingXlsxStream; + OUString aEmbeddedfileName; + CPPUNIT_ASSERT(aGrabBag[i].Value >>= aEmbeddingsList); // PropertyValue of proper type + sal_Int32 length = aEmbeddingsList.getLength(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), length); + for(int j = 0; j < length; ++j) + { + aEmbeddingsList[j].Value >>= aEmbeddingXlsxStream; + aEmbeddedfileName = aEmbeddingsList[j].Name; + CPPUNIT_ASSERT(aEmbeddingXlsxStream.get()); // Reference not empty + CPPUNIT_ASSERT_EQUAL(OUString::createFromAscii(testEmbeddedFileNames[j]),aEmbeddedfileName); + } + } + } + CPPUNIT_ASSERT(bEmbeddings); // Grab Bag has all the expected elements +} + CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ExportTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/chart2/qa/extras/data/docx/testMultipleChart.docx b/chart2/qa/extras/data/docx/testMultipleChart.docx new file mode 100644 index 0000000..28d8bbc Binary files /dev/null and b/chart2/qa/extras/data/docx/testMultipleChart.docx differ diff --git a/chart2/qa/extras/data/docx/testMultiplechartembeddings.docx b/chart2/qa/extras/data/docx/testMultiplechartembeddings.docx new file mode 100644 index 0000000..28d8bbc Binary files /dev/null and b/chart2/qa/extras/data/docx/testMultiplechartembeddings.docx differ diff --git a/include/oox/export/chartexport.hxx b/include/oox/export/chartexport.hxx index a0f8d31..729e9ef 100644 --- a/include/oox/export/chartexport.hxx +++ b/include/oox/export/chartexport.hxx @@ -113,6 +113,8 @@ private: sal_Bool bIncludeTable ); void exportChart( com::sun::star::uno::Reference< com::sun::star::chart::XChartDocument > rChartDoc ); + void exportExternalData( com::sun::star::uno::Reference< + com::sun::star::chart::XChartDocument > rChartDoc ); void exportLegend( com::sun::star::uno::Reference< com::sun::star::chart::XChartDocument > rChartDoc ); void exportTitle( com::sun::star::uno::Reference< diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx index 03ec2ab..ede7ff9 100644 --- a/oox/source/export/chartexport.cxx +++ b/oox/source/export/chartexport.cxx @@ -747,6 +747,8 @@ void ChartExport::exportChartSpace( Reference< ::com::sun::star::chart::XChartDo //XML_chart exportChart(rChartDoc); + exportExternalData(rChartDoc); + // TODO: printSettings // TODO: style // TODO: text properties @@ -757,6 +759,53 @@ void ChartExport::exportChartSpace( Reference< ::com::sun::star::chart::XChartDo pFS->endElement( FSNS( XML_c, XML_chartSpace ) ); } +void ChartExport::exportExternalData( Reference< ::com::sun::star::chart::XChartDocument > rChartDoc ) +{ + // Embedded external data is grab bagged for docx file hence adding export part of + // external data for docx files only. + if(GetDocumentType() != DOCUMENT_DOCX) + return; + + OUString externalDataPath; + Reference< beans::XPropertySet > xDocPropSet( rChartDoc->getDiagram(), uno::UNO_QUERY ); + if( xDocPropSet.is()) + { + try + { + Any aAny( xDocPropSet->getPropertyValue( + OUString( "ExternalData" ))); + aAny >>= externalDataPath; + } + catch( beans::UnknownPropertyException & ) + { + DBG_WARNING( "Required property not found in ChartDocument" ); + } + } + if(!externalDataPath.isEmpty()) + { + // Here adding external data entry to relationship. + OUString relationPath = externalDataPath; + // Converting absolute path to relative path. + if( externalDataPath[ 0 ] != '.' && externalDataPath[ 1 ] != '.') + { + sal_Int32 nStartPos = 0; + sal_Int32 nSepPos = externalDataPath.indexOf( '/', nStartPos ); + if( nSepPos > 0) + { + relationPath = relationPath.copy( nSepPos, ::std::max< sal_Int32 >( externalDataPath.getLength(), 0 ) - nSepPos ); + relationPath = OUStringBuffer( ".." ).append( relationPath ).makeStringAndClear(); + } + } + FSHelperPtr pFS = GetFS(); + OUString sRelId = GetFB()->addRelation(pFS->getOutputStream(), + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package", + relationPath); + pFS->singleElementNS( XML_c, XML_externalData, + FSNS(XML_r, XML_id), OUStringToOString(sRelId, RTL_TEXTENCODING_UTF8), + FSEND); + } +} + void ChartExport::exportChart( Reference< ::com::sun::star::chart::XChartDocument > rChartDoc ) { Reference< chart2::XChartDocument > xNewDoc( rChartDoc, uno::UNO_QUERY ); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits