1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "excelfilter.hxx"
22 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
23 #include <osl/diagnose.h>
25 #include <oox/helper/binaryinputstream.hxx>
26 #include "biffinputstream.hxx"
27 #include "excelchartconverter.hxx"
28 #include "excelvbaproject.hxx"
29 #include "stylesbuffer.hxx"
30 #include "themebuffer.hxx"
31 #include "workbookfragment.hxx"
32 #include "xestream.hxx"
37 using namespace ::com::sun::star::lang
;
38 using namespace ::com::sun::star::sheet
;
39 using namespace ::com::sun::star::uno
;
40 using namespace ::com::sun::star::xml::sax
;
41 using namespace ::oox::core
;
43 using ::oox::drawingml::table::TableStyleListPtr
;
45 ExcelFilter::ExcelFilter( const Reference
< XComponentContext
>& rxContext
) throw( RuntimeException
) :
46 XmlFilterBase( rxContext
),
51 ExcelFilter::~ExcelFilter()
53 OSL_ENSURE( !mpBookGlob
, "ExcelFilter::~ExcelFilter - workbook data not cleared" );
56 void ExcelFilter::registerWorkbookGlobals( WorkbookGlobals
& rBookGlob
)
58 mpBookGlob
= &rBookGlob
;
61 WorkbookGlobals
& ExcelFilter::getWorkbookGlobals() const
63 OSL_ENSURE( mpBookGlob
, "ExcelFilter::getWorkbookGlobals - missing workbook data" );
67 void ExcelFilter::unregisterWorkbookGlobals()
72 bool ExcelFilter::importDocument()
74 /* To activate the XLSX/XLSB dumper, insert the full path to the file
75 file:///<path-to-oox-module>/source/dump/xlsbdumper.ini
76 into the environment variable OOO_XLSBDUMPER and start the office with
77 this variable (nonpro only). */
78 //OOX_DUMP_FILE( ::oox::dump::xlsb::Dumper );
80 OUString aWorkbookPath
= getFragmentPathFromFirstTypeFromOfficeDoc( "officeDocument" );
81 if( aWorkbookPath
.isEmpty() )
88 importDocumentProperties();
90 catch( const Exception
& e
)
92 SAL_WARN("sc", "exception when importing document properties " << e
.Message
);
96 SAL_WARN("sc", "exception when importing document properties");
98 /* Construct the WorkbookGlobals object referred to by every instance of
99 the class WorkbookHelper, and execute the import filter by constructing
100 an instance of WorkbookFragment and loading the file. */
101 WorkbookGlobalsRef
xBookGlob(WorkbookHelper::constructGlobals(*this));
102 if (xBookGlob
.get() && importFragment(new WorkbookFragment(*xBookGlob
, aWorkbookPath
)))
114 bool ExcelFilter::exportDocument() throw()
119 const ::oox::drawingml::Theme
* ExcelFilter::getCurrentTheme() const
121 return &WorkbookHelper( getWorkbookGlobals() ).getTheme();
124 ::oox::vml::Drawing
* ExcelFilter::getVmlDrawing()
129 const TableStyleListPtr
ExcelFilter::getTableStyles()
131 return TableStyleListPtr();
134 ::oox::drawingml::chart::ChartConverter
* ExcelFilter::getChartConverter()
136 return WorkbookHelper( getWorkbookGlobals() ).getChartConverter();
139 void ExcelFilter::useInternalChartDataTable( bool bInternal
)
141 return WorkbookHelper( getWorkbookGlobals() ).useInternalChartDataTable( bInternal
);
144 GraphicHelper
* ExcelFilter::implCreateGraphicHelper() const
146 return new ExcelGraphicHelper( getWorkbookGlobals() );
149 ::oox::ole::VbaProject
* ExcelFilter::implCreateVbaProject() const
151 return new ExcelVbaProject( getComponentContext(), Reference
< XSpreadsheetDocument
>( getModel(), UNO_QUERY
) );
154 sal_Bool SAL_CALL
ExcelFilter::filter( const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& rDescriptor
) throw( ::com::sun::star::uno::RuntimeException
, std::exception
)
156 if ( XmlFilterBase::filter( rDescriptor
) )
159 if ( isExportFilter() )
161 Reference
< XExporter
> xExporter(
162 new XclExpXmlStream( getComponentContext() ) );
164 Reference
< XComponent
> xDocument( getModel(), UNO_QUERY
);
165 Reference
< XFilter
> xFilter( xExporter
, UNO_QUERY
);
169 xExporter
->setSourceDocument( xDocument
);
170 if ( xFilter
->filter( rDescriptor
) )
178 OUString
ExcelFilter::getImplementationName() throw (css::uno::RuntimeException
, std::exception
)
180 return OUString( "com.sun.star.comp.oox.xls.ExcelFilter" );
187 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface
* SAL_CALL
188 com_sun_star_comp_oox_xls_ExcelFilter_get_implementation(::com::sun::star::uno::XComponentContext
* context
,
189 ::com::sun::star::uno::Sequence
<css::uno::Any
> const &)
191 return cppu::acquire(new oox::xls::ExcelFilter(context
));
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */