LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sc / source / filter / excel / expop2.cxx
blobee8ba0fff2b954dc245ab9a95d4ef647b8427c74
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
31 #include <root.hxx>
32 #include <excdoc.hxx>
33 #include <exp_op.hxx>
35 #include <xehelper.hxx>
37 #include <officecfg/Office/Calc.hxx>
39 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
40 #include <com/sun/star/frame/XModel.hpp>
42 namespace com::sun::star::document { class XDocumentProperties; }
44 namespace {
46 enum class VBAExportMode
48 NONE,
49 REEXPORT_STREAM,
50 FULL_EXPORT
55 ExportBiff5::ExportBiff5( XclExpRootData& rExpData, SvStream& rStrm ):
56 ExportTyp( rStrm ),
57 XclExpRoot( rExpData )
59 // only need part of the Root data
60 pExcRoot = &GetOldRoot();
61 pExcRoot->pER = this; // ExcRoot -> XclExpRoot
62 pExcRoot->eDateiTyp = Biff5;
63 pExcDoc.reset( new ExcDocument( *this ) );
66 ExportBiff5::~ExportBiff5()
70 ErrCode ExportBiff5::Write()
72 SfxObjectShell* pDocShell = GetDocShell();
73 OSL_ENSURE( pDocShell, "ExportBiff5::Write - no document shell" );
75 tools::SvRef<SotStorage> xRootStrg = GetRootStorage();
76 OSL_ENSURE( xRootStrg.is(), "ExportBiff5::Write - no root storage" );
78 VBAExportMode eVbaExportMode = VBAExportMode::NONE;
79 if( GetBiff() == EXC_BIFF8 )
81 if (officecfg::Office::Calc::Filter::Import::VBA::UseExport::get())
82 eVbaExportMode = VBAExportMode::FULL_EXPORT;
83 else
85 const SvtFilterOptions& rFilterOpt = SvtFilterOptions::Get();
86 if (rFilterOpt.IsLoadExcelBasicStorage())
87 eVbaExportMode = VBAExportMode::REEXPORT_STREAM;
91 if ( pDocShell && xRootStrg.is() && eVbaExportMode == VBAExportMode::FULL_EXPORT)
93 VbaExport aExport(pDocShell->GetModel());
94 if (aExport.containsVBAProject())
96 tools::SvRef<SotStorage> xVBARoot = xRootStrg->OpenSotStorage("_VBA_PROJECT_CUR");
97 aExport.exportVBA( xVBARoot.get() );
100 else if( pDocShell && xRootStrg.is() && eVbaExportMode == VBAExportMode::REEXPORT_STREAM )
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);
108 pExcDoc->ReadDoc(); // ScDoc -> ExcDoc
109 pExcDoc->Write( aOut ); // wechstreamen
111 if( pDocShell && xRootStrg.is() )
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() )
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 );
126 else
127 sfx2::SaveOlePropertySet( xDocProps, xRootStrg.get() );
130 const XclExpAddressConverter& rAddrConv = GetAddressConverter();
131 if( rAddrConv.IsRowTruncated() )
132 return SCWARN_EXPORT_MAXROW;
133 if( rAddrConv.IsColTruncated() )
134 return SCWARN_EXPORT_MAXCOL;
135 if( rAddrConv.IsTabTruncated() )
136 return SCWARN_EXPORT_MAXTAB;
138 return ERRCODE_NONE;
141 ExportBiff8::ExportBiff8( XclExpRootData& rExpData, SvStream& rStrm ) :
142 ExportBiff5( rExpData, rStrm )
144 pExcRoot->eDateiTyp = Biff8;
147 ExportBiff8::~ExportBiff8()
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */