diff options
-rw-r--r-- | include/oox/ole/vbaexport.hxx | 10 | ||||
-rw-r--r-- | oox/source/ole/vbaexport.cxx | 41 | ||||
-rw-r--r-- | sc/source/filter/excel/xestream.cxx | 3 |
3 files changed, 46 insertions, 8 deletions
diff --git a/include/oox/ole/vbaexport.hxx b/include/oox/ole/vbaexport.hxx index 3217e1b8b9b1..8c3094b6312b 100644 --- a/include/oox/ole/vbaexport.hxx +++ b/include/oox/ole/vbaexport.hxx @@ -19,6 +19,7 @@ namespace com { namespace sun { namespace star { namespace container { class XNameContainer; } namespace frame { class XModel; } + namespace script { class XLibraryContainer; } } } } class OOX_DLLPUBLIC VbaExport @@ -28,14 +29,19 @@ public: void exportVBA(); + bool containsVBAProject(); + private: css::uno::Reference<css::container::XNameContainer> getBasicLibrary(); - css::uno::Reference<css::frame::XModel> mxModel; + css::uno::Reference<css::script::XLibraryContainer> + getLibraryContainer(); - OUString maProjectName; + OUString getProjectName(); + + css::uno::Reference<css::frame::XModel> mxModel; }; class VBACompressionChunk diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx index dbcc2560c48c..feecd37d95b7 100644 --- a/oox/source/ole/vbaexport.cxx +++ b/oox/source/ole/vbaexport.cxx @@ -13,6 +13,7 @@ #include <com/sun/star/script/XLibraryContainer.hpp> #include <com/sun/star/script/vba/XVBAModuleInfo.hpp> +#include <com/sun/star/script/vba/XVBACompatibility.hpp> #include <com/sun/star/frame/XModel.hpp> #include <oox/helper/binaryoutputstream.hxx> @@ -313,8 +314,6 @@ void VBACompression::write() VbaExport::VbaExport(css::uno::Reference<css::frame::XModel> xModel): mxModel(xModel) { - // TODO: how do we get the correct project name - maProjectName = "VBAProject"; } namespace { @@ -642,20 +641,28 @@ void VbaExport::exportVBA() aStorage->Commit(); } +css::uno::Reference<css::script::XLibraryContainer> VbaExport::getLibraryContainer() +{ + oox::PropertySet aDocProp(mxModel); + css::uno::Reference<css::script::XLibraryContainer> xLibContainer(aDocProp.getAnyProperty(oox::PROP_BasicLibraries), css::uno::UNO_QUERY); + + return xLibContainer; +} + css::uno::Reference<css::container::XNameContainer> VbaExport::getBasicLibrary() { css::uno::Reference<css::container::XNameContainer> xLibrary; try { - oox::PropertySet aDocProp(mxModel); - css::uno::Reference<css::script::XLibraryContainer> xLibContainer(aDocProp.getAnyProperty(oox::PROP_BasicLibraries), css::uno::UNO_QUERY_THROW); + css::uno::Reference<css::script::XLibraryContainer> xLibContainer = getLibraryContainer(); css::uno::Sequence<OUString> aElementNames = xLibContainer->getElementNames(); sal_Int32 n = aElementNames.getLength(); for (sal_Int32 i = 0; i < n; ++i) { SAL_DEBUG(aElementNames[i]); } - xLibrary.set( xLibContainer->getByName(maProjectName), css::uno::UNO_QUERY_THROW ); + OUString aProjectName = getProjectName(); + xLibrary.set( xLibContainer->getByName(aProjectName), css::uno::UNO_QUERY_THROW ); } catch(...) { @@ -664,4 +671,28 @@ css::uno::Reference<css::container::XNameContainer> VbaExport::getBasicLibrary() return xLibrary; } +bool VbaExport::containsVBAProject() +{ + css::uno::Reference<css::script::XLibraryContainer> xLibContainer = getLibraryContainer(); + if (!xLibContainer.is()) + return false; + + css::uno::Reference<css::script::vba::XVBACompatibility> xVbaCompatibility (xLibContainer, css::uno::UNO_QUERY); + if (!xVbaCompatibility.is()) + return false; + + bool bVBACompatibilty = xVbaCompatibility->getVBACompatibilityMode(); + + return bVBACompatibilty; +} + +OUString VbaExport::getProjectName() +{ + css::uno::Reference<css::script::vba::XVBACompatibility> xVbaCompatibility(getLibraryContainer(), css::uno::UNO_QUERY); + if (xVbaCompatibility.is()) + return xVbaCompatibility->getProjectName(); + + return OUString(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/excel/xestream.cxx b/sc/source/filter/excel/xestream.cxx index fec468223977..490f9d47811f 100644 --- a/sc/source/filter/excel/xestream.cxx +++ b/sc/source/filter/excel/xestream.cxx @@ -1093,7 +1093,8 @@ bool XclExpXmlStream::exportDocument() "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" ) ); VbaExport aExport(getModel()); - aExport.exportVBA(); + if (aExport.containsVBAProject()) + aExport.exportVBA(); // destruct at the end of the block { |