1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: excelfilter.cxx,v $
10 * $Revision: 1.6.6.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "oox/xls/excelfilter.hxx"
32 #include "oox/helper/binaryinputstream.hxx"
33 #include "oox/xls/biffdetector.hxx"
34 #include "oox/xls/biffinputstream.hxx"
35 #include "oox/xls/excelchartconverter.hxx"
36 #include "oox/xls/themebuffer.hxx"
37 #include "oox/xls/workbookfragment.hxx"
38 #include "oox/dump/biffdumper.hxx"
39 #include "oox/dump/xlsbdumper.hxx"
41 using ::rtl::OUString
;
42 using ::com::sun::star::uno::Any
;
43 using ::com::sun::star::uno::Reference
;
44 using ::com::sun::star::uno::Sequence
;
45 using ::com::sun::star::uno::Exception
;
46 using ::com::sun::star::uno::XInterface
;
47 using ::com::sun::star::lang::XMultiServiceFactory
;
48 using ::com::sun::star::xml::sax::XFastDocumentHandler
;
49 using ::oox::core::BinaryFilterBase
;
50 using ::oox::core::FragmentHandlerRef
;
51 using ::oox::core::Relation
;
52 using ::oox::core::Relations
;
53 using ::oox::core::XmlFilterBase
;
54 using ::oox::drawingml::table::TableStyleListPtr
;
59 // ============================================================================
61 ExcelFilterBase::ExcelFilterBase() :
66 ExcelFilterBase::~ExcelFilterBase()
68 OSL_ENSURE( !mpHelper
, "ExcelFilterBase::~ExcelFilterBase - workbook helper not cleared" );
71 void ExcelFilterBase::setWorkbookHelper( WorkbookHelper
& rHelper
)
76 WorkbookHelper
& ExcelFilterBase::getWorkbookHelper() const
78 OSL_ENSURE( mpHelper
, "ExcelFilterBase::getWorkbookHelper - missing workbook helper" );
82 void ExcelFilterBase::clearWorkbookHelper()
87 // ============================================================================
89 OUString SAL_CALL
ExcelFilter_getImplementationName() throw()
91 return CREATE_OUSTRING( "com.sun.star.comp.oox.ExcelFilter" );
94 Sequence
< OUString
> SAL_CALL
ExcelFilter_getSupportedServiceNames() throw()
96 OUString aServiceName
= CREATE_OUSTRING( "com.sun.star.comp.oox.ExcelFilter" );
97 Sequence
< OUString
> aSeq( &aServiceName
, 1 );
101 Reference
< XInterface
> SAL_CALL
ExcelFilter_createInstance(
102 const Reference
< XMultiServiceFactory
>& rxGlobalFactory
) throw( Exception
)
104 return static_cast< ::cppu::OWeakObject
* >( new ExcelFilter( rxGlobalFactory
) );
107 // ----------------------------------------------------------------------------
109 ExcelFilter::ExcelFilter( const Reference
< XMultiServiceFactory
>& rxGlobalFactory
) :
110 XmlFilterBase( rxGlobalFactory
)
114 ExcelFilter::~ExcelFilter()
118 bool ExcelFilter::importDocument() throw()
120 /* to activate the XLSX/XLSB dumper, define the environment variable
121 OOO_XLSBDUMPER and insert the full path to the file
122 file:///<path-to-oox-module>/source/dump/xlsbdumper.ini. */
123 OOX_DUMP_FILE( ::oox::dump::xlsb::Dumper
);
126 OUString aWorkbookPath
= getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATIONSTYPE( "officeDocument" ) );
127 if( aWorkbookPath
.getLength() > 0 )
129 WorkbookHelperRoot
aHelper( *this );
130 if( aHelper
.isValid() )
132 setWorkbookHelper( aHelper
); // needed for callbacks
133 bRet
= importFragment( new OoxWorkbookFragment( aHelper
, aWorkbookPath
) );
134 clearWorkbookHelper();
140 bool ExcelFilter::exportDocument() throw()
145 sal_Int32
ExcelFilter::getSchemeColor( sal_Int32 nToken
) const
147 return getWorkbookHelper().getTheme().getColorByToken( nToken
);
150 sal_Int32
ExcelFilter::getPaletteColor( sal_Int32 nPaletteIdx
) const
152 return getWorkbookHelper().getStyles().getPaletteColor( nPaletteIdx
);
155 const ::oox::drawingml::Theme
* ExcelFilter::getCurrentTheme() const
157 return &getWorkbookHelper().getTheme();
160 ::oox::vml::Drawing
* ExcelFilter::getVmlDrawing()
165 const TableStyleListPtr
ExcelFilter::getTableStyles()
167 return TableStyleListPtr();
170 ::oox::drawingml::chart::ChartConverter
& ExcelFilter::getChartConverter()
172 return getWorkbookHelper().getChartConverter();
175 OUString
ExcelFilter::implGetImplementationName() const
177 return ExcelFilter_getImplementationName();
180 // ============================================================================
182 OUString SAL_CALL
ExcelBiffFilter_getImplementationName() throw()
184 return CREATE_OUSTRING( "com.sun.star.comp.oox.ExcelBiffFilter" );
187 Sequence
< OUString
> SAL_CALL
ExcelBiffFilter_getSupportedServiceNames() throw()
189 OUString aServiceName
= CREATE_OUSTRING( "com.sun.star.comp.oox.ExcelBiffFilter" );
190 Sequence
< OUString
> aSeq( &aServiceName
, 1 );
194 Reference
< XInterface
> SAL_CALL
ExcelBiffFilter_createInstance(
195 const Reference
< XMultiServiceFactory
>& rxGlobalFactory
) throw( Exception
)
197 return static_cast< ::cppu::OWeakObject
* >( new ExcelBiffFilter( rxGlobalFactory
) );
200 // ----------------------------------------------------------------------------
202 ExcelBiffFilter::ExcelBiffFilter( const Reference
< XMultiServiceFactory
>& rxGlobalFactory
) :
203 BinaryFilterBase( rxGlobalFactory
)
207 ExcelBiffFilter::~ExcelBiffFilter()
211 bool ExcelBiffFilter::importDocument() throw()
213 /* to activate the BIFF dumper, define the environment variable
214 OOO_BIFFDUMPER and insert the full path to the file
215 file:///<path-to-oox-module>/source/dump/biffdumper.ini. */
216 OOX_DUMP_FILE( ::oox::dump::biff::Dumper
);
218 /* The boolean argument "UseBiffFilter" passed through XInitialisation
219 decides whether to use the BIFF file dumper implemented in this filter
220 only (false or missing), or to import/export the document (true). */
221 Any aUseBiffFilter
= getArgument( CREATE_OUSTRING( "UseBiffFilter" ) );
222 bool bUseBiffFilter
= false;
223 if( !(aUseBiffFilter
>>= bUseBiffFilter
) || !bUseBiffFilter
)
228 // detect BIFF version and workbook stream name
229 OUString aWorkbookName
;
230 BiffType eBiff
= BiffDetector::detectStorageBiffVersion( aWorkbookName
, getStorage() );
231 OSL_ENSURE( eBiff
!= BIFF_UNKNOWN
, "ExcelBiffFilter::ExcelBiffFilter - invalid file format" );
232 if( eBiff
!= BIFF_UNKNOWN
)
234 WorkbookHelperRoot
aHelper( *this, eBiff
);
235 if( aHelper
.isValid() )
237 setWorkbookHelper( aHelper
); // needed for callbacks
238 bRet
= BiffWorkbookFragment( aHelper
, aWorkbookName
).importFragment();
239 clearWorkbookHelper();
245 bool ExcelBiffFilter::exportDocument() throw()
250 sal_Int32
ExcelBiffFilter::getPaletteColor( sal_Int32 nPaletteIdx
) const
252 return getWorkbookHelper().getStyles().getPaletteColor( nPaletteIdx
);
255 OUString
ExcelBiffFilter::implGetImplementationName() const
257 return ExcelBiffFilter_getImplementationName();
260 // ============================================================================