[Libreoffice-commits] core.git: 5 commits - filter/Configuration_filter.mk filter/README filter/source include/oox oox/source sc/source
Markus Mohrhard
markus.mohrhard at googlemail.com
Thu Sep 24 21:43:52 PDT 2015
filter/Configuration_filter.mk | 1
filter/README | 12 ++
filter/source/config/fragments/filters/calc_MS_Excel_2007_VBA_XML.xcu | 30 +++++++
filter/source/config/fragments/filters/calc_MS_Excel_2007_XML.xcu | 2
include/oox/core/filterbase.hxx | 5 -
oox/source/core/filterbase.cxx | 34 +++++++-
oox/source/ole/vbaexport.cxx | 22 +++--
sc/source/filter/excel/xestream.cxx | 42 ++++++----
sc/source/filter/inc/xestream.hxx | 4
sc/source/filter/oox/excelfilter.cxx | 3
10 files changed, 125 insertions(+), 30 deletions(-)
New commits:
commit c52982e7410dc8457b0496ece681ff06f1d3596d
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Fri Sep 25 06:39:40 2015 +0200
better OOXML VBA export
Change-Id: If02aa26e974b0f16b45c5476234c6425fd128ae4
diff --git a/filter/Configuration_filter.mk b/filter/Configuration_filter.mk
index bb54fcd..4ff9855 100644
--- a/filter/Configuration_filter.mk
+++ b/filter/Configuration_filter.mk
@@ -546,6 +546,7 @@ $(eval $(call filter_Configuration_add_filters,fcfg_langpack,fcfg_calc_filters.x
calc8 \
calc8_template \
calc_MS_Excel_2007_XML \
+ calc_MS_Excel_2007_VBA_XML \
calc_MS_Excel_2007_XML_Template \
calc_MS_Excel_2007_Binary \
calc_OOXML \
diff --git a/filter/source/config/fragments/filters/calc_MS_Excel_2007_VBA_XML.xcu b/filter/source/config/fragments/filters/calc_MS_Excel_2007_VBA_XML.xcu
new file mode 100644
index 0000000..afd66db
--- /dev/null
+++ b/filter/source/config/fragments/filters/calc_MS_Excel_2007_VBA_XML.xcu
@@ -0,0 +1,30 @@
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+-->
+<node oor:name="Calc MS Excel 2007 VBA XML" oor:op="replace">
+ <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER PREFERRED ENCRYPTION PASSWORDTOMODIFY</value></prop>
+ <prop oor:name="UIComponent"/>
+ <prop oor:name="FilterService"><value>com.sun.star.comp.oox.xls.ExcelFilter</value></prop>
+ <prop oor:name="UserData"><value>macro-enabled</value></prop>
+ <prop oor:name="FileFormatVersion"/>
+ <prop oor:name="Type"><value>MS Excel 2007 XML</value></prop>
+ <prop oor:name="TemplateName"/>
+ <prop oor:name="DocumentService"><value>com.sun.star.sheet.SpreadsheetDocument</value></prop>
+ <prop oor:name="UIName">
+ <value xml:lang="en-US">Microsoft Excel 2007-2016 XML (macro enabled)</value>
+ </prop>
+</node>
diff --git a/include/oox/core/filterbase.hxx b/include/oox/core/filterbase.hxx
index 6056792..f34e0ba 100644
--- a/include/oox/core/filterbase.hxx
+++ b/include/oox/core/filterbase.hxx
@@ -245,6 +245,7 @@ public:
virtual void SAL_CALL cancel()
throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
+ bool exportVBA() const;
protected:
virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
diff --git a/oox/source/core/filterbase.cxx b/oox/source/core/filterbase.cxx
index f56397e..9c7383a 100644
--- a/oox/source/core/filterbase.cxx
+++ b/oox/source/core/filterbase.cxx
@@ -148,6 +148,8 @@ struct FilterBaseImpl
Reference< XInteractionHandler > mxInteractionHandler;
Reference< XShape > mxParentShape;
+ bool mbExportVBA;
+
explicit FilterBaseImpl( const Reference< XComponentContext >& rxContext ) throw( RuntimeException );
void setDocumentModel( const Reference< XComponent >& rxComponent ) throw( IllegalArgumentException );
@@ -159,7 +161,8 @@ FilterBaseImpl::FilterBaseImpl( const Reference< XComponentContext >& rxContext
meDirection( FILTERDIRECTION_UNKNOWN ),
meVersion( ECMA_DIALECT ),
mxComponentContext( rxContext, UNO_SET_THROW ),
- mxComponentFactory( rxContext->getServiceManager(), UNO_SET_THROW )
+ mxComponentFactory( rxContext->getServiceManager(), UNO_SET_THROW ),
+ mbExportVBA(false)
{
}
@@ -417,6 +420,30 @@ void SAL_CALL FilterBase::initialize( const Sequence< Any >& rArgs ) throw( Exce
catch( Exception& )
{
}
+
+ if (rArgs.getLength() >= 1)
+ {
+ Sequence<css::beans::PropertyValue> aSeq;
+ rArgs[0] >>= aSeq;
+ sal_Int32 nLen = aSeq.getLength();
+ for (sal_Int32 i = 0; i < nLen; ++i)
+ {
+ css::beans::PropertyValue& rVal = aSeq[i];
+ if (rVal.Name == "UserData")
+ {
+ css::uno::Sequence<OUString> aUserDataSeq;
+ rVal.Value >>= aUserDataSeq;
+ sal_Int32 nUserDataSeqLen = aUserDataSeq.getLength();
+ for (sal_Int32 j = 0; j < nUserDataSeqLen; ++j)
+ {
+ if (aUserDataSeq[j] == "macro-enabled")
+ {
+ mxImpl->mbExportVBA = true;
+ }
+ }
+ }
+ }
+ }
}
// com.sun.star.document.XImporter interface
@@ -553,6 +580,11 @@ GraphicHelper* FilterBase::implCreateGraphicHelper() const
return new GraphicHelper( mxImpl->mxComponentContext, mxImpl->mxTargetFrame, mxImpl->mxStorage );
}
+bool FilterBase::exportVBA() const
+{
+ return mxImpl->mbExportVBA;
+}
+
} // namespace core
} // namespace oox
diff --git a/sc/source/filter/excel/xestream.cxx b/sc/source/filter/excel/xestream.cxx
index 1595019..716b360 100644
--- a/sc/source/filter/excel/xestream.cxx
+++ b/sc/source/filter/excel/xestream.cxx
@@ -928,9 +928,10 @@ sax_fastparser::FSHelperPtr XclXmlUtils::WriteFontData( sax_fastparser::FSHelper
return pStream;
}
-XclExpXmlStream::XclExpXmlStream( const Reference< XComponentContext >& rCC )
+XclExpXmlStream::XclExpXmlStream( const Reference< XComponentContext >& rCC, bool bExportVBA )
: XmlFilterBase( rCC ),
- mpRoot( NULL )
+ mpRoot( NULL ),
+ mbExportVBA(bExportVBA)
{
}
@@ -1088,25 +1089,34 @@ bool XclExpXmlStream::exportDocument()
ScDocShell::GetViewData()->WriteExtOptions( mpRoot->GetExtDocOptions() );
OUString const workbook = "xl/workbook.xml";
+ const char* pWorkbookContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml";
+
+
+ if (mbExportVBA)
+ pWorkbookContentType = "application/vnd.ms-excel.sheet.macroEnabled.main+xml";
+
PushStream( CreateOutputStream( workbook, workbook,
Reference <XOutputStream>(),
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",
+ pWorkbookContentType,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" ) );
- VbaExport aExport(getModel());
- if (aExport.containsVBAProject())
+ if (mbExportVBA)
{
- SvMemoryStream aVbaStream(4096, 4096);
- tools::SvRef<SotStorage> pVBAStorage(new SotStorage(aVbaStream));
- aExport.exportVBA(pVBAStorage);
- aVbaStream.Seek(0);
- css::uno::Reference<css::io::XInputStream> xVBAStream(
- new utl::OInputStreamWrapper(aVbaStream));
- css::uno::Reference<css::io::XOutputStream> xVBAOutput =
- openFragmentStream("xl/vbaProject.bin", "VBA");
- comphelper::OStorageHelper::CopyInputToOutput(xVBAStream, xVBAOutput);
-
- addRelation(GetCurrentStream()->getOutputStream(), "http://schemas.microsoft.com/office/2006/relationships/vbaProject", "vbaProject.bin");
+ VbaExport aExport(getModel());
+ if (aExport.containsVBAProject())
+ {
+ SvMemoryStream aVbaStream(4096, 4096);
+ tools::SvRef<SotStorage> pVBAStorage(new SotStorage(aVbaStream));
+ aExport.exportVBA(pVBAStorage);
+ aVbaStream.Seek(0);
+ css::uno::Reference<css::io::XInputStream> xVBAStream(
+ new utl::OInputStreamWrapper(aVbaStream));
+ css::uno::Reference<css::io::XOutputStream> xVBAOutput =
+ openFragmentStream("xl/vbaProject.bin", "application/vnd.ms-office.vbaProject");
+ comphelper::OStorageHelper::CopyInputToOutput(xVBAStream, xVBAOutput);
+
+ addRelation(GetCurrentStream()->getOutputStream(), "http://schemas.microsoft.com/office/2006/relationships/vbaProject", "vbaProject.bin");
+ }
}
// destruct at the end of the block
diff --git a/sc/source/filter/inc/xestream.hxx b/sc/source/filter/inc/xestream.hxx
index a4177dc..dce1cd4 100644
--- a/sc/source/filter/inc/xestream.hxx
+++ b/sc/source/filter/inc/xestream.hxx
@@ -293,7 +293,7 @@ public:
class XclExpXmlStream : public oox::core::XmlFilterBase
{
public:
- XclExpXmlStream( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& rCC );
+ XclExpXmlStream( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& rCC, bool bExportVBA );
virtual ~XclExpXmlStream();
/** Returns the filter root data. */
@@ -374,6 +374,8 @@ private:
const XclExpRoot* mpRoot;
std::stack< sax_fastparser::FSHelperPtr > maStreams;
XclExpXmlPathToStateMap maOpenedStreamMap;
+
+ bool mbExportVBA;
};
#endif
diff --git a/sc/source/filter/oox/excelfilter.cxx b/sc/source/filter/oox/excelfilter.cxx
index 5771a90..ef992e7 100644
--- a/sc/source/filter/oox/excelfilter.cxx
+++ b/sc/source/filter/oox/excelfilter.cxx
@@ -158,8 +158,9 @@ sal_Bool SAL_CALL ExcelFilter::filter( const ::com::sun::star::uno::Sequence< ::
if ( isExportFilter() )
{
+ bool bExportVBA = exportVBA();
Reference< XExporter > xExporter(
- new XclExpXmlStream( getComponentContext() ) );
+ new XclExpXmlStream( getComponentContext(), bExportVBA ) );
Reference< XComponent > xDocument( getModel(), UNO_QUERY );
Reference< XFilter > xFilter( xExporter, UNO_QUERY );
commit 14c521c879514006af72193c7f6546d954626f73
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Fri Sep 25 05:16:15 2015 +0200
remove whitespace
Change-Id: If01b299fd40597cc3ee91c01a6a7785c6d44352e
diff --git a/include/oox/core/filterbase.hxx b/include/oox/core/filterbase.hxx
index 471377f..6056792 100644
--- a/include/oox/core/filterbase.hxx
+++ b/include/oox/core/filterbase.hxx
@@ -72,8 +72,6 @@ namespace oox { namespace ole {
namespace oox {
namespace core {
-
-
enum OoxmlVersion
{
ECMA_DIALECT,
@@ -279,8 +277,6 @@ private:
std::unique_ptr< FilterBaseImpl > mxImpl;
};
-
-
} // namespace core
} // namespace oox
commit c0cb29569ac06e6feccbee30c42df6657aa3ba9e
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Fri Sep 25 02:47:29 2015 +0200
document filter's type and filters split
The explanation was kindly provided by Kohei.
Change-Id: Ibcf652b5df14abeb6c97dfbba58a5015f56ca335
diff --git a/filter/README b/filter/README
index 85dfb9b..6c13f14 100644
--- a/filter/README
+++ b/filter/README
@@ -11,3 +11,15 @@ loaded from other places. For instance "icgm" has ImportCGM, and is
loaded and used by sd/source/filter/cgm/sdcgmfilter.cxx (!).
Svgreader is used for "File->Open" and then to choose the svg file.
For "Insert->Picture->From File", see svgio/source/svgreader directory.
+
+====================
+filter configuration
+====================
+
+The filter configuration consists of two parts, the type definition in
+filter/source/config/fragments/types/ and the actual filter definition
+in filter/source/config/fragments/filters/.
+
+Each file type e.g. text file should be represented by exactly one
+type definition. This type can then be referenced by several different
+filters, e.g. calc text, writer text.
commit 21d67ef6c0627f2bdbd2e0d4c656838ebe149656
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Fri Sep 25 02:37:17 2015 +0200
indentation fix
Change-Id: I3a68ec1a23474af12c138dcfdc5c00ec1ee2eab7
diff --git a/filter/source/config/fragments/filters/calc_MS_Excel_2007_XML.xcu b/filter/source/config/fragments/filters/calc_MS_Excel_2007_XML.xcu
index 13febd1..2979b7d 100644
--- a/filter/source/config/fragments/filters/calc_MS_Excel_2007_XML.xcu
+++ b/filter/source/config/fragments/filters/calc_MS_Excel_2007_XML.xcu
@@ -27,4 +27,4 @@
<prop oor:name="UIName">
<value xml:lang="en-US">Microsoft Excel 2007-2013 XML</value>
</prop>
- </node>
+</node>
commit 4d9b0e2af84760dc136154017f5cf6b637caba02
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Fri Sep 25 02:07:04 2015 +0200
export correct id for workbook stream
Change-Id: I03fa8243fa6472a75fc0881ba47c631e3730e5d3
diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index f61e493..9f8a5dc 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -66,6 +66,12 @@ void exportUTF16String(SvStream& rStrm, const OUString& rString)
}
}
+bool isWorkbook(css::uno::Reference<css::uno::XInterface> xInterface)
+{
+ css::uno::Reference<ooo::vba::excel::XWorkbook> xWorkbook(xInterface, css::uno::UNO_QUERY);
+ return xWorkbook.is();
+}
+
}
VBACompressionChunk::VBACompressionChunk(SvStream& rCompressedStream, const sal_uInt8* pData, sal_Size nChunkSize)
@@ -636,14 +642,18 @@ void exportDirStream(SvStream& rStrm, css::uno::Reference<css::container::XNameC
}
// section 2.3.4.3 Module Stream
-void exportModuleStream(SvStream& rStrm, const OUString& rSourceCode, const OUString& aElementName, sal_Int32 nModuleType)
+void exportModuleStream(SvStream& rStrm, const OUString& rSourceCode, const OUString& aElementName, css::script::ModuleInfo& rInfo)
{
SvMemoryStream aModuleStream(4096, 4096);
exportString(aModuleStream, "Attribute VB_Name = \"" + aElementName + "\"\r\n");
- if (nModuleType == 4)
+ if (rInfo.ModuleType == 4)
{
- exportString(aModuleStream, "Attribute VB_Base = \"0{00020820-0000-0000-C000-000000000046}\"\r\n");
+ if (isWorkbook(rInfo.ModuleObject))
+ exportString(aModuleStream, "Attribute VB_Base = \"0{00020819-0000-0000-C000-000000000046}\"\r\n");
+ else
+ exportString(aModuleStream, "Attribute VB_Base = \"0{00020820-0000-0000-C000-000000000046}\"\r\n");
+
exportString(aModuleStream, "Attribute VB_GlobalNameSpace = False\r\n");
exportString(aModuleStream, "Attribute VB_Creatable = False\r\n");
exportString(aModuleStream, "Attribute VB_PredeclaredId = True\r\n");
@@ -834,8 +844,8 @@ void getCorrectExportOrder(css::uno::Reference<css::container::XNameContainer> x
for (sal_Int32 i = 0; i < n; ++i)
{
css::script::ModuleInfo aModuleInfo = xModuleInfo->getModuleInfo(aElementNames[i]);
- css::uno::Reference<ooo::vba::excel::XWorkbook> xWorkbook(aModuleInfo.ModuleObject, css::uno::UNO_QUERY);
- if (xWorkbook.is())
+ bool bWorkbook = isWorkbook(aModuleInfo.ModuleObject);
+ if (bWorkbook)
{
nWorkbookIndex = i;
rLibraryMap[nCurrentId] = i;
@@ -952,7 +962,7 @@ void VbaExport::exportVBA(SotStorage* pRootStorage)
css::script::ModuleInfo aModuleInfo = xModuleInfo->getModuleInfo(rModuleName);
OUString aSourceCode;
aCode >>= aSourceCode;
- exportModuleStream(*pModuleStream, aSourceCode, rModuleName, aModuleInfo.ModuleType);
+ exportModuleStream(*pModuleStream, aSourceCode, rModuleName, aModuleInfo);
pModuleStream->Commit();
}
More information about the Libreoffice-commits
mailing list