diff options
author | sushil_shinde <sushil.shinde@synerzip.com> | 2013-12-27 14:38:53 +0530 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2014-01-16 14:41:05 +0100 |
commit | b1e6269d1c0b312a2990324f0334527d2c04414a (patch) | |
tree | 51d9a5d86a0daf09e88138228906beb8e16a14a3 | |
parent | 5b8a16209f1e1d8fc43157463384f6ab407ac514 (diff) |
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
-rw-r--r-- | chart2/qa/extras/chart2export.cxx | 54 | ||||
-rw-r--r-- | chart2/qa/extras/data/docx/testMultipleChart.docx | bin | 0 -> 47534 bytes | |||
-rw-r--r-- | chart2/qa/extras/data/docx/testMultiplechartembeddings.docx | bin | 0 -> 47534 bytes | |||
-rw-r--r-- | include/oox/export/chartexport.hxx | 2 | ||||
-rw-r--r-- | oox/source/export/chartexport.cxx | 49 |
5 files changed, 105 insertions, 0 deletions
diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx index eee9161d8bbb..6cef73b26831 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 Binary files differnew file mode 100644 index 000000000000..28d8bbcfe143 --- /dev/null +++ b/chart2/qa/extras/data/docx/testMultipleChart.docx diff --git a/chart2/qa/extras/data/docx/testMultiplechartembeddings.docx b/chart2/qa/extras/data/docx/testMultiplechartembeddings.docx Binary files differnew file mode 100644 index 000000000000..28d8bbcfe143 --- /dev/null +++ b/chart2/qa/extras/data/docx/testMultiplechartembeddings.docx diff --git a/include/oox/export/chartexport.hxx b/include/oox/export/chartexport.hxx index a0f8d319468a..729e9ef28a21 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 03ec2abd4339..ede7ff989932 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 ); |