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 <unotools/fltrcfg.hxx>
22 #include <osl/diagnose.h>
23 #include <sfx2/objsh.hxx>
24 #include <sfx2/docinf.hxx>
25 #include <filter/msfilter/svxmsbas.hxx>
27 #include <oox/ole/vbaexport.hxx>
29 #include <scerrors.hxx>
35 #include <xehelper.hxx>
37 #include <officecfg/Office/Calc.hxx>
39 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
41 namespace com
{ namespace sun
{ namespace star
{ namespace document
{ class XDocumentProperties
; } } } }
45 enum class VBAExportMode
54 ExportBiff5::ExportBiff5( XclExpRootData
& rExpData
, SvStream
& rStrm
):
56 XclExpRoot( rExpData
)
58 // only need part of the Root data
59 pExcRoot
= &GetOldRoot();
60 pExcRoot
->pER
= this; // ExcRoot -> XclExpRoot
61 pExcRoot
->eDateiTyp
= Biff5
;
62 pExcDoc
.reset( new ExcDocument( *this ) );
65 ExportBiff5::~ExportBiff5()
69 ErrCode
ExportBiff5::Write()
71 SfxObjectShell
* pDocShell
= GetDocShell();
72 OSL_ENSURE( pDocShell
, "ExportBiff5::Write - no document shell" );
74 tools::SvRef
<SotStorage
> xRootStrg
= GetRootStorage();
75 OSL_ENSURE( xRootStrg
.is(), "ExportBiff5::Write - no root storage" );
77 VBAExportMode eVbaExportMode
= VBAExportMode::NONE
;
78 if( GetBiff() == EXC_BIFF8
)
80 if (officecfg::Office::Calc::Filter::Import::VBA::UseExport::get())
81 eVbaExportMode
= VBAExportMode::FULL_EXPORT
;
84 const SvtFilterOptions
& rFilterOpt
= SvtFilterOptions::Get();
85 if (rFilterOpt
.IsLoadExcelBasicStorage())
86 eVbaExportMode
= VBAExportMode::REEXPORT_STREAM
;
90 if ( pDocShell
&& xRootStrg
.is() && eVbaExportMode
== VBAExportMode::FULL_EXPORT
)
92 VbaExport
aExport(pDocShell
->GetModel());
93 if (aExport
.containsVBAProject())
95 tools::SvRef
<SotStorage
> xVBARoot
= xRootStrg
->OpenSotStorage("_VBA_PROJECT_CUR");
96 aExport
.exportVBA( xVBARoot
.get() );
99 else if( pDocShell
&& xRootStrg
.is() && eVbaExportMode
== VBAExportMode::REEXPORT_STREAM
)
101 SvxImportMSVBasic
aBasicImport( *pDocShell
, *xRootStrg
);
102 const ErrCode nErr
= aBasicImport
.SaveOrDelMSVBAStorage( true, EXC_STORAGE_VBA_PROJECT
);
103 if( nErr
!= ERRCODE_NONE
)
104 pDocShell
->SetError(nErr
);
107 pExcDoc
->ReadDoc(); // ScDoc -> ExcDoc
108 pExcDoc
->Write( aOut
); // wechstreamen
110 if( pDocShell
&& xRootStrg
.is() )
112 using namespace ::com::sun::star
;
113 uno::Reference
<document::XDocumentPropertiesSupplier
> xDPS(
114 pDocShell
->GetModel(), uno::UNO_QUERY_THROW
);
115 uno::Reference
<document::XDocumentProperties
> xDocProps
116 = xDPS
->getDocumentProperties();
117 if ( SvtFilterOptions::Get().IsEnableCalcPreview() )
119 std::shared_ptr
<GDIMetaFile
> xMetaFile
=
120 pDocShell
->GetPreviewMetaFile();
121 uno::Sequence
<sal_Int8
> metaFile(
122 sfx2::convertMetaFile(xMetaFile
.get()));
123 sfx2::SaveOlePropertySet( xDocProps
, xRootStrg
.get(), &metaFile
);
126 sfx2::SaveOlePropertySet( xDocProps
, xRootStrg
.get() );
129 const XclExpAddressConverter
& rAddrConv
= GetAddressConverter();
130 if( rAddrConv
.IsRowTruncated() )
131 return SCWARN_EXPORT_MAXROW
;
132 if( rAddrConv
.IsColTruncated() )
133 return SCWARN_EXPORT_MAXCOL
;
134 if( rAddrConv
.IsTabTruncated() )
135 return SCWARN_EXPORT_MAXTAB
;
140 ExportBiff8::ExportBiff8( XclExpRootData
& rExpData
, SvStream
& rStrm
) :
141 ExportBiff5( rExpData
, rStrm
)
143 pExcRoot
->eDateiTyp
= Biff8
;
146 ExportBiff8::~ExportBiff8()
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */