xref: /aoo41x/main/sc/source/filter/excel/expop2.cxx (revision b3f79822)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 
28 
29 //------------------------------------------------------------------------
30 
31 #include <unotools/fltrcfg.hxx>
32 
33 #include <sfx2/objsh.hxx>
34 #include <sfx2/docinf.hxx>
35 #include <filter/msfilter/svxmsbas.hxx>
36 
37 #include "scerrors.hxx"
38 #include "scextopt.hxx"
39 
40 #include "root.hxx"
41 #include "excdoc.hxx"
42 #include "exp_op.hxx"
43 
44 #include "xcl97esc.hxx"
45 
46 #include "document.hxx"
47 #include "rangenam.hxx"
48 #include "filtopt.hxx"
49 #include "xltools.hxx"
50 #include "xelink.hxx"
51 
52 #include <com/sun/star/document/XDocumentProperties.hpp>
53 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
54 
55 
ExportBiff5(XclExpRootData & rExpData,SvStream & rStrm)56 ExportBiff5::ExportBiff5( XclExpRootData& rExpData, SvStream& rStrm ):
57     ExportTyp( rStrm, &rExpData.mrDoc, rExpData.meTextEnc ),
58     XclExpRoot( rExpData )
59 {
60 	// nur Teil der Root-Daten gebraucht
61     pExcRoot = &GetOldRoot();
62     pExcRoot->pER = this;   // ExcRoot -> XclExpRoot
63 	pExcRoot->eDateiTyp = Biff5;
64     pExcDoc = new ExcDocument( *this );
65 }
66 
67 
~ExportBiff5()68 ExportBiff5::~ExportBiff5()
69 {
70 	delete pExcDoc;
71 }
72 
73 
Write()74 FltError ExportBiff5::Write()
75 {
76     SfxObjectShell* pDocShell = GetDocShell();
77     DBG_ASSERT( pDocShell, "ExportBiff5::Write - no document shell" );
78 
79     SotStorageRef xRootStrg = GetRootStorage();
80     DBG_ASSERT( xRootStrg.Is(), "ExportBiff5::Write - no root storage" );
81 
82     bool bWriteBasicCode = false;
83     bool bWriteBasicStrg = false;
84     if( GetBiff() == EXC_BIFF8 )
85 	{
86         if( SvtFilterOptions* pFilterOpt = SvtFilterOptions::Get() )
87         {
88             bWriteBasicCode = pFilterOpt->IsLoadExcelBasicCode();
89             bWriteBasicStrg = pFilterOpt->IsLoadExcelBasicStorage();
90         }
91 	}
92 
93     if( pDocShell && xRootStrg.Is() && bWriteBasicStrg )
94 	{
95         SvxImportMSVBasic aBasicImport( *pDocShell, *xRootStrg, bWriteBasicCode, bWriteBasicStrg );
96         sal_uLong nErr = aBasicImport.SaveOrDelMSVBAStorage( sal_True, EXC_STORAGE_VBA_PROJECT );
97 		if( nErr != ERRCODE_NONE )
98             pDocShell->SetError( nErr, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
99 	}
100 
101 	pExcDoc->ReadDoc();			// ScDoc -> ExcDoc
102 	pExcDoc->Write( aOut );		// wechstreamen
103 
104     if( pDocShell && xRootStrg.Is() )
105     {
106         // #i88642# update doc info (revision etc)
107         pDocShell->UpdateDocInfoForSave();
108 
109         using namespace ::com::sun::star;
110         uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
111                 pDocShell->GetModel(), uno::UNO_QUERY_THROW);
112         uno::Reference<document::XDocumentProperties> xDocProps
113                 = xDPS->getDocumentProperties();
114 		if ( SvtFilterOptions::Get()->IsEnableCalcPreview() )
115 		{
116 			::boost::shared_ptr<GDIMetaFile> pMetaFile =
117 				pDocShell->GetPreviewMetaFile (sal_False);
118 			uno::Sequence<sal_uInt8> metaFile(
119 				sfx2::convertMetaFile(pMetaFile.get()));
120 			sfx2::SaveOlePropertySet(xDocProps, xRootStrg, &metaFile);
121 		}
122 		else
123 			sfx2::SaveOlePropertySet(xDocProps, xRootStrg );
124     }
125 
126     //! TODO: separate warnings for columns and sheets
127     const XclExpAddressConverter& rAddrConv = GetAddressConverter();
128     if( rAddrConv.IsColTruncated() || rAddrConv.IsRowTruncated() || rAddrConv.IsTabTruncated() )
129 		return SCWARN_EXPORT_MAXROW;
130 
131     return eERR_OK;
132 }
133 
134 
135 
ExportBiff8(XclExpRootData & rExpData,SvStream & rStrm)136 ExportBiff8::ExportBiff8( XclExpRootData& rExpData, SvStream& rStrm ) :
137     ExportBiff5( rExpData, rStrm )
138 {
139 	pExcRoot->eDateiTyp = Biff8;
140 }
141 
142 
~ExportBiff8()143 ExportBiff8::~ExportBiff8()
144 {
145 }
146 
147 
ExportXml2007(XclExpRootData & rExpData,SvStream & rStrm)148 ExportXml2007::ExportXml2007( XclExpRootData& rExpData, SvStream& rStrm )
149     : ExportTyp( rStrm, &rExpData.mrDoc, rExpData.meTextEnc )
150     , XclExpRoot( rExpData )
151 {
152     pExcRoot = &GetOldRoot();
153     pExcRoot->pER = this;
154     pExcRoot->eDateiTyp = Biff8;
155     pExcDoc = new ExcDocument( *this );
156 }
157 
158 
~ExportXml2007()159 ExportXml2007::~ExportXml2007()
160 {
161     delete pExcDoc;
162 }
163 
164 
Write()165 FltError ExportXml2007::Write()
166 {
167     SfxObjectShell* pDocShell = GetDocShell();
168     DBG_ASSERT( pDocShell, "ExportXml2007::Write - no document shell" );
169 
170     SotStorageRef xRootStrg = GetRootStorage();
171     DBG_ASSERT( xRootStrg.Is(), "ExportXml2007::Write - no root storage" );
172 
173     bool bWriteBasicCode = false;
174     bool bWriteBasicStrg = false;
175 
176     if( SvtFilterOptions* pFilterOpt = SvtFilterOptions::Get() )
177     {
178         bWriteBasicCode = pFilterOpt->IsLoadExcelBasicCode();
179         bWriteBasicStrg = pFilterOpt->IsLoadExcelBasicStorage();
180     }
181 
182     if( pDocShell && xRootStrg.Is() && bWriteBasicStrg )
183     {
184         SvxImportMSVBasic aBasicImport( *pDocShell, *xRootStrg, bWriteBasicCode, bWriteBasicStrg );
185         sal_uLong nErr = aBasicImport.SaveOrDelMSVBAStorage( sal_True, EXC_STORAGE_VBA_PROJECT );
186         if( nErr != ERRCODE_NONE )
187             pDocShell->SetError( nErr, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
188     }
189 
190     pExcDoc->ReadDoc();         // ScDoc -> ExcDoc
191     pExcDoc->WriteXml( aOut );  // wechstreamen
192 
193     if( pDocShell && xRootStrg.Is() )
194     {
195         using namespace ::com::sun::star;
196         uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
197                 pDocShell->GetModel(), uno::UNO_QUERY_THROW);
198         uno::Reference<document::XDocumentProperties> xDocProps
199                 = xDPS->getDocumentProperties();
200         ::boost::shared_ptr<GDIMetaFile> pMetaFile =
201             pDocShell->GetPreviewMetaFile (sal_False);
202         uno::Sequence<sal_uInt8> metaFile(
203             sfx2::convertMetaFile(pMetaFile.get()));
204         sfx2::SaveOlePropertySet(xDocProps, xRootStrg, &metaFile);
205     }
206 
207     //! TODO: separate warnings for columns and sheets
208     const XclExpAddressConverter& rAddrConv = GetAddressConverter();
209     if( rAddrConv.IsColTruncated() || rAddrConv.IsRowTruncated() || rAddrConv.IsTabTruncated() )
210         return SCWARN_EXPORT_MAXROW;
211 
212     return eERR_OK;
213 }
214 
215 
216