LibreOffice Module sc (master) 1
expop2.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 <unotools/fltrcfg.hxx>
21
22#include <osl/diagnose.h>
23#include <sfx2/objsh.hxx>
24#include <sfx2/docinf.hxx>
26
27#include <oox/ole/vbaexport.hxx>
28
29#include <scerrors.hxx>
30
31#include <root.hxx>
32#include <excdoc.hxx>
33#include <exp_op.hxx>
34
35#include <xehelper.hxx>
36
37#include <officecfg/Office/Calc.hxx>
38
39#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
40#include <com/sun/star/frame/XModel.hpp>
41
42namespace com::sun::star::document { class XDocumentProperties; }
43
44namespace {
45
46enum class VBAExportMode
47{
48 NONE,
49 REEXPORT_STREAM,
50 FULL_EXPORT
51};
52
53}
54
57 XclExpRoot( rExpData )
58{
59 // only need part of the Root data
61 pExcRoot->pER = this; // ExcRoot -> XclExpRoot
63 pExcDoc.reset( new ExcDocument( *this ) );
64}
65
67{
68}
69
71{
72 SfxObjectShell* pDocShell = GetDocShell();
73 OSL_ENSURE( pDocShell, "ExportBiff5::Write - no document shell" );
74
76 OSL_ENSURE( xRootStrg.is(), "ExportBiff5::Write - no root storage" );
77
78 VBAExportMode eVbaExportMode = VBAExportMode::NONE;
79 if( GetBiff() == EXC_BIFF8 )
80 {
81 if (officecfg::Office::Calc::Filter::Import::VBA::UseExport::get())
82 eVbaExportMode = VBAExportMode::FULL_EXPORT;
83 else
84 {
85 const SvtFilterOptions& rFilterOpt = SvtFilterOptions::Get();
86 if (rFilterOpt.IsLoadExcelBasicStorage())
87 eVbaExportMode = VBAExportMode::REEXPORT_STREAM;
88 }
89 }
90
91 if ( pDocShell && xRootStrg.is() && eVbaExportMode == VBAExportMode::FULL_EXPORT)
92 {
93 VbaExport aExport(pDocShell->GetModel());
94 if (aExport.containsVBAProject())
95 {
96 tools::SvRef<SotStorage> xVBARoot = xRootStrg->OpenSotStorage("_VBA_PROJECT_CUR");
97 aExport.exportVBA( xVBARoot.get() );
98 }
99 }
100 else if( pDocShell && xRootStrg.is() && eVbaExportMode == VBAExportMode::REEXPORT_STREAM )
101 {
102 SvxImportMSVBasic aBasicImport( *pDocShell, *xRootStrg );
103 const ErrCode nErr = aBasicImport.SaveOrDelMSVBAStorage( true, EXC_STORAGE_VBA_PROJECT );
104 if( nErr != ERRCODE_NONE )
105 pDocShell->SetError(nErr);
106 }
107
108 pExcDoc->ReadDoc(); // ScDoc -> ExcDoc
109 pExcDoc->Write( aOut ); // wechstreamen
110
111 if( pDocShell && xRootStrg.is() )
112 {
113 using namespace ::com::sun::star;
114 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
115 pDocShell->GetModel(), uno::UNO_QUERY_THROW);
116 uno::Reference<document::XDocumentProperties> xDocProps
117 = xDPS->getDocumentProperties();
118 if ( SvtFilterOptions::Get().IsEnableCalcPreview() )
119 {
120 std::shared_ptr<GDIMetaFile> xMetaFile =
121 pDocShell->GetPreviewMetaFile();
122 uno::Sequence<sal_Int8> metaFile(
123 sfx2::convertMetaFile(xMetaFile.get()));
124 sfx2::SaveOlePropertySet( xDocProps, xRootStrg.get(), &metaFile );
125 }
126 else
127 sfx2::SaveOlePropertySet( xDocProps, xRootStrg.get() );
128 }
129
130 const XclExpAddressConverter& rAddrConv = GetAddressConverter();
131 if( rAddrConv.IsRowTruncated() )
133 if( rAddrConv.IsColTruncated() )
135 if( rAddrConv.IsTabTruncated() )
137
138 return ERRCODE_NONE;
139}
140
142 ExportBiff5( rExpData, rStrm )
143{
145}
146
148{
149}
150/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ErrCode Write() override
Definition: expop2.cxx:70
RootData * pExcRoot
Definition: exp_op.hxx:47
virtual ~ExportBiff5() override
Definition: expop2.cxx:66
ExportBiff5(XclExpRootData &rExpData, SvStream &rStrm)
Definition: expop2.cxx:55
std::unique_ptr< ExcDocument > pExcDoc
Definition: exp_op.hxx:44
ExportBiff8(XclExpRootData &rExpData, SvStream &rStrm)
Definition: expop2.cxx:141
virtual ~ExportBiff8() override
Definition: expop2.cxx:147
SvStream & aOut
Definition: exp_op.hxx:33
void SetError(ErrCode rErr)
std::shared_ptr< GDIMetaFile > GetPreviewMetaFile(bool bFullContent=false) const
css::uno::Reference< css::frame::XModel3 > GetModel() const
bool IsLoadExcelBasicStorage() const
static SvtFilterOptions & Get()
ErrCode SaveOrDelMSVBAStorage(bool bSaveInto, const OUString &rStorageName)
bool containsVBAProject()
void exportVBA(SotStorage *pRootStorage)
bool IsRowTruncated() const
Returns whether the "some rows have been cut" warning box should be shown.
Definition: xladdress.hxx:148
bool IsColTruncated() const
Returns whether the "some columns have been cut" warning box should be shown.
Definition: xladdress.hxx:146
bool IsTabTruncated() const
Returns whether the "some sheets have been cut" warning box should be shown.
Definition: xladdress.hxx:150
Provides functions to convert Calc cell addresses to Excel cell addresses.
Definition: xehelper.hxx:82
Access to global data from other classes.
Definition: xeroot.hxx:113
XclExpAddressConverter & GetAddressConverter() const
Returns the address converter.
Definition: xeroot.cxx:82
SfxObjectShell * GetDocShell() const
Returns the object shell of the Calc document.
Definition: xlroot.cxx:291
const tools::SvRef< SotStorage > & GetRootStorage() const
Returns the OLE2 root storage of the imported/exported file.
Definition: xlroot.hxx:186
XclBiff GetBiff() const
Returns the current BIFF version of the importer/exporter.
Definition: xlroot.hxx:141
RootData & GetOldRoot() const
Returns old RootData struct.
Definition: xlroot.hxx:138
T * get() const
bool is() const
#define ERRCODE_NONE
@ Biff5
Definition: flttypes.hxx:28
@ Biff8
Definition: flttypes.hxx:29
NONE
void SvStream & rStrm
uno::Sequence< sal_Int8 > convertMetaFile(GDIMetaFile const *i_pThumb)
bool SaveOlePropertySet(const uno::Reference< document::XDocumentProperties > &i_xDocProps, SotStorage *i_pStorage, const uno::Sequence< sal_Int8 > *i_pThumb, const uno::Sequence< sal_Int8 > *i_pGuid, const uno::Sequence< sal_Int8 > *i_pHyperlinks)
#define SCWARN_EXPORT_MAXTAB
Definition: scerrors.hxx:74
#define SCWARN_EXPORT_MAXCOL
Definition: scerrors.hxx:73
#define SCWARN_EXPORT_MAXROW
Definition: scerrors.hxx:72
BiffTyp eDateiTyp
Definition: root.hxx:45
XclExpRoot * pER
Definition: root.hxx:60
Stores global buffers and data needed for Excel export filter.
Definition: xeroot.hxx:60
@ EXC_BIFF8
MS Excel 5.0, MS Excel 7.0 (95)
Definition: xlconst.hxx:35
constexpr OUStringLiteral EXC_STORAGE_VBA_PROJECT
Definition: xlconst.hxx:80