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>
24 #include <sal/log.hxx>
26 #include <excelvbaproject.hxx>
27 #include <stylesbuffer.hxx>
28 #include <themebuffer.hxx>
29 #include <workbookfragment.hxx>
30 #include <xestream.hxx>
32 #include <addressconverter.hxx>
33 #include <document.hxx>
35 #include <scerrors.hxx>
36 #include <comphelper/diagnose_ex.hxx>
40 using namespace ::com::sun::star::lang
;
41 using namespace ::com::sun::star::sheet
;
42 using namespace ::com::sun::star::uno
;
43 using namespace ::oox::core
;
45 using ::oox::drawingml::table::TableStyleListPtr
;
47 ExcelFilter::ExcelFilter( const Reference
< XComponentContext
>& rxContext
) :
48 XmlFilterBase( rxContext
),
53 ExcelFilter::~ExcelFilter()
55 OSL_ENSURE( !mpBookGlob
, "ExcelFilter::~ExcelFilter - workbook data not cleared" );
58 void ExcelFilter::registerWorkbookGlobals( WorkbookGlobals
& rBookGlob
)
60 mpBookGlob
= &rBookGlob
;
63 WorkbookGlobals
& ExcelFilter::getWorkbookGlobals() const
65 OSL_ENSURE( mpBookGlob
, "ExcelFilter::getWorkbookGlobals - missing workbook data" );
69 void ExcelFilter::unregisterWorkbookGlobals()
74 bool ExcelFilter::importDocument()
76 /* To activate the XLSX/XLSB dumper, insert the full path to the file
77 file:///<path-to-oox-module>/source/dump/xlsbdumper.ini
78 into the environment variable OOO_XLSBDUMPER and start the office with
79 this variable (nonpro only). */
80 //OOX_DUMP_FILE( ::oox::dump::xlsb::Dumper );
82 OUString aWorkbookPath
= getFragmentPathFromFirstTypeFromOfficeDoc( u
"officeDocument" );
83 if( aWorkbookPath
.isEmpty() )
90 importDocumentProperties();
92 catch( const Exception
& )
94 TOOLS_WARN_EXCEPTION("sc", "exception when importing document properties");
98 SAL_WARN("sc", "exception when importing document properties");
100 /* Construct the WorkbookGlobals object referred to by every instance of
101 the class WorkbookHelper, and execute the import filter by constructing
102 an instance of WorkbookFragment and loading the file. */
103 WorkbookGlobalsRef
xBookGlob(WorkbookHelper::constructGlobals(*this));
106 rtl::Reference
<WorkbookFragment
> xWorkbookFragment( new WorkbookFragment(*xBookGlob
, aWorkbookPath
));
108 ScDocument
& rDoc
= xWorkbookFragment
->getScDocument();
109 ScDocShell
* pDocSh
= rDoc
.GetDocumentShell();
111 pDocSh
->SetInitialLinkUpdate( pDocSh
->GetMedium());
113 bool bRet
= importFragment( xWorkbookFragment
);
114 if (bRet
&& !pDocSh
->GetErrorCode())
116 const AddressConverter
& rAC
= xWorkbookFragment
->getAddressConverter();
117 if (rAC
.isTabOverflow())
118 pDocSh
->SetError(SCWARN_IMPORT_SHEET_OVERFLOW
);
119 else if (rAC
.isColOverflow())
120 pDocSh
->SetError(SCWARN_IMPORT_COLUMN_OVERFLOW
);
121 else if (rAC
.isRowOverflow())
122 pDocSh
->SetError(SCWARN_IMPORT_ROW_OVERFLOW
);
134 bool ExcelFilter::exportDocument() noexcept
139 const ::oox::drawingml::Theme
* ExcelFilter::getCurrentTheme() const
141 return &WorkbookHelper( getWorkbookGlobals() ).getTheme();
144 ::oox::vml::Drawing
* ExcelFilter::getVmlDrawing()
149 TableStyleListPtr
ExcelFilter::getTableStyles()
151 return TableStyleListPtr();
154 ::oox::drawingml::chart::ChartConverter
* ExcelFilter::getChartConverter()
156 return WorkbookHelper( getWorkbookGlobals() ).getChartConverter();
159 void ExcelFilter::useInternalChartDataTable( bool bInternal
)
161 return WorkbookHelper( getWorkbookGlobals() ).useInternalChartDataTable( bInternal
);
164 GraphicHelper
* ExcelFilter::implCreateGraphicHelper() const
166 return new ExcelGraphicHelper( getWorkbookGlobals() );
169 ::oox::ole::VbaProject
* ExcelFilter::implCreateVbaProject() const
171 return new ExcelVbaProject( getComponentContext(), Reference
< XSpreadsheetDocument
>( getModel(), UNO_QUERY
) );
174 sal_Bool SAL_CALL
ExcelFilter::filter( const css::uno::Sequence
< css::beans::PropertyValue
>& rDescriptor
)
176 if ( XmlFilterBase::filter( rDescriptor
) )
179 if ( isExportFilter() )
181 bool bExportVBA
= exportVBA();
182 Reference
< XExporter
> xExporter(
183 new XclExpXmlStream( getComponentContext(), bExportVBA
, isExportTemplate() ) );
185 Reference
< XComponent
> xDocument
= getModel();
186 Reference
< XFilter
> xFilter( xExporter
, UNO_QUERY
);
190 xExporter
->setSourceDocument( xDocument
);
191 if ( xFilter
->filter( rDescriptor
) )
199 OUString
ExcelFilter::getImplementationName()
201 return u
"com.sun.star.comp.oox.xls.ExcelFilter"_ustr
;
204 } // namespace oox::xls
207 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
208 com_sun_star_comp_oox_xls_ExcelFilter_get_implementation(css::uno::XComponentContext
* context
,
209 css::uno::Sequence
<css::uno::Any
> const &)
211 return cppu::acquire(new oox::xls::ExcelFilter(context
));
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */