diff options
author | Katarina Machalkova <kmachalkova@suse.cz> | 2010-10-13 17:50:08 +0200 |
---|---|---|
committer | Katarina Machalkova <kmachalkova@suse.cz> | 2010-10-13 19:51:45 +0200 |
commit | aae7fdec530e8b60b2a02d94a82dc006d12ce910 (patch) | |
tree | 182ae4d25c5f49e109bce9a5fce860dd02c361dc | |
parent | 2ce689bf63f903d459f7e102830b429646ff16a1 (diff) |
Merged xlsx-shared-xlsx-shared-import-and-export.diff from ooo-build
-rw-r--r-- | sc/source/filter/excel/excdoc.cxx | 16 | ||||
-rw-r--r-- | sc/source/filter/excel/excel.cxx | 19 | ||||
-rw-r--r-- | sc/source/filter/excel/expop2.cxx | 56 | ||||
-rw-r--r-- | sc/source/filter/excel/xestream.cxx | 180 | ||||
-rw-r--r-- | sc/source/filter/inc/excdoc.hxx | 2 | ||||
-rw-r--r-- | sc/source/filter/inc/exp_op.hxx | 15 | ||||
-rw-r--r-- | sc/source/filter/inc/xestream.hxx | 8 | ||||
-rw-r--r-- | sc/source/ui/docshell/docsh.cxx | 6 | ||||
-rw-r--r-- | sc/util/scfilt.map | 3 |
9 files changed, 172 insertions, 133 deletions
diff --git a/sc/source/filter/excel/excdoc.cxx b/sc/source/filter/excel/excdoc.cxx index 0e9b70d66333..b366f3a413d5 100644 --- a/sc/source/filter/excel/excdoc.cxx +++ b/sc/source/filter/excel/excdoc.cxx @@ -781,19 +781,17 @@ void ExcDocument::Write( SvStream& rSvStrm ) pExpChangeTrack->Write(); } -void ExcDocument::WriteXml( SvStream& rStrm ) +void ExcDocument::WriteXml( XclExpXmlStream& rStrm ) { - XclExpXmlStream aStrm( ::comphelper::getProcessServiceFactory(), rStrm, GetRoot() ); - SfxObjectShell* pDocShell = GetDocShell(); using namespace ::com::sun::star; uno::Reference<document::XDocumentPropertiesSupplier> xDPS( pDocShell->GetModel(), uno::UNO_QUERY_THROW ); uno::Reference<document::XDocumentProperties> xDocProps = xDPS->getDocumentProperties(); - aStrm.exportDocumentProperties( xDocProps ); + rStrm.exportDocumentProperties( xDocProps ); - sax_fastparser::FSHelperPtr& rWorkbook = aStrm.GetCurrentStream(); + sax_fastparser::FSHelperPtr& rWorkbook = rStrm.GetCurrentStream(); rWorkbook->startElement( XML_workbook, XML_xmlns, "http://schemas.openxmlformats.org/spreadsheetml/2006/main", FSNS(XML_xmlns, XML_r), "http://schemas.openxmlformats.org/officeDocument/2006/relationships", @@ -810,7 +808,7 @@ void ExcDocument::WriteXml( SvStream& rStrm ) { InitializeSave(); - aHeader.WriteXml( aStrm ); + aHeader.WriteXml( rStrm ); for( size_t nTab = 0, nTabCount = maTableList.GetSize(); nTab < nTabCount; ++nTab ) { @@ -821,17 +819,17 @@ void ExcDocument::WriteXml( SvStream& rStrm ) xBoundsheet->SetStreamPos( aXclStrm.GetSvStreamPos() ); #endif // write the table - maTableList.GetRecord( nTab )->WriteXml( aStrm ); + maTableList.GetRecord( nTab )->WriteXml( rStrm ); } } if( pExpChangeTrack ) - pExpChangeTrack->WriteXml( aStrm ); + pExpChangeTrack->WriteXml( rStrm ); rWorkbook->endElement( XML_workbook ); rWorkbook.reset(); - aStrm.commitStorage(); + rStrm.commitStorage(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/excel/excel.cxx b/sc/source/filter/excel/excel.cxx index 1fa74a3d5d17..c0012c5519f7 100644 --- a/sc/source/filter/excel/excel.cxx +++ b/sc/source/filter/excel/excel.cxx @@ -262,25 +262,10 @@ static FltError lcl_ExportExcelBiff( SfxMedium& rMedium, ScDocument *pDocument, return eRet; } -static FltError lcl_ExportExcel2007Xml( SfxMedium& rMedium, ScDocument *pDocument, - SvStream* pMedStrm, CharSet eNach ) -{ - SotStorageRef xRootStrg = (SotStorage*) 0; - - XclExpRootData aExpData( EXC_BIFF8, rMedium, xRootStrg, *pDocument, eNach ); - aExpData.meOutput = EXC_OUTPUT_XML_2007; - - ExportXml2007 aFilter( aExpData, *pMedStrm ); - - FltError eRet = aFilter.Write(); - - return eRet; -} - FltError ScFormatFilterPluginImpl::ScExportExcel5( SfxMedium& rMedium, ScDocument *pDocument, ExportFormatExcel eFormat, CharSet eNach ) { - if( eFormat != ExpBiff5 && eFormat != ExpBiff8 && eFormat != Exp2007Xml ) + if( eFormat != ExpBiff5 && eFormat != ExpBiff8 ) return eERR_NI; // check the passed Calc document @@ -295,8 +280,6 @@ FltError ScFormatFilterPluginImpl::ScExportExcel5( SfxMedium& rMedium, ScDocumen FltError eRet = eERR_UNKN_BIFF; if( eFormat == ExpBiff5 || eFormat == ExpBiff8 ) eRet = lcl_ExportExcelBiff( rMedium, pDocument, pMedStrm, eFormat == ExpBiff8, eNach ); - else if( eFormat == Exp2007Xml ) - eRet = lcl_ExportExcel2007Xml( rMedium, pDocument, pMedStrm, eNach ); return eRet; } diff --git a/sc/source/filter/excel/expop2.cxx b/sc/source/filter/excel/expop2.cxx index 2f1a14dfdf1a..643b557300c6 100644 --- a/sc/source/filter/excel/expop2.cxx +++ b/sc/source/filter/excel/expop2.cxx @@ -148,60 +148,4 @@ ExportBiff8::ExportBiff8( XclExpRootData& rExpData, SvStream& rStrm ) : ExportBiff8::~ExportBiff8() { } - - -ExportXml2007::ExportXml2007( XclExpRootData& rExpData, SvStream& rStrm ) - : ExportTyp( rStrm, &rExpData.mrDoc, rExpData.meTextEnc ) - , XclExpRoot( rExpData ) -{ - pExcRoot = &GetOldRoot(); - pExcRoot->pER = this; - pExcRoot->eDateiTyp = Biff8; - pExcDoc = new ExcDocument( *this ); -} - - -ExportXml2007::~ExportXml2007() -{ - delete pExcDoc; -} - - -FltError ExportXml2007::Write() -{ - SfxObjectShell* pDocShell = GetDocShell(); - DBG_ASSERT( pDocShell, "ExportXml2007::Write - no document shell" ); - - SotStorageRef xRootStrg = GetRootStorage(); - DBG_ASSERT( xRootStrg.Is(), "ExportXml2007::Write - no root storage" ); - - bool bWriteBasicCode = false; - bool bWriteBasicStrg = false; - - if( SvtFilterOptions* pFilterOpt = SvtFilterOptions::Get() ) - { - bWriteBasicCode = pFilterOpt->IsLoadExcelBasicCode(); - bWriteBasicStrg = pFilterOpt->IsLoadExcelBasicStorage(); - } - - if( pDocShell && xRootStrg.Is() && bWriteBasicStrg ) - { - SvxImportMSVBasic aBasicImport( *pDocShell, *xRootStrg, bWriteBasicCode, bWriteBasicStrg ); - ULONG nErr = aBasicImport.SaveOrDelMSVBAStorage( TRUE, EXC_STORAGE_VBA_PROJECT ); - if( nErr != ERRCODE_NONE ) - pDocShell->SetError( nErr, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); - } - - pExcDoc->ReadDoc(); // ScDoc -> ExcDoc - pExcDoc->WriteXml( aOut ); // wechstreamen - - //! TODO: separate warnings for columns and sheets - const XclExpAddressConverter& rAddrConv = GetAddressConverter(); - if( rAddrConv.IsColTruncated() || rAddrConv.IsRowTruncated() || rAddrConv.IsTabTruncated() ) - return SCWARN_EXPORT_MAXROW; - - return eERR_OK; -} - - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/excel/xestream.cxx b/sc/source/filter/excel/xestream.cxx index 8e3a535e4b93..eefa876aadfd 100644 --- a/sc/source/filter/excel/xestream.cxx +++ b/sc/source/filter/excel/xestream.cxx @@ -47,6 +47,9 @@ #include "rangelst.hxx" #include "compiler.hxx" +#include <../../ui/inc/docsh.hxx> +#include <excdoc.hxx> + #include <oox/core/tokens.hxx> #include <formula/grammar.hxx> #include <oox/export/drawingml.hxx> @@ -54,14 +57,20 @@ #define DEBUG_XL_ENCRYPTION 0 using ::com::sun::star::beans::PropertyValue; +using ::com::sun::star::embed::XStorage; using ::com::sun::star::io::XOutputStream; using ::com::sun::star::io::XStream; using ::com::sun::star::lang::XComponent; using ::com::sun::star::lang::XMultiServiceFactory; using ::com::sun::star::lang::XServiceInfo; +using ::com::sun::star::lang::XSingleServiceFactory; +using ::com::sun::star::registry::InvalidRegistryException; +using ::com::sun::star::registry::XRegistryKey; +using ::com::sun::star::uno::Exception; using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::Sequence; using ::com::sun::star::uno::UNO_QUERY; +using ::com::sun::star::uno::XInterface; using ::rtl::OString; using ::rtl::OUString; using ::utl::OStreamWrapper; @@ -951,29 +960,10 @@ sax_fastparser::FSHelperPtr XclXmlUtils::WriteFontData( sax_fastparser::FSHelper // ============================================================================ -XclExpXmlStream::XclExpXmlStream( const Reference< XMultiServiceFactory >& rSMgr, SvStream& rStrm, const XclExpRoot& rRoot ) - : XmlFilterBase( rSMgr ) - , mrRoot( rRoot ) +XclExpXmlStream::XclExpXmlStream( const Reference< XMultiServiceFactory >& rSMgr ) + : XmlFilterBase( rSMgr ), + mpRoot( NULL ) { - Sequence< PropertyValue > aArgs( 1 ); - const OUString sStream( RTL_CONSTASCII_USTRINGPARAM( "StreamForOutput" ) ); - aArgs[0].Name = sStream; - aArgs[0].Value <<= Reference< XStream > ( new OStreamWrapper( rStrm ) ); - - XServiceInfo* pInfo = rRoot.GetDocModelObj(); - Reference< XComponent > aComponent( pInfo, UNO_QUERY ); - setSourceDocument( aComponent ); - filter( aArgs ); - - PushStream( CreateOutputStream( - OUString::createFromAscii( "xl/workbook.xml" ), - OUString::createFromAscii( "xl/workbook.xml" ), - Reference< XOutputStream >(), - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml", - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" ) ); - - DrawingML::ResetCounters(); - XclObjList::ResetCounters(); } XclExpXmlStream::~XclExpXmlStream() @@ -1086,14 +1076,57 @@ oox::drawingml::chart::ChartConverter& XclExpXmlStream::getChartConverter() return * (oox::drawingml::chart::ChartConverter*) NULL; } -bool XclExpXmlStream::exportDocument() throw() +ScDocShell* XclExpXmlStream::getDocShell() { - return false; + Reference< XInterface > xModel( getModel(), UNO_QUERY ); + + ScModelObj *pObj = dynamic_cast < ScModelObj* >( xModel.get() ); + + if ( pObj ) + return reinterpret_cast < ScDocShell* >( pObj->GetEmbeddedObject() ); + + return 0; } -::rtl::OUString XclExpXmlStream::implGetImplementationName() const +bool XclExpXmlStream::exportDocument() throw() { - return CREATE_OUSTRING( "TODO" ); + ScDocShell* pShell = getDocShell(); + ScDocument* pDoc = pShell->GetDocument(); + SotStorageRef rStorage = dynamic_cast <SotStorage*>( Reference<XStorage>( pShell->GetStorage() ).get() ); + + XclExpRootData aData( EXC_BIFF8, *pShell->GetMedium (), rStorage, *pDoc, RTL_TEXTENCODING_DONTKNOW ); + XclExpRoot aRoot( aData ); + + mpRoot = &aRoot; + aRoot.GetOldRoot().pER = &aRoot; + aRoot.GetOldRoot().eDateiTyp = Biff8; + + if ( SvtFilterOptions* pOptions = SvtFilterOptions::Get() ) + if ( pShell && pOptions->IsLoadExcelBasicStorage() ) + if ( sal_uInt32 nError + = SvxImportMSVBasic( *pShell, *rStorage, + pOptions->IsLoadExcelBasicCode(), + pOptions->IsLoadExcelBasicStorage() ) + .SaveOrDelMSVBAStorage( true, EXC_STORAGE_VBA_PROJECT) ) + { + pShell->SetError( nError, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); + } + + OUString const workbook = CREATE_OUSTRING( "xl/workbook.xml" ); + PushStream( CreateOutputStream( workbook, workbook, + Reference <XOutputStream>(), + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" ) ); + + // destruct at the end of the block + { + ExcDocument aDocRoot( aRoot ); + aDocRoot.ReadDoc(); + aDocRoot.WriteXml( *this ); + } + + mpRoot = NULL; + return true; } void XclExpXmlStream::Trace( const char* format, ...) @@ -1104,4 +1137,99 @@ void XclExpXmlStream::Trace( const char* format, ...) va_end( ap ); } +////////////////////////////////////////////////////////////////////////// +// UNO stuff so that the filter is registered +////////////////////////////////////////////////////////////////////////// + +#define IMPL_NAME "com.sun.star.comp.oox.ExcelFilterExport" + +OUString XlsxExport_getImplementationName() +{ + return OUString( RTL_CONSTASCII_USTRINGPARAM( IMPL_NAME ) ); +} + +::rtl::OUString XclExpXmlStream::implGetImplementationName() const +{ + return CREATE_OUSTRING( "TODO" ); +} + + +Sequence< OUString > SAL_CALL XlsxExport_getSupportedServiceNames() throw() +{ + const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.ExportFilter" ) ); + const Sequence< OUString > aSeq( &aServiceName, 1 ); + return aSeq; +} + +Reference< XInterface > SAL_CALL XlsxExport_createInstance(const Reference< XMultiServiceFactory > & rSMgr ) throw( Exception ) +{ + return (cppu::OWeakObject*) new XclExpXmlStream( rSMgr ); +} + +#ifdef __cplusplus +extern "C" +{ +#endif + +SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment( const sal_Char ** ppEnvTypeName, uno_Environment ** /* ppEnv */ ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo( void* /* pServiceManager */, void* pRegistryKey ) +{ + sal_Bool bRet = sal_False; + + if( pRegistryKey ) + { + try + { + Reference< XRegistryKey > xNewKey1( + static_cast< XRegistryKey* >( pRegistryKey )->createKey( + OUString::createFromAscii( IMPL_NAME "/UNO/SERVICES/" ) ) ); + xNewKey1->createKey( XlsxExport_getSupportedServiceNames().getConstArray()[0] ); + + bRet = sal_True; + } + catch( InvalidRegistryException& ) + { + OSL_ENSURE( sal_False, "### InvalidRegistryException!" ); + } + } + + return bRet; +} + +// ------------------------ +// - component_getFactory - +// ------------------------ + +SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory( const sal_Char* pImplName, void* pServiceManager, void* /* pRegistryKey */ ) +{ + Reference< XSingleServiceFactory > xFactory; + void* pRet = 0; + + if ( rtl_str_compare( pImplName, IMPL_NAME ) == 0 ) + { + const OUString aServiceName( OUString::createFromAscii( IMPL_NAME ) ); + + xFactory = Reference< XSingleServiceFactory >( ::cppu::createSingleFactory( + reinterpret_cast< XMultiServiceFactory* >( pServiceManager ), + XlsxExport_getImplementationName(), + XlsxExport_createInstance, + XlsxExport_getSupportedServiceNames() ) ); + } + + if ( xFactory.is() ) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + + return pRet; +} + +#ifdef __cplusplus +} +#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/inc/excdoc.hxx b/sc/source/filter/inc/excdoc.hxx index 5da6a5d38d83..39cacc405170 100644 --- a/sc/source/filter/inc/excdoc.hxx +++ b/sc/source/filter/inc/excdoc.hxx @@ -110,7 +110,7 @@ public: void ReadDoc( void ); void Write( SvStream& rSvStrm ); - void WriteXml( SvStream& rSvStrm ); + void WriteXml( XclExpXmlStream& ); }; diff --git a/sc/source/filter/inc/exp_op.hxx b/sc/source/filter/inc/exp_op.hxx index 79fff8675d84..9bb2765ccc0b 100644 --- a/sc/source/filter/inc/exp_op.hxx +++ b/sc/source/filter/inc/exp_op.hxx @@ -127,21 +127,6 @@ public: }; -class ExportXml2007 : public ExportTyp, protected XclExpRoot -{ -private: - ExcDocument* pExcDoc; - -protected: - RootData* pExcRoot; - -public: - ExportXml2007( XclExpRootData& rExpData, SvStream& rStrm ); - virtual ~ExportXml2007(); - FltError Write(); -}; - - #endif diff --git a/sc/source/filter/inc/xestream.hxx b/sc/source/filter/inc/xestream.hxx index 36879c91f76b..f0bcb70cf033 100644 --- a/sc/source/filter/inc/xestream.hxx +++ b/sc/source/filter/inc/xestream.hxx @@ -257,6 +257,7 @@ private: (s.Len() && s.GetChar( 0 ) != 0 ? XclXmlUtils::ToOString( s ).getStr() : NULL) class ScAddress; +class ScDocShell; class ScDocument; class ScFormulaCell; class ScRange; @@ -305,11 +306,11 @@ public: class XclExpXmlStream : public oox::core::XmlFilterBase { public: - XclExpXmlStream( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rSMgr, SvStream& rStrm, const XclExpRoot& rRoot ); + XclExpXmlStream( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rSMgr ); virtual ~XclExpXmlStream(); /** Returns the filter root data. */ - inline const XclExpRoot& GetRoot() const { return mrRoot; } + inline const XclExpRoot& GetRoot() const { return *mpRoot; } sax_fastparser::FSHelperPtr& GetCurrentStream(); void PushStream( sax_fastparser::FSHelperPtr aStream ); @@ -341,12 +342,13 @@ public: void Trace( const char* format, ...); private: virtual ::rtl::OUString implGetImplementationName() const; + ScDocShell *getDocShell(); typedef std::map< ::rtl::OUString, std::pair< ::rtl::OUString, sax_fastparser::FSHelperPtr > > XclExpXmlPathToStateMap; - const XclExpRoot& mrRoot; /// Filter root data. + const XclExpRoot* mpRoot; std::stack< sax_fastparser::FSHelperPtr > maStreams; XclExpXmlPathToStateMap maOpenedStreamMap; }; diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index d3152f51a0d3..ea287877380c 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -172,7 +172,6 @@ static const sal_Char __FAR_DATA pFilterExcel95[] = "MS Excel 95"; static const sal_Char __FAR_DATA pFilterEx95Temp[] = "MS Excel 95 Vorlage/Template"; static const sal_Char __FAR_DATA pFilterExcel97[] = "MS Excel 97"; static const sal_Char __FAR_DATA pFilterEx97Temp[] = "MS Excel 97 Vorlage/Template"; -static const sal_Char __FAR_DATA pFilterEx07Xml[] = "Calc MS Excel 2007 XML"; static const sal_Char __FAR_DATA pFilterDBase[] = "dBase"; static const sal_Char __FAR_DATA pFilterDif[] = "DIF"; static const sal_Char __FAR_DATA pFilterSylk[] = "SYLK"; @@ -2091,8 +2090,7 @@ BOOL __EXPORT ScDocShell::ConvertTo( SfxMedium &rMed ) } else if (aFltName.EqualsAscii(pFilterExcel5) || aFltName.EqualsAscii(pFilterExcel95) || aFltName.EqualsAscii(pFilterExcel97) || aFltName.EqualsAscii(pFilterEx5Temp) || - aFltName.EqualsAscii(pFilterEx95Temp) || aFltName.EqualsAscii(pFilterEx97Temp) || - aFltName.EqualsAscii(pFilterEx07Xml)) + aFltName.EqualsAscii(pFilterEx95Temp) || aFltName.EqualsAscii(pFilterEx97Temp)) { WaitObject aWait( GetActiveDialogParent() ); @@ -2134,8 +2132,6 @@ BOOL __EXPORT ScDocShell::ConvertTo( SfxMedium &rMed ) ExportFormatExcel eFormat = ExpBiff5; if( aFltName.EqualsAscii( pFilterExcel97 ) || aFltName.EqualsAscii( pFilterEx97Temp ) ) eFormat = ExpBiff8; - if( aFltName.EqualsAscii( pFilterEx07Xml ) ) - eFormat = Exp2007Xml; FltError eError = ScFormatFilter::Get().ScExportExcel5( rMed, &aDocument, eFormat, RTL_TEXTENCODING_MS_1252 ); if( eError && !GetError() ) diff --git a/sc/util/scfilt.map b/sc/util/scfilt.map index 642b8db15088..ea169e176103 100644 --- a/sc/util/scfilt.map +++ b/sc/util/scfilt.map @@ -1,6 +1,9 @@ UDK_3_0_0 { global: ScFilterCreate; + component_getImplementationEnvironment; + component_writeInfo; + component_getFactory; local: *; }; |