LibreOffice Module sc (master) 1
excelfilter.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <excelfilter.hxx>
21
22#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
23#include <osl/diagnose.h>
24#include <sal/log.hxx>
25
26#include <excelvbaproject.hxx>
27#include <stylesbuffer.hxx>
28#include <themebuffer.hxx>
29#include <workbookfragment.hxx>
30#include <xestream.hxx>
31
32#include <addressconverter.hxx>
33#include <document.hxx>
34#include <docsh.hxx>
35#include <scerrors.hxx>
37
38namespace oox::xls {
39
40using namespace ::com::sun::star::lang;
41using namespace ::com::sun::star::sheet;
42using namespace ::com::sun::star::uno;
43using namespace ::oox::core;
44
45using ::oox::drawingml::table::TableStyleListPtr;
46
47ExcelFilter::ExcelFilter( const Reference< XComponentContext >& rxContext ) :
48 XmlFilterBase( rxContext ),
49 mpBookGlob( nullptr )
50{
51}
52
54{
55 OSL_ENSURE( !mpBookGlob, "ExcelFilter::~ExcelFilter - workbook data not cleared" );
56}
57
59{
60 mpBookGlob = &rBookGlob;
61}
62
64{
65 OSL_ENSURE( mpBookGlob, "ExcelFilter::getWorkbookGlobals - missing workbook data" );
66 return *mpBookGlob;
67}
68
70{
71 mpBookGlob = nullptr;
72}
73
75{
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 );
81
82 OUString aWorkbookPath = getFragmentPathFromFirstTypeFromOfficeDoc( u"officeDocument" );
83 if( aWorkbookPath.isEmpty() )
84 return false;
85
86 try
87 {
88 try
89 {
91 }
92 catch( const Exception& )
93 {
94 TOOLS_WARN_EXCEPTION("sc", "exception when importing document properties");
95 }
96 catch( ... )
97 {
98 SAL_WARN("sc", "exception when importing document properties");
99 }
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. */
104 if (xBookGlob)
105 {
106 rtl::Reference<WorkbookFragment> xWorkbookFragment( new WorkbookFragment(*xBookGlob, aWorkbookPath));
107
108 ScDocument& rDoc = xWorkbookFragment->getScDocument();
109 ScDocShell* pDocSh = static_cast<ScDocShell*>(rDoc.GetDocumentShell());
110 assert( pDocSh );
111 pDocSh->SetInitialLinkUpdate( pDocSh->GetMedium());
112
113 bool bRet = importFragment( xWorkbookFragment);
114 if (bRet && !pDocSh->GetErrorCode())
115 {
116 const AddressConverter& rAC = xWorkbookFragment->getAddressConverter();
117 if (rAC.isTabOverflow())
119 else if (rAC.isColOverflow())
121 else if (rAC.isRowOverflow())
123 }
124 return bRet;
125 }
126 }
127 catch (...)
128 {
129 }
130
131 return false;
132}
133
135{
136 return false;
137}
138
139const ::oox::drawingml::Theme* ExcelFilter::getCurrentTheme() const
140{
142}
143
145{
146 return nullptr;
147}
148
150{
151 return TableStyleListPtr();
152}
153
155{
157}
158
160{
162}
163
165{
167}
168
170{
171 return new ExcelVbaProject( getComponentContext(), Reference< XSpreadsheetDocument >( getModel(), UNO_QUERY ) );
172}
173
174sal_Bool SAL_CALL ExcelFilter::filter( const css::uno::Sequence< css::beans::PropertyValue >& rDescriptor )
175{
176 if ( XmlFilterBase::filter( rDescriptor ) )
177 return true;
178
179 if ( isExportFilter() )
180 {
181 bool bExportVBA = exportVBA();
182 Reference< XExporter > xExporter(
183 new XclExpXmlStream( getComponentContext(), bExportVBA, isExportTemplate() ) );
184
185 Reference< XComponent > xDocument = getModel();
186 Reference< XFilter > xFilter( xExporter, UNO_QUERY );
187
188 if ( xFilter.is() )
189 {
190 xExporter->setSourceDocument( xDocument );
191 if ( xFilter->filter( rDescriptor ) )
192 return true;
193 }
194 }
195
196 return false;
197}
198
200{
201 return "com.sun.star.comp.oox.xls.ExcelFilter";
202}
203
204} // namespace oox::xls
205
206
207extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
209 css::uno::Sequence<css::uno::Any> const &)
210{
211 return cppu::acquire(new oox::xls::ExcelFilter(context));
212}
213
214
215/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetInitialLinkUpdate(const SfxMedium *pMedium)
Definition: docsh4.cxx:116
SfxObjectShell * GetDocumentShell() const
Definition: document.hxx:1081
void SetError(ErrCode rErr)
ErrCode GetErrorCode() const
SfxMedium * GetMedium() const
bool isExportFilter() const
bool exportVBA() const
const css::uno::Reference< css::frame::XModel > & getModel() const
bool isExportTemplate() const
const css::uno::Reference< css::uno::XComponentContext > & getComponentContext() const
OUString getFragmentPathFromFirstTypeFromOfficeDoc(std::u16string_view rPart)
bool importFragment(const rtl::Reference< FragmentHandler > &rxHandler)
Converter for cell addresses and cell ranges for OOXML and BIFF filters.
virtual bool exportDocument() noexcept override
virtual bool importDocument() override
Definition: excelfilter.cxx:74
virtual GraphicHelper * implCreateGraphicHelper() const override
virtual sal_Bool SAL_CALL filter(const css::uno::Sequence< css::beans::PropertyValue > &rDescriptor) override
virtual ::oox::vml::Drawing * getVmlDrawing() override
virtual OUString SAL_CALL getImplementationName() override
virtual const ::oox::drawingml::Theme * getCurrentTheme() const override
virtual void useInternalChartDataTable(bool bInternal) override
virtual ::oox::drawingml::table::TableStyleListPtr getTableStyles() override
virtual ~ExcelFilter() override
Definition: excelfilter.cxx:53
virtual ::oox::drawingml::chart::ChartConverter * getChartConverter() override
void registerWorkbookGlobals(WorkbookGlobals &rBookGlob)
Definition: excelfilter.cxx:58
virtual ::oox::ole::VbaProject * implCreateVbaProject() const override
WorkbookGlobals * mpBookGlob
Definition: excelfilter.hxx:56
ExcelFilter(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
Definition: excelfilter.cxx:47
WorkbookGlobals & getWorkbookGlobals() const
Definition: excelfilter.cxx:63
void unregisterWorkbookGlobals()
Definition: excelfilter.cxx:69
Relative character height if escaped.
Special implementation of the VBA project for the Excel filters.
Helper class to provide access to global workbook data.
void useInternalChartDataTable(bool bInternal)
oox::drawingml::chart::ChartConverter * getChartConverter() const
Returns the chart object converter.
static WorkbookGlobalsRef constructGlobals(ExcelFilter &rFilter)
ThemeBuffer & getTheme() const
Returns the office theme object read from the theme substorage.
#define TOOLS_WARN_EXCEPTION(area, stream)
float u
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_oox_xls_ExcelFilter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
#define SAL_WARN(area, stream)
@ Exception
std::shared_ptr< TableStyleList > TableStyleListPtr
std::shared_ptr< WorkbookGlobals > WorkbookGlobalsRef
#define SCWARN_IMPORT_ROW_OVERFLOW
Definition: scerrors.hxx:62
#define SCWARN_IMPORT_COLUMN_OVERFLOW
Definition: scerrors.hxx:63
#define SCWARN_IMPORT_SHEET_OVERFLOW
Definition: scerrors.hxx:64
unsigned char sal_Bool