1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: expop2.cxx,v $
10 * $Revision: 1.35.14.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 //------------------------------------------------------------------------
38 #include <svtools/fltrcfg.hxx>
40 #include <sfx2/objsh.hxx>
41 #include <sfx2/docinf.hxx>
42 #include <svx/svxmsbas.hxx>
44 #include "scerrors.hxx"
45 #include "scextopt.hxx"
51 #include "xcl97esc.hxx"
53 #include "document.hxx"
54 #include "rangenam.hxx"
55 #include "filtopt.hxx"
56 #include "xltools.hxx"
59 #include <com/sun/star/document/XDocumentProperties.hpp>
60 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
63 ExportBiff5::ExportBiff5( XclExpRootData
& rExpData
, SvStream
& rStrm
):
64 ExportTyp( rStrm
, &rExpData
.mrDoc
, rExpData
.meTextEnc
),
65 XclExpRoot( rExpData
)
67 // nur Teil der Root-Daten gebraucht
68 pExcRoot
= &GetOldRoot();
69 pExcRoot
->pER
= this; // ExcRoot -> XclExpRoot
70 pExcRoot
->eDateiTyp
= Biff5
;
71 pExcDoc
= new ExcDocument( *this );
75 ExportBiff5::~ExportBiff5()
81 FltError
ExportBiff5::Write()
83 SfxObjectShell
* pDocShell
= GetDocShell();
84 DBG_ASSERT( pDocShell
, "ExportBiff5::Write - no document shell" );
86 SotStorageRef xRootStrg
= GetRootStorage();
87 DBG_ASSERT( xRootStrg
.Is(), "ExportBiff5::Write - no root storage" );
89 bool bWriteBasicCode
= false;
90 bool bWriteBasicStrg
= false;
91 if( GetBiff() == EXC_BIFF8
)
93 if( SvtFilterOptions
* pFilterOpt
= SvtFilterOptions::Get() )
95 bWriteBasicCode
= pFilterOpt
->IsLoadExcelBasicCode();
96 bWriteBasicStrg
= pFilterOpt
->IsLoadExcelBasicStorage();
100 if( pDocShell
&& xRootStrg
.Is() && bWriteBasicStrg
)
102 SvxImportMSVBasic
aBasicImport( *pDocShell
, *xRootStrg
, bWriteBasicCode
, bWriteBasicStrg
);
103 ULONG nErr
= aBasicImport
.SaveOrDelMSVBAStorage( TRUE
, EXC_STORAGE_VBA_PROJECT
);
104 if( nErr
!= ERRCODE_NONE
)
105 pDocShell
->SetError( nErr
, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
) ) );
108 pExcDoc
->ReadDoc(); // ScDoc -> ExcDoc
109 pExcDoc
->Write( aOut
); // wechstreamen
111 if( pDocShell
&& xRootStrg
.Is() )
113 // #i88642# update doc info (revision etc)
114 pDocShell
->UpdateDocInfoForSave();
116 using namespace ::com::sun::star
;
117 uno::Reference
<document::XDocumentPropertiesSupplier
> xDPS(
118 pDocShell
->GetModel(), uno::UNO_QUERY_THROW
);
119 uno::Reference
<document::XDocumentProperties
> xDocProps
120 = xDPS
->getDocumentProperties();
121 if ( SvtFilterOptions::Get()->IsEnableCalcPreview() )
123 ::boost::shared_ptr
<GDIMetaFile
> pMetaFile
=
124 pDocShell
->GetPreviewMetaFile (sal_False
);
125 uno::Sequence
<sal_uInt8
> metaFile(
126 sfx2::convertMetaFile(pMetaFile
.get()));
127 sfx2::SaveOlePropertySet(xDocProps
, xRootStrg
, &metaFile
);
130 sfx2::SaveOlePropertySet(xDocProps
, xRootStrg
);
133 //! TODO: separate warnings for columns and sheets
134 const XclExpAddressConverter
& rAddrConv
= GetAddressConverter();
135 if( rAddrConv
.IsColTruncated() || rAddrConv
.IsRowTruncated() || rAddrConv
.IsTabTruncated() )
136 return SCWARN_EXPORT_MAXROW
;
143 ExportBiff8::ExportBiff8( XclExpRootData
& rExpData
, SvStream
& rStrm
) :
144 ExportBiff5( rExpData
, rStrm
)
146 pExcRoot
->eDateiTyp
= Biff8
;
147 pExcRoot
->pEscher
= new XclEscher( GetRoot(), GetDoc().GetTableCount() );
151 ExportBiff8::~ExportBiff8()
153 delete pExcRoot
->pEscher
;
154 pExcRoot
->pEscher
= NULL
;
158 ExportXml2007::ExportXml2007( XclExpRootData
& rExpData
, SvStream
& rStrm
)
159 : ExportTyp( rStrm
, &rExpData
.mrDoc
, rExpData
.meTextEnc
)
160 , XclExpRoot( rExpData
)
162 pExcRoot
= &GetOldRoot();
163 pExcRoot
->pER
= this;
164 pExcRoot
->eDateiTyp
= Biff8
;
165 pExcRoot
->pEscher
= new XclEscher( *pExcRoot
->pER
, GetDoc().GetTableCount() );
166 pExcDoc
= new ExcDocument( *this );
170 ExportXml2007::~ExportXml2007()
172 delete pExcRoot
->pEscher
;
173 pExcRoot
->pEscher
= NULL
;
179 FltError
ExportXml2007::Write()
181 SfxObjectShell
* pDocShell
= GetDocShell();
182 DBG_ASSERT( pDocShell
, "ExportXml2007::Write - no document shell" );
184 SotStorageRef xRootStrg
= GetRootStorage();
185 DBG_ASSERT( xRootStrg
.Is(), "ExportXml2007::Write - no root storage" );
187 bool bWriteBasicCode
= false;
188 bool bWriteBasicStrg
= false;
190 if( SvtFilterOptions
* pFilterOpt
= SvtFilterOptions::Get() )
192 bWriteBasicCode
= pFilterOpt
->IsLoadExcelBasicCode();
193 bWriteBasicStrg
= pFilterOpt
->IsLoadExcelBasicStorage();
196 if( pDocShell
&& xRootStrg
.Is() && bWriteBasicStrg
)
198 SvxImportMSVBasic
aBasicImport( *pDocShell
, *xRootStrg
, bWriteBasicCode
, bWriteBasicStrg
);
199 ULONG nErr
= aBasicImport
.SaveOrDelMSVBAStorage( TRUE
, EXC_STORAGE_VBA_PROJECT
);
200 if( nErr
!= ERRCODE_NONE
)
201 pDocShell
->SetError( nErr
, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
) ) );
204 pExcDoc
->ReadDoc(); // ScDoc -> ExcDoc
205 pExcDoc
->WriteXml( aOut
); // wechstreamen
207 if( pDocShell
&& xRootStrg
.Is() )
209 using namespace ::com::sun::star
;
210 uno::Reference
<document::XDocumentPropertiesSupplier
> xDPS(
211 pDocShell
->GetModel(), uno::UNO_QUERY_THROW
);
212 uno::Reference
<document::XDocumentProperties
> xDocProps
213 = xDPS
->getDocumentProperties();
214 ::boost::shared_ptr
<GDIMetaFile
> pMetaFile
=
215 pDocShell
->GetPreviewMetaFile (sal_False
);
216 uno::Sequence
<sal_uInt8
> metaFile(
217 sfx2::convertMetaFile(pMetaFile
.get()));
218 sfx2::SaveOlePropertySet(xDocProps
, xRootStrg
, &metaFile
);
221 //! TODO: separate warnings for columns and sheets
222 const XclExpAddressConverter
& rAddrConv
= GetAddressConverter();
223 if( rAddrConv
.IsColTruncated() || rAddrConv
.IsRowTruncated() || rAddrConv
.IsTabTruncated() )
224 return SCWARN_EXPORT_MAXROW
;