LibreOffice Module sc (master)  1
xiroot.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 <xiroot.hxx>
21 #include <addincol.hxx>
22 #include <colrowst.hxx>
23 #include <document.hxx>
24 #include <formel.hxx>
25 #include <scextopt.hxx>
26 #include <xihelper.hxx>
27 #include <xiformula.hxx>
28 #include <xilink.hxx>
29 #include <xiname.hxx>
30 #include <xistyle.hxx>
31 #include <xicontent.hxx>
32 #include <xiescher.hxx>
33 #include <xipivot.hxx>
34 #include <xipage.hxx>
35 #include <xiview.hxx>
36 
37 #include <root.hxx>
38 #include <excimp8.hxx>
39 #include <documentimport.hxx>
40 
41 // Global data ================================================================
42 
44  const tools::SvRef<SotStorage>& xRootStrg, ScDocument& rDoc, rtl_TextEncoding eTextEnc ) :
45  XclRootData( eBiff, rMedium, xRootStrg, rDoc, eTextEnc, false ),
46  mxDocImport(std::make_shared<ScDocumentImport>(rDoc)),
47  mbHasCodePage( false ),
48  mbHasBasic( false )
49 {
50 }
51 
53 {
54 }
55 
57  XclRoot( rImpRootData ),
58  mrImpData( rImpRootData )
59 {
60  mrImpData.mxAddrConv = std::make_shared<XclImpAddressConverter>( GetRoot() );
61  mrImpData.mxFmlaComp = std::make_shared<XclImpFormulaCompiler>( GetRoot() );
62  mrImpData.mxPalette = std::make_shared<XclImpPalette>( GetRoot() );
63  mrImpData.mxFontBfr = std::make_shared<XclImpFontBuffer>( GetRoot() );
64  mrImpData.mxNumFmtBfr = std::make_shared<XclImpNumFmtBuffer>( GetRoot() );
65  mrImpData.mpXFBfr = std::make_shared<XclImpXFBuffer>( GetRoot() );
66  mrImpData.mxXFRangeBfr = std::make_shared<XclImpXFRangeBuffer>( GetRoot() );
67  mrImpData.mxTabInfo = std::make_shared<XclImpTabInfo>();
68  mrImpData.mxNameMgr = std::make_shared<XclImpNameManager>( GetRoot() );
69  mrImpData.mxObjMgr = std::make_shared<XclImpObjectManager>( GetRoot() );
70 
71  if( GetBiff() == EXC_BIFF8 )
72  {
73  mrImpData.mxLinkMgr = std::make_shared<XclImpLinkManager>( GetRoot() );
74  mrImpData.mxSst = std::make_shared<XclImpSst>( GetRoot() );
75  mrImpData.mxCondFmtMgr = std::make_shared<XclImpCondFormatManager>( GetRoot() );
76  mrImpData.mxValidMgr = std::make_shared<XclImpValidationManager>( GetRoot() );
77  // TODO still in old RootData (deleted by RootData)
79  mrImpData.mxWebQueryBfr = std::make_shared<XclImpWebQueryBuffer>( GetRoot() );
80  mrImpData.mxPTableMgr = std::make_shared<XclImpPivotTableManager>( GetRoot() );
81  mrImpData.mxTabProtect = std::make_shared<XclImpSheetProtectBuffer>( GetRoot() );
82  mrImpData.mxDocProtect = std::make_shared<XclImpDocProtectBuffer>( GetRoot() );
83  }
84 
85  mrImpData.mxPageSett = std::make_shared<XclImpPageSettings>( GetRoot() );
86  mrImpData.mxDocViewSett = std::make_shared<XclImpDocViewSettings>( GetRoot() );
87  mrImpData.mxTabViewSett = std::make_shared<XclImpTabViewSettings>( GetRoot() );
88  mrImpData.mpPrintRanges = std::make_unique<ScRangeListTabs>( GetRoot() );
89  mrImpData.mpPrintTitles = std::make_unique<ScRangeListTabs>( GetRoot() );
90 }
91 
92 void XclImpRoot::SetCodePage( sal_uInt16 nCodePage )
93 {
95  mrImpData.mbHasCodePage = true;
96 }
97 
99 {
100  if( GetBiff() <= EXC_BIFF4 )
101  {
106  }
110  // delete the automatically generated codename
111  GetDoc().SetCodeName( nScTab, OUString() );
112 }
113 
115 {
120 }
121 
123 {
124  return *mrImpData.mxAddrConv;
125 }
126 
128 {
129  return *mrImpData.mxFmlaComp;
130 }
131 
133 {
134  // TODO still in old RootData
135  return *GetOldRoot().pFmlaConverter;
136 }
137 
139 {
140  assert(mrImpData.mxSst && "XclImpRoot::GetSst - invalid call, wrong BIFF");
141  return *mrImpData.mxSst;
142 }
143 
145 {
146  return *mrImpData.mxPalette;
147 }
148 
150 {
151  return *mrImpData.mxFontBfr;
152 }
153 
155 {
156  return *mrImpData.mxNumFmtBfr;
157 }
158 
160 {
161  return *mrImpData.mpXFBfr;
162 }
163 
165 {
166  return *mrImpData.mxXFRangeBfr;
167 }
168 
170 {
171  return *mrImpData.mpPrintRanges;
172 }
173 
175 {
176  return *mrImpData.mpPrintTitles;
177 }
178 
180 {
181  return *mrImpData.mxTabInfo;
182 }
183 
185 {
186  return *mrImpData.mxNameMgr;
187 }
188 
190 {
191  assert(mrImpData.mxLinkMgr && "XclImpRoot::GetLinkManager - invalid call, wrong BIFF");
192  return *mrImpData.mxLinkMgr;
193 }
194 
196 {
197  return *mrImpData.mxObjMgr;
198 }
199 
201 {
202  OSL_ENSURE( !IsInGlobals(), "XclImpRoot::GetCurrSheetDrawing - must not be called from workbook globals" );
203  return mrImpData.mxObjMgr->GetSheetDrawing( GetCurrScTab() );
204 }
205 
207 {
208  assert(mrImpData.mxCondFmtMgr && "XclImpRoot::GetCondFormatManager - invalid call, wrong BIFF");
209  return *mrImpData.mxCondFmtMgr;
210 }
211 
213 {
214  assert(mrImpData.mxValidMgr && "XclImpRoot::GetValidationManager - invalid call, wrong BIFF");
215  return *mrImpData.mxValidMgr;
216 }
217 
219 {
220  // TODO still in old RootData
221  assert(GetOldRoot().pAutoFilterBuffer && "XclImpRoot::GetFilterManager - invalid call, wrong BIFF");
222  return *GetOldRoot().pAutoFilterBuffer;
223 }
224 
226 {
227  assert(mrImpData.mxWebQueryBfr && "XclImpRoot::GetWebQueryBuffer - invalid call, wrong BIFF");
228  return *mrImpData.mxWebQueryBfr;
229 }
230 
232 {
233  assert(mrImpData.mxPTableMgr && "XclImpRoot::GetPivotTableManager - invalid call, wrong BIFF");
234  return *mrImpData.mxPTableMgr;
235 }
236 
238 {
239  assert(mrImpData.mxTabProtect && "XclImpRoot::GetSheetProtectBuffer - invalid call, wrong BIFF");
240  return *mrImpData.mxTabProtect;
241 }
242 
244 {
245  assert(mrImpData.mxDocProtect && "XclImpRoot::GetDocProtectBuffer - invalid call, wrong BIFF");
246  return *mrImpData.mxDocProtect;
247 }
248 
250 {
251  return *mrImpData.mxPageSett;
252 }
253 
255 {
256  return *mrImpData.mxDocViewSett;
257 }
258 
260 {
261  return *mrImpData.mxTabViewSett;
262 }
263 
264 OUString XclImpRoot::GetScAddInName( const OUString& rXclName )
265 {
266  OUString aScName;
267  if( ScGlobal::GetAddInCollection()->GetCalcName( rXclName, aScName ) )
268  return aScName;
269  return rXclName;
270 }
271 
272 void XclImpRoot::ReadCodeName( XclImpStream& rStrm, bool bGlobals )
273 {
274  if( !(mrImpData.mbHasBasic && (GetBiff() == EXC_BIFF8)) )
275  return;
276 
277  OUString aName = rStrm.ReadUniString();
278  if( aName.isEmpty() )
279  return;
280 
281  if( bGlobals )
282  {
284  GetDoc().SetCodeName( aName );
285  }
286  else
287  {
289  GetDoc().SetCodeName( GetCurrScTab(), aName );
290  }
291 }
292 
294 {
295  return *mrImpData.mxDocImport;
296 }
297 
298 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XclImpValidationManager & GetValidationManager() const
Definition: xiroot.cxx:212
void ReadCodeName(XclImpStream &rStrm, bool bGlobals)
Reads the CODENAME record and inserts the codename into the document.
Definition: xiroot.cxx:272
static SC_DLLPUBLIC ScUnoAddInCollection * GetAddInCollection()
Definition: global.cxx:279
ScDocumentImport & GetDocImport()
Definition: xiroot.cxx:293
Drawing manager of a single sheet.
Definition: xiescher.hxx:1110
XclBiff
An enumeration for all Excel file format types (BIFF types).
Definition: xlconst.hxx:29
void Finalize()
Applies styles and cell merging to the current sheet in the document.
Definition: xistyle.cxx:1985
Contains all view settings for a single sheet.
Definition: xiview.hxx:58
Contains all XF records occurred in the file.
Definition: xistyle.hxx:477
XclImpTabViewSettings & GetTabViewSettings() const
Returns the view settings of the current sheet.
Definition: xiroot.cxx:259
void Convert(SCTAB nScTab)
Inserts all column and row settings of the specified sheet, except the hidden flags.
Definition: colrowst.cxx:178
XclImpNumFmtBuffer & GetNumFmtBuffer() const
Returns the number format buffer.
Definition: xiroot.cxx:154
Contains document view settings (WINDOW1 record).
Definition: xiview.hxx:28
XclImpPivotTableManager & GetPivotTableManager() const
Returns the pivot table manager.
Definition: xiroot.cxx:231
void Initialize()
Initializes the object to be used for a new sheet.
Definition: xiview.cxx:96
XclImpValidationMgrRef mxValidMgr
Conditional formatting.
Definition: xiroot.hxx:104
Stores all drawing and OLE objects and additional data related to these objects.
Definition: xiescher.hxx:1144
Stores global buffers and data needed for Excel import filter.
Definition: xiroot.hxx:63
XclImpWebQueryBfrRef mxWebQueryBfr
Data validation.
Definition: xiroot.hxx:105
XclImpRootData & mrImpData
Definition: xiroot.hxx:216
static OUString GetScAddInName(const OUString &rXclName)
Returns the Calc add-in function name for an Excel function name.
Definition: xiroot.cxx:264
This buffer contains all internal defined names of the document.
Definition: xiname.hxx:81
XclImpCondFmtMgrRef mxCondFmtMgr
All drawing objects.
Definition: xiroot.hxx:103
std::unique_ptr< ScRangeListTabs > mpPrintRanges
Definition: xiroot.hxx:116
void Finalize()
Sets the view settings at the current sheet or the extended sheet options object. ...
Definition: xiview.cxx:212
XclImpObjectMgrRef mxObjMgr
Manager for internal/external links.
Definition: xiroot.hxx:102
void Initialize()
Clears all buffered data, used to set up for a new sheet.
Definition: xistyle.cxx:637
XclImpXFRangeBuffer & GetXFRangeBuffer() const
Returns the buffer of XF index ranges for a sheet.
Definition: xiroot.cxx:164
Contains the XF indexes for every used cell in a single sheet.
Definition: xistyle.hxx:606
Stores global buffers and data needed elsewhere in the Excel filters.
Definition: xlroot.hxx:61
const ScExtDocSettings & GetDocSettings() const
Definition: scextopt.cxx:170
std::shared_ptr< T > make_shared(Args &&...args)
XclImpObjectManager & GetObjectManager() const
Returns the drawing object manager.
Definition: xiroot.cxx:195
ScDocument & GetDoc() const
Returns reference to the destination document (import) or source document (export).
Definition: xlroot.cxx:285
RootData & GetOldRoot() const
Returns old RootData struct.
Definition: xlroot.hxx:138
Accessor class to ScDocument.
const XclImpRoot & GetRoot() const
Returns this root instance - for code readability in derived classes.
Definition: xiroot.hxx:134
XclImpPageSettings & GetPageSettings() const
Returns the page settings of the current sheet.
Definition: xiroot.cxx:249
Provides functions to convert Excel cell addresses to Calc cell addresses.
Definition: xihelper.hxx:41
XclImpPalette & GetPalette() const
Returns the color buffer.
Definition: xiroot.cxx:144
void SetCodeName(const OUString &r)
Definition: document.hxx:608
XclImpSst & GetSst() const
Returns the shared string table.
Definition: xiroot.cxx:138
ExcelToSc & GetOldFmlaConverter() const
Returns the old formula converter.
Definition: xiroot.cxx:132
XclImpXFBuffer & GetXFBuffer() const
Returns the cell formatting attributes buffer.
Definition: xiroot.cxx:159
XclImpDocViewSettRef mxDocViewSett
Page settings for current sheet.
Definition: xiroot.hxx:109
void Finalize()
Creates a page stylesheet from current settings and sets it at current sheet.
Definition: xipage.cxx:231
OUString maGlobCodeName
Global codename (VBA module name).
Definition: scextopt.hxx:29
Imports and collects all conditional formatting of a sheet.
Definition: xicontent.hxx:147
bool mbHasBasic
true = CODEPAGE record exists.
Definition: xiroot.hxx:120
XclImpNameMgrRef mxNameMgr
Sheet creation order list.
Definition: xiroot.hxx:99
XclImpNumFmtBfrRef mxNumFmtBfr
All fonts in the file.
Definition: xiroot.hxx:94
void SetCodeName(SCTAB nTab, const OUString &rCodeName)
Appends a codename for a sheet.
Definition: scextopt.cxx:206
std::unique_ptr< XclImpAutoFilterBuffer > pAutoFilterBuffer
Definition: root.hxx:53
XclImpRootData(XclBiff eBiff, SfxMedium &rMedium, const tools::SvRef< SotStorage > &xRootStrg, ScDocument &rDoc, rtl_TextEncoding eTextEnc)
true = document contains VB project.
Definition: xiroot.cxx:43
MS Excel 5.0, MS Excel 7.0 (95)
Definition: xlconst.hxx:35
A buffer containing information about names and creation order of sheets.
Definition: xilink.hxx:60
XclImpTabInfo & GetTabInfo() const
Returns the buffer that contains the sheet creation order.
Definition: xiroot.cxx:179
XclImpSstRef mxSst
The formula compiler.
Definition: xiroot.hxx:91
ScExtDocOptions & GetExtDocOptions() const
Returns the extended document options.
Definition: xlroot.cxx:428
XclImpAutoFilterBuffer & GetFilterManager() const
Returns the filter manager.
Definition: xiroot.cxx:218
XclImpFontBfrRef mxFontBfr
The color buffer.
Definition: xiroot.hxx:93
static rtl_TextEncoding GetTextEncoding(sal_uInt16 nCodePage)
Returns a text encoding from an Excel code page.
Definition: xltools.cxx:430
XclImpTabInfoRef mxTabInfo
Buffer of XF index ranges in a sheet.
Definition: xiroot.hxx:98
XclImpAddressConverter & GetAddressConverter() const
Returns the address converter.
Definition: xiroot.cxx:122
Contains all page (print) settings for a single sheet.
Definition: xipage.hxx:29
Stores all user defined number formats occurred in the file.
Definition: xistyle.hxx:204
void FinalizeTable()
Is called when import filter stops importing a single sheet (all BIFF versions).
Definition: xiroot.cxx:114
std::shared_ptr< ScDocumentImport > mxDocImport
Document protection options.
Definition: xiroot.hxx:114
The formula compiler to create Calc token arrays from Excel token arrays.
Definition: xiformula.hxx:32
MS Excel 3.0.
Definition: xlconst.hxx:33
std::unique_ptr< ScRangeListTabs > mpPrintTitles
Definition: xiroot.hxx:117
virtual ~XclImpRootData() override
Definition: xiroot.cxx:52
ScRangeListTabs & GetTitleAreaBuffer() const
Returns the buffer that contains all print titles in the document.
Definition: xiroot.cxx:174
XclImpDocProtectRef mxDocProtect
Sheet protection options for current sheet.
Definition: xiroot.hxx:112
XclImpNameManager & GetNameManager() const
Returns the buffer that contains internal defined names.
Definition: xiroot.cxx:184
void SetTextEncoding(rtl_TextEncoding eTextEnc)
Sets the text encoding to import/export byte strings.
Definition: xlroot.cxx:201
XclImpFormulaCompiler & GetFormulaCompiler() const
Returns the formula converter.
Definition: xiroot.cxx:127
SCTAB GetCurrScTab() const
Returns the current Calc sheet index.
Definition: xlroot.hxx:162
XclImpPageSettRef mxPageSett
All pivot tables and pivot caches.
Definition: xiroot.hxx:108
Imports validation data.
Definition: xicontent.hxx:168
XclImpSheetDrawing & GetCurrSheetDrawing() const
Returns the drawing container of the current sheet.
Definition: xiroot.cxx:200
XclImpFmlaCompRef mxFmlaComp
The address converter.
Definition: xiroot.hxx:89
XclImpXFBfrRef mpXFBfr
All number formats in the file.
Definition: xiroot.hxx:95
XclImpLinkManager & GetLinkManager() const
Returns the link manager.
Definition: xiroot.cxx:189
void SetCodePage(sal_uInt16 nCodePage)
Sets a code page read from a CODEPAGE record for byte string import.
Definition: xiroot.cxx:92
OUString ReadUniString(sal_uInt16 nChars, sal_uInt8 nFlags)
Reads ext.
Definition: xistream.cxx:891
XclImpPTableMgrRef mxPTableMgr
All web queries.
Definition: xiroot.hxx:106
XclImpWebQueryBuffer & GetWebQueryBuffer() const
Returns the web query buffer.
Definition: xiroot.cxx:225
void Initialize()
Initializes the object to be used for a new sheet.
Definition: xipage.cxx:47
XclImpPaletteRef mxPalette
The shared string table.
Definition: xiroot.hxx:92
XclImpRoot(XclImpRootData &rImpRootData)
Definition: xiroot.cxx:56
OUString aName
XclImpFontBuffer & GetFontBuffer() const
Returns the font buffer.
Definition: xiroot.cxx:149
The main class for pivot table import.
Definition: xipivot.hxx:371
Stores the data of all fonts occurred in an Excel file.
Definition: xistyle.hxx:152
void Initialize()
Clears all buffered data, used to set up for a new sheet.
Definition: xistyle.cxx:152
XclBiff GetBiff() const
Returns the current BIFF version of the importer/exporter.
Definition: xlroot.hxx:141
ExcelToSc * pFmlaConverter
Definition: root.hxx:49
The SST (shared string table) contains all strings used in a BIFF8 file.
Definition: xicontent.hxx:55
Stores the default colors for the current BIFF version and the contents of a PALETTE record...
Definition: xistyle.hxx:44
XclImpAddrConvRef mxAddrConv
Definition: xiroot.hxx:88
XclImpDocViewSettings & GetDocViewSettings() const
Returns the view settings of the entire document.
Definition: xiroot.cxx:254
XclImpLinkMgrRef mxLinkMgr
Internal defined names.
Definition: xiroot.hxx:100
XclImpCondFormatManager & GetCondFormatManager() const
Returns the conditional formatting manager.
Definition: xiroot.cxx:206
XclImpXFRangeBfrRef mxXFRangeBfr
All XF record data in the file.
Definition: xiroot.hxx:96
This class is used to import record oriented streams.
Definition: xistream.hxx:277
void Initialize()
Clears all buffered data, used to set up for a new sheet.
Definition: xistyle.cxx:1565
XclImpColRowSettings * pColRowBuff
Definition: root.hxx:50
void InitializeTable(SCTAB nScTab)
Is called when import filter starts importing a single sheet (all BIFF versions). ...
Definition: xiroot.cxx:98
bool IsInGlobals() const
Returns the current Calc sheet index.
Definition: xlroot.hxx:160
XclImpTabProtectRef mxTabProtect
View settings for current sheet.
Definition: xiroot.hxx:111
void Initialize()
Clears all buffered data, used to set up for a new sheet.
Definition: xistyle.cxx:1888
XclImpSheetProtectBuffer & GetSheetProtectBuffer() const
Returns the sheet protection options of the current sheet.
Definition: xiroot.cxx:237
Access to global data for a filter object (imported or exported document) from other classes...
Definition: xlroot.hxx:127
XclImpDocProtectBuffer & GetDocProtectBuffer() const
Returns the document protection options.
Definition: xiroot.cxx:243
void Initialize()
Clears all buffered data, used to set up for a new sheet.
Definition: xistyle.cxx:547
XclImpTabViewSettRef mxTabViewSett
View settings for entire document.
Definition: xiroot.hxx:110
sal_Int16 SCTAB
Definition: types.hxx:22
This is the central class for the import of all internal/external links.
Definition: xilink.hxx:183
ScRangeListTabs & GetPrintAreaBuffer() const
Returns the buffer that contains all print areas in the document.
Definition: xiroot.cxx:169
bool m_bDetectedRangeSegmentation false
bool mbHasCodePage
Definition: xiroot.hxx:119