[Libreoffice-commits] core.git: Branch 'feature/vba-export' - 7 commits - basctl/inc basctl/source include/oox include/svtools officecfg/registry oox/source sc/source sfx2/source uui/source

Markus Mohrhard markus.mohrhard at googlemail.com
Mon Aug 24 15:17:07 PDT 2015


 basctl/inc/basidesh.hrc                                  |    1 
 basctl/source/basicide/basidesh.cxx                      |    6 
 basctl/source/basicide/basidesh.src                      |    4 
 include/oox/ole/vbaexport.hxx                            |   14 +-
 include/svtools/sfxecode.hxx                             |    1 
 officecfg/registry/schema/org/openoffice/Office/Calc.xcs |    8 +
 oox/source/ole/vbaexport.cxx                             |   95 +++++++++------
 sc/source/filter/excel/expop2.cxx                        |   38 +++++-
 sc/source/filter/excel/xestream.cxx                      |    8 +
 sfx2/source/doc/guisaveas.cxx                            |   35 -----
 uui/source/iahndl.cxx                                    |   25 ---
 uui/source/ids.hrc                                       |    1 
 uui/source/ids.src                                       |    5 
 13 files changed, 126 insertions(+), 115 deletions(-)

New commits:
commit 9d8670a740710fa8856b26e76c10569fc0265439
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Tue Aug 25 00:14:02 2015 +0200

    handle different callers for vba export code
    
    This now integrates it correctly with the XLS code, the XLSX one
    requires a bit more work to copy the stream to the OOXML file.
    
    Change-Id: Ic853ce795fc2ac2941083a76fd0a8cad7c6add09

diff --git a/include/oox/ole/vbaexport.hxx b/include/oox/ole/vbaexport.hxx
index 8c3094b..69d34b1 100644
--- a/include/oox/ole/vbaexport.hxx
+++ b/include/oox/ole/vbaexport.hxx
@@ -16,6 +16,8 @@
 
 #include <oox/dllapi.h>
 
