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