+class SotStorage;
+
 namespace com { namespace sun { namespace star {
     namespace container { class XNameContainer; }
     namespace frame { class XModel; }
@@ -27,7 +29,7 @@ class OOX_DLLPUBLIC VbaExport
 public:
     VbaExport(css::uno::Reference<css::frame::XModel> xModel);
 
-    void exportVBA();
+    void exportVBA(SotStorage* pRootStorage);
 
     bool containsVBAProject();
 
diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index b4d1d6d..fb77a50 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -611,15 +611,10 @@ void exportDirStream(SvStream& rStrm)
 
 }
 
-void VbaExport::exportVBA()
+void VbaExport::exportVBA(SotStorage* pRootStorage)
 {
     // start here with the VBA export
-
-    const OUString aVbaStreamLocation("/tmp/vba_out.bin");
-    SvFileStream aVbaStream(aVbaStreamLocation, STREAM_READWRITE);
-
-    tools::SvRef<SotStorage> aStorage(new SotStorage(aVbaStream));
-    SotStorage* pVBAStream = aStorage->OpenSotStorage("VBA", STREAM_READWRITE);
+    SotStorage* pVBAStream = pRootStorage->OpenSotStorage("VBA", STREAM_READWRITE);
     SotStorageStream* pDirStream = pVBAStream->OpenSotStream("dir", STREAM_READWRITE);
 
     // export
@@ -638,7 +633,7 @@ void VbaExport::exportVBA()
     }
     pDirStream->Commit();
     pVBAStream->Commit();
-    aStorage->Commit();
+    pRootStorage->Commit();
 }
 
 css::uno::Reference<css::script::XLibraryContainer> VbaExport::getLibraryContainer()
diff --git a/sc/source/filter/excel/expop2.cxx b/sc/source/filter/excel/expop2.cxx
index 6833576..68898e9 100644
--- a/sc/source/filter/excel/expop2.cxx
+++ b/sc/source/filter/excel/expop2.cxx
@@ -97,7 +97,10 @@ FltError ExportBiff5::Write()
     {
         VbaExport aExport(pDocShell->GetModel());
         if (aExport.containsVBAProject())
-            aExport.exportVBA();
+        {
+            SotStorage* pVBARoot = xRootStrg->OpenSotStorage("_VBA_PROJECT_CUR");
+            aExport.exportVBA(pVBARoot);
+        }
     }
     else if( pDocShell && xRootStrg.Is() && eVbaExportMode == VBAExportMode::REEXPORT_STREAM )
     {
diff --git a/sc/source/filter/excel/xestream.cxx b/sc/source/filter/excel/xestream.cxx
index b307ede..363339f 100644
--- a/sc/source/filter/excel/xestream.cxx
+++ b/sc/source/filter/excel/xestream.cxx
@@ -1094,7 +1094,12 @@ bool XclExpXmlStream::exportDocument()
 
     VbaExport aExport(getModel());
     if (aExport.containsVBAProject())
-        aExport.exportVBA();
+    {
+        const OUString aVbaStreamLocation("/tmp/vba_out.bin");
+        SvFileStream aVbaStream(aVbaStreamLocation, STREAM_READWRITE);
+        tools::SvRef<SotStorage> pVBAStorage(new SotStorage(aVbaStream));
+        aExport.exportVBA(pVBAStorage);
+    }
 
     // destruct at the end of the block
     {
commit b96ddefef144ad5679b052e80930680a1ccd2cfe
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Mon Aug 24 23:56:54 2015 +0200

    introduce mode to save vba stream also to xls files
    
    Change-Id: Ic1066fa9492090e42d37ec487c2e9e8234de4375

diff --git a/officecfg/registry/schema/org/openoffice/Office/Calc.xcs b/officecfg/registry/schema/org/openoffice/Office/Calc.xcs
index bb74d74..35bc578 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Calc.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Calc.xcs
@@ -1629,6 +1629,14 @@
           <info>
             <desc>Specifies how VBA macros are treated in Excel files.</desc>
           </info>
+          <prop oor:name="UseExport" oor:type="xs:boolean" oor:nillable="false">
+            <!-- UIHints: Tools  Options - Filter Settings  Microsoft Office  [Section] Microsoft Excel 97/2000 -->
+            <info>
+              <desc>Indicates whether VBA macros are exported through the vba export code.</desc>
+              <label>Export VBA</label>
+            </info>
+            <value>true</value>
+          </prop>
           <prop oor:name="Load" oor:type="xs:boolean" oor:nillable="false">
             <!-- OldPath: Filter/MS_Office/Basic/Excel -->
             <!-- OldLocation: soffice.cfg -->
diff --git a/sc/source/filter/excel/expop2.cxx b/sc/source/filter/excel/expop2.cxx
index f9726f6..6833576 100644
--- a/sc/source/filter/excel/expop2.cxx
+++ b/sc/source/filter/excel/expop2.cxx
@@ -23,6 +23,8 @@
 #include <sfx2/docinf.hxx>
 #include <filter/msfilter/svxmsbas.hxx>
 
+#include <oox/ole/vbaexport.hxx>
+
 #include "scerrors.hxx"
 #include "scextopt.hxx"
 
@@ -38,9 +40,22 @@
 #include "xltools.hxx"
 #include "xelink.hxx"
 
+#include <officecfg/Office/Calc.hxx>
+
 #include <com/sun/star/document/XDocumentProperties.hpp>
 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
 
+namespace {
+
+enum class VBAExportMode
+{
+    NONE,
+    REEXPORT_STREAM,
+    FULL_EXPORT
+};
+
+}
+
 ExportBiff5::ExportBiff5( XclExpRootData& rExpData, SvStream& rStrm ):
     ExportTyp( rStrm, &rExpData.mrDoc, rExpData.meTextEnc ),
     XclExpRoot( rExpData )
@@ -65,14 +80,26 @@ FltError ExportBiff5::Write()
     tools::SvRef<SotStorage> xRootStrg = GetRootStorage();
     OSL_ENSURE( xRootStrg.Is(), "ExportBiff5::Write - no root storage" );
 
-    bool bWriteBasicStrg = false;
+    VBAExportMode eVbaExportMode = VBAExportMode::NONE;
     if( GetBiff() == EXC_BIFF8 )
     {
-        const SvtFilterOptions& rFilterOpt = SvtFilterOptions::Get();
-        bWriteBasicStrg = rFilterOpt.IsLoadExcelBasicStorage();
+        if (officecfg::Office::Calc::Filter::Import::VBA::UseExport::get())
+            eVbaExportMode = VBAExportMode::FULL_EXPORT;
+        else
+        {
+            const SvtFilterOptions& rFilterOpt = SvtFilterOptions::Get();
+            if (rFilterOpt.IsLoadExcelBasicStorage())
+                eVbaExportMode = VBAExportMode::REEXPORT_STREAM;
+        }
     }
 
-    if( pDocShell && xRootStrg.Is() && bWriteBasicStrg )
+    if ( pDocShell && xRootStrg.Is() && eVbaExportMode == VBAExportMode::FULL_EXPORT)
+    {
+        VbaExport aExport(pDocShell->GetModel());
+        if (aExport.containsVBAProject())
+            aExport.exportVBA();
+    }
+    else if( pDocShell && xRootStrg.Is() && eVbaExportMode == VBAExportMode::REEXPORT_STREAM )
     {
         SvxImportMSVBasic aBasicImport( *pDocShell, *xRootStrg );
         sal_uLong nErr = aBasicImport.SaveOrDelMSVBAStorage( true, EXC_STORAGE_VBA_PROJECT );
commit 36be0d31b5df39fc5444277c7acadcbeaa839d3b
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Mon Aug 24 23:48:45 2015 +0200

    remove more warnings about vba export
    
    Change-Id: I8d0e6f69dd4d51d195422e6e934fedc406caec16

diff --git a/include/svtools/sfxecode.hxx b/include/svtools/sfxecode.hxx
index 5246f5a..4968f0e 100644
--- a/include/svtools/sfxecode.hxx
+++ b/include/svtools/sfxecode.hxx
@@ -77,7 +77,6 @@
 #define ERRCODE_SFX_INCOMPLETE_ENCRYPTION    (ERRCODE_WARNING_MASK | ERRCODE_AREA_SFX | ERRCODE_CLASS_NONE | 55)
 #define ERRCODE_SFX_DOCUMENT_MACRO_DISABLED_MAC (ERRCODE_WARNING_MASK | ERRCODE_AREA_SFX | ERRCODE_CLASS_NONE | 56)
 #define ERRCODE_SFX_FORMAT_ROWCOL           (ERRCODE_AREA_SFX | ERRCODE_CLASS_NONE | 57)
-#define ERRCODE_SFX_VBASIC_CANTSAVE_STORAGE (ERRCODE_WARNING_MASK | ERRCODE_AREA_SFX | ERRCODE_CLASS_NONE | 58)
 
 
 //Dies und das
diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx
index 306202f..2de33c4 100644
--- a/sfx2/source/doc/guisaveas.cxx
+++ b/sfx2/source/doc/guisaveas.cxx
@@ -803,41 +803,6 @@ sal_Int8 ModelData_Impl::CheckFilter( const OUString& aFilterName )
 
         if ( !aPreusedFilterName.equals( aFilterName ) && !aUIName.equals( aDefUIName ) )
         {
-            // is it possible to get these names from somewhere and not just
-            // hardcode them?
-            OUString sXLSXFilter("Calc MS Excel 2007 XML");
-            OUString sOtherXLSXFilter("Calc Office Open XML");
-            bool bHasMacros = hasMacros( GetModel() );
-            if ( bHasMacros && (  aFilterName == sXLSXFilter  ||  aFilterName == sOtherXLSXFilter ) )
-            {
-                uno::Reference< task::XInteractionHandler > xHandler;
-                GetMediaDescr()[ OUString( "InteractionHandler" ) ] >>= xHandler;
-                if ( xHandler.is() )
-                {
-                    bool bResult = false;
-                    try
-                    {
-                        task::ErrorCodeRequest aErrorCode;
-                        aErrorCode.ErrCode = ERRCODE_SFX_VBASIC_CANTSAVE_STORAGE;
-
-                        uno::Any aRequest = uno::makeAny( aErrorCode );
-                        uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations( 2 );
-
-                        ::rtl::Reference< ::comphelper::OInteractionApprove > pApprove( new ::comphelper::OInteractionApprove );
-                        aContinuations[ 0 ] = pApprove.get();
-
-                        ::rtl::Reference< ::comphelper::OInteractionAbort > pAbort( new ::comphelper::OInteractionAbort );
-                        aContinuations[ 1 ] = pAbort.get();
-                        xHandler->handle(::framework::InteractionRequest::CreateRequest (aRequest,aContinuations));
-                        bResult = pApprove->wasSelected();
-                    }
-                    catch( const uno::Exception& )
-                    {
-                    }
-                    if ( !bResult )
-                        return STATUS_SAVEAS;
-                }
-            }
             if ( !SfxStoringHelper::WarnUnacceptableFormat( GetModel(), aUIName, aDefUIName, aDefExtension,
                                                             true, (bool)( nDefFiltFlags & SfxFilterFlags::ALIEN ) ) )
                 return STATUS_SAVEAS_STANDARDNAME;
diff --git a/uui/source/iahndl.cxx b/uui/source/iahndl.cxx
index d16935b..4c98ee6 100644
--- a/uui/source/iahndl.cxx
+++ b/uui/source/iahndl.cxx
@@ -747,26 +747,11 @@ UUIInteractionHelper::handleRequest_impl(
         task::ErrorCodeRequest aErrorCodeRequest;
         if (aAnyRequest >>= aErrorCodeRequest)
         {
-            // Sucky special handling for xlsx macro filter warning
-            if ( (sal_uInt32)ERRCODE_SFX_VBASIC_CANTSAVE_STORAGE == (sal_uInt32)aErrorCodeRequest.ErrCode)
-            {
-                std::vector< OUString > aArguments;
-                handleErrorHandlerRequest( task::InteractionClassification_WARNING,
-                                       ERRCODE_UUI_IO_WARN_CANTSAVE_MACROS,
-                                       aArguments,
-                                       rRequest->getContinuations(),
-                                       bObtainErrorStringOnly,
-                                       bHasErrorString,
-                                       rErrorString);
-            }
-            else
-            {
-                handleGenericErrorRequest( aErrorCodeRequest.ErrCode,
-                                       rRequest->getContinuations(),
-                                       bObtainErrorStringOnly,
-                                       bHasErrorString,
-                                       rErrorString);
-            }
+            handleGenericErrorRequest( aErrorCodeRequest.ErrCode,
+                    rRequest->getContinuations(),
+                    bObtainErrorStringOnly,
+                    bHasErrorString,
+                    rErrorString);
             return true;
         }
 
diff --git a/uui/source/ids.hrc b/uui/source/ids.hrc
index 9ff94d8..e70c7a8 100644
--- a/uui/source/ids.hrc
+++ b/uui/source/ids.hrc
@@ -133,7 +133,6 @@
 #define ERRCODE_UUI_LOCKING_NOT_LOCKED                          (ERRCODE_AREA_UUI + 61)
 #define ERRCODE_UUI_LOCKING_LOCK_EXPIRED                        (ERRCODE_AREA_UUI + 62)
 #define ERRCODE_UUI_CANNOT_ACTIVATE_FACTORY                     (ERRCODE_AREA_UUI + 63)
-#define ERRCODE_UUI_IO_WARN_CANTSAVE_MACROS                     (ERRCODE_WARNING_MASK | ( ERRCODE_AREA_UUI + 64))
 #define ERRCODE_AREA_UUI_UNKNOWNAUTH    25000
 #define SSLWARN_TYPE_DOMAINMISMATCH     10
 #define SSLWARN_TYPE_EXPIRED            20
diff --git a/uui/source/ids.src b/uui/source/ids.src
index 13e2bab..d7ae643 100644
--- a/uui/source/ids.src
+++ b/uui/source/ids.src
@@ -397,11 +397,6 @@ Resource RID_UUI_ERRHDL
         Text [ en-US ] = "Component cannot be loaded, possibly broken or incomplete installation.\nFull error message:\n\n $(ARG1).";
     };
 
-    String (ERRCODE_UUI_IO_WARN_CANTSAVE_MACROS & ERRCODE_RES_MASK)
-    {
-        Text [ en-US ] = "You are saving to a macro-free document format, the macros contained in this document will not be saved.\nDo you wish to continue?";
-    };
-
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit f056dc1e744b0246e20fbda2989ddb3602095180
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Mon Aug 24 12:52:55 2015 +0200

    no need to warn anymore as we can save VBA now
    
    Well we will be able when this feature hits master.
    
    Change-Id: I5547863e9002bfe16119a26059fa5281bd9e9070

diff --git a/basctl/inc/basidesh.hrc b/basctl/inc/basidesh.hrc
index 3403c79..df9f997 100644
--- a/basctl/inc/basidesh.hrc
+++ b/basctl/inc/basidesh.hrc
@@ -61,7 +61,6 @@
 #define RID_STR_OPEN                    ( RID_BASICIDE_START + 20 )
 #define RID_STR_SAVE                    ( RID_BASICIDE_START + 21 )
 #define RID_STR_RUNTIMEERROR            ( RID_BASICIDE_START + 22 )
-#define RID_STR_CANNOTSAVEVBA           ( RID_BASICIDE_START + 23 )
 #define RID_STR_STDDIALOGNAME           ( RID_BASICIDE_START + 24 )
 
 #define RID_STR_STDMODULENAME           ( RID_BASICIDE_START + 27 )
diff --git a/basctl/source/basicide/basidesh.cxx b/basctl/source/basicide/basidesh.cxx
index 79e352e..11374b7 100644
--- a/basctl/source/basicide/basidesh.cxx
+++ b/basctl/source/basicide/basidesh.cxx
@@ -257,14 +257,8 @@ Shell::~Shell()
 void Shell::onDocumentCreated( const ScriptDocument& /*_rDocument*/ )
 {
     if (pCurWin)
-    {
         pCurWin->OnNewDocument();
 
-        // for VBA documents, show a warning that we can save them only in ODF
-        if (pCurWin->GetDocument().isInVBAMode())
-            GetViewFrame()->AppendInfoBar("vba_save", IDE_RESSTR(RID_STR_CANNOTSAVEVBA));
-    }
-
     UpdateWindows();
 }
 
diff --git a/basctl/source/basicide/basidesh.src b/basctl/source/basicide/basidesh.src
index 3b2d243..65c7066 100644
--- a/basctl/source/basicide/basidesh.src
+++ b/basctl/source/basicide/basidesh.src
@@ -211,10 +211,6 @@ String RID_STR_CANNOTCLOSE
 {
     Text [ en-US ] = "The window cannot be closed while BASIC is running." ;
 };
-String RID_STR_CANNOTSAVEVBA
-{
-    Text [ en-US ] = "You are editing a VBA macro. Changes can be saved only in OpenDocument Format." ;
-};
 String RID_STR_REPLACESTDLIB
 {
     Text [ en-US ] = "The default library cannot be replaced." ;
commit 364f0c5b0eefd231ff5ac5361d21485db274ca47
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Mon Aug 24 12:50:54 2015 +0200

    we don't need that code anymore
    
    Change-Id: I77b5816a4e7743494444b0ac2366164a3bc5d13d

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index cd5a5b7..b4d1d6d 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -655,12 +655,6 @@ css::uno::Reference<css::container::XNameContainer> VbaExport::getBasicLibrary()
     try
     {
         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]);
-        }
         OUString aProjectName = getProjectName();
         xLibrary.set( xLibContainer->getByName(aProjectName), css::uno::UNO_QUERY_THROW );
     }
commit 1c57558ccd36dd91363981808804bd1d0855dca0
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Mon Aug 24 12:46:00 2015 +0200

    get correct vba project name
    
    Change-Id: I48efd62ca1df00b8a0cbecb01b394814ca40c2e9

diff --git a/include/oox/ole/vbaexport.hxx b/include/oox/ole/vbaexport.hxx
index 3217e1b..8c3094b 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 dbcc256..cd5a5b7 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_THROW);
+
+    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,25 @@ css::uno::Reference<css::container::XNameContainer> VbaExport::getBasicLibrary()
     return xLibrary;
 }
 
+bool VbaExport::containsVBAProject()
+{
+    css::uno::Reference<css::script::XLibraryContainer> xLibContainer = getLibraryContainer();
+    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 2c4f0d7..b307ede 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
     {
commit 762c6269d86eed8927863d703926776058616bc6
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sun Aug 23 19:37:48 2015 +0200

    small refactoring in the vba export code
    
    Change-Id: I68a7c7700b8405f4fe2b75516deff684f21e256c

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index 619c820..dbcc256 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -30,6 +30,8 @@
 #define CODEPAGE RTL_TEXTENCODING_MS_1252
 #endif
 
+#define VBA_EXPORT_DEBUG 1
+
 namespace {
 
 void exportString(SvStream& rStrm, const OUString& rString)
@@ -582,11 +584,30 @@ void writePROJECTMODULES(SvStream& rStrm)
 // section 2.3.4.2
 void exportDirStream(SvStream& rStrm)
 {
-    writePROJECTINFORMATION(rStrm);
-    writePROJECTREFERENCES(rStrm);
-    writePROJECTMODULES(rStrm);
-    rStrm.WriteUInt16(0x0010); // terminator
-    rStrm.WriteUInt32(0x00000000); // reserved
+    SvMemoryStream aDirStream(4096, 4096);
+
+    writePROJECTINFORMATION(aDirStream);
+    writePROJECTREFERENCES(aDirStream);
+    writePROJECTMODULES(aDirStream);
+    aDirStream.WriteUInt16(0x0010); // terminator
+    aDirStream.WriteUInt32(0x00000000); // reserved
+
+    aDirStream.Seek(0);
+
+#if VBA_EXPORT_DEBUG
+    const OUString aDirFileName("/tmp/vba_dir_out.bin");
+    SvFileStream aDirStreamDebug(aDirFileName, STREAM_READWRITE);
+
+    aDirStreamDebug.WriteStream(aDirStream);
+    aDirStream.Seek(0);
+#endif
+
+    // the stream for the compression
+    SvMemoryStream aMemoryStream(4096, 4096);
+    aMemoryStream.WriteStream(aDirStream);
+
+    VBACompression aCompression(rStrm, aDirStream);
+    aCompression.write();
 }
 
 }
@@ -602,19 +623,8 @@ void VbaExport::exportVBA()
     SotStorage* pVBAStream = aStorage->OpenSotStorage("VBA", STREAM_READWRITE);
     SotStorageStream* pDirStream = pVBAStream->OpenSotStream("dir", STREAM_READWRITE);
 
-    const OUString aDirFileName("/tmp/vba_dir_out.bin");
-    SvFileStream aDirStream(aDirFileName, STREAM_READWRITE);
-
     // export
-    exportDirStream(aDirStream);
-
-    aDirStream.Seek(0);
-
-    SvMemoryStream aMemoryStream(4096, 4096);
-    aMemoryStream.WriteStream(aDirStream);
-
-    VBACompression aCompression(*pDirStream, aMemoryStream);
-    aCompression.write();
+    exportDirStream(*pDirStream);
 
     css::uno::Reference<css::container::XNameContainer> xNameContainer = getBasicLibrary();
     css::uno::Sequence<OUString> aElementNames = xNameContainer->getElementNames();


More information about the Libreoffice-commits mailing list