1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
|
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#ifndef OOX_XLS_WORKSHEETHELPER_HXX
#define OOX_XLS_WORKSHEETHELPER_HXX
#include "oox/helper/progressbar.hxx"
#include "oox/ole/olehelper.hxx"
#include "oox/xls/addressconverter.hxx"
#include "oox/xls/formulabase.hxx"
namespace com { namespace sun { namespace star {
namespace awt { struct Point; }
namespace awt { struct Rectangle; }
namespace awt { struct Size; }
namespace drawing { class XDrawPage; }
namespace sheet { class XSheetCellRanges; }
namespace sheet { class XSpreadsheet; }
namespace table { class XCell; }
namespace table { class XCellRange; }
namespace table { class XTableColumns; }
namespace table { class XTableRows; }
namespace util { struct DateTime; }
} } }
namespace oox {
namespace xls {
class AutoFilterBuffer;
struct BinAddress;
struct BinRange;
class BinRangeList;
class CommentsBuffer;
class CondFormatBuffer;
class PageSettings;
class QueryTableBuffer;
class SharedFormulaBuffer;
class SheetViewSettings;
class VmlDrawing;
class WorksheetSettings;
// ============================================================================
// ============================================================================
/** An enumeration for all types of sheets in a workbook. */
enum WorksheetType
{
SHEETTYPE_WORKSHEET, /// Worksheet.
SHEETTYPE_CHARTSHEET, /// Chart sheet.
SHEETTYPE_MACROSHEET, /// Macro sheet.
SHEETTYPE_DIALOGSHEET, /// Dialog sheet (BIFF5+).
SHEETTYPE_MODULESHEET, /// VB module sheet (BIFF5 only).
SHEETTYPE_EMPTYSHEET /// Other (unsupported) sheet type.
};
// ============================================================================
/** Stores some data about a cell. */
struct CellModel
{
::com::sun::star::uno::Reference< ::com::sun::star::table::XCell > mxCell;
::com::sun::star::table::CellAddress maAddress;
::rtl::OUString maValueStr; /// String containing cell value data.
::rtl::OUString maFormulaRef; /// String containing formula range for array/shared formulas.
sal_Int32 mnCellType; /// Data type of the cell.
sal_Int32 mnFormulaType; /// Type of the imported formula.
sal_Int32 mnSharedId; /// Shared formula identifier for current cell.
sal_Int32 mnXfId; /// XF identifier for the cell.
sal_Int32 mnNumFmtId; /// Forced number format for the cell.
bool mbHasValueStr; /// True = contents of maValueStr are valid.
bool mbShowPhonetic; /// True = show phonetic text.
inline explicit CellModel() { reset(); }
void reset();
};
// ----------------------------------------------------------------------------
/** Stores data about a data table a.k.a. multiple operation range. */
struct DataTableModel
{
::rtl::OUString maRef1; /// String containing first reference cell for data table formulas.
::rtl::OUString maRef2; /// String containing second reference cell for data table formulas.
bool mb2dTable; /// True = 2-dimensional data table.
bool mbRowTable; /// True = row oriented data table.
bool mbRef1Deleted; /// True = first reference cell deleted.
bool mbRef2Deleted; /// True = second reference cell deleted.
explicit DataTableModel();
};
// ----------------------------------------------------------------------------
/** Stores formatting data about a range of columns. */
struct ColumnModel
{
sal_Int32 mnFirstCol; /// 1-based (!) index of first column.
sal_Int32 mnLastCol; /// 1-based (!) index of last column.
double mfWidth; /// Column width in number of characters.
sal_Int32 mnXfId; /// Column default formatting.
sal_Int32 mnLevel; /// Column outline level.
bool mbShowPhonetic; /// True = cells in column show phonetic settings.
bool mbHidden; /// True = column is hidden.
bool mbCollapsed; /// True = column outline is collapsed.
explicit ColumnModel();
/** Expands this entry with the passed column range, if column settings are equal. */
bool tryExpand( const ColumnModel& rModel );
};
// ----------------------------------------------------------------------------
/** Stores formatting data about a range of rows. */
struct RowModel
{
sal_Int32 mnFirstRow; /// 1-based (!) index of first row.
sal_Int32 mnLastRow; /// 1-based (!) index of last row.
double mfHeight; /// Row height in points.
sal_Int32 mnXfId; /// Row default formatting (see mbIsFormatted).
sal_Int32 mnLevel; /// Row outline level.
bool mbCustomHeight; /// True = row has custom height.
bool mbCustomFormat; /// True = cells in row have explicit formatting.
bool mbShowPhonetic; /// True = cells in row show phonetic settings.
bool mbHidden; /// True = row is hidden.
bool mbCollapsed; /// True = row outline is collapsed.
bool mbThickTop; /// True = row has extra space above text.
bool mbThickBottom; /// True = row has extra space below text.
explicit RowModel();
/** Expands this entry with the passed row range, if row settings are equal. */
bool tryExpand( const RowModel& rModel );
};
// ----------------------------------------------------------------------------
/** Stores formatting data about a page break. */
struct PageBreakModel
{
sal_Int32 mnColRow; /// 0-based (!) index of column/row.
sal_Int32 mnMin; /// Start of limited break.
sal_Int32 mnMax; /// End of limited break.
bool mbManual; /// True = manual page break.
explicit PageBreakModel();
};
// ----------------------------------------------------------------------------
/** Stores data about a hyperlink range. */
struct HyperlinkModel : public ::oox::ole::StdHlinkInfo
{
::com::sun::star::table::CellRangeAddress
maRange; /// The cell area containing the hyperlink.
::rtl::OUString maTooltip; /// Additional tooltip text.
explicit HyperlinkModel();
};
// ----------------------------------------------------------------------------
/** Stores data about ranges with data validation settings. */
struct ValidationModel
{
ApiCellRangeList maRanges;
ApiTokenSequence maTokens1;
ApiTokenSequence maTokens2;
::rtl::OUString maInputTitle;
::rtl::OUString maInputMessage;
::rtl::OUString maErrorTitle;
::rtl::OUString maErrorMessage;
sal_Int32 mnType;
sal_Int32 mnOperator;
sal_Int32 mnErrorStyle;
bool mbShowInputMsg;
bool mbShowErrorMsg;
bool mbNoDropDown;
bool mbAllowBlank;
explicit ValidationModel();
/** Sets the passed BIFF validation type. */
void setBiffType( sal_uInt8 nType );
/** Sets the passed BIFF operator. */
void setBiffOperator( sal_uInt8 nOperator );
/** Sets the passed BIFF error style. */
void setBiffErrorStyle( sal_uInt8 nErrorStyle );
};
// ============================================================================
// ============================================================================
class WorksheetData;
class WorksheetHelper : public WorkbookHelper
{
public:
/*implicit*/ WorksheetHelper( WorksheetData& rSheetData );
/** Returns the type of this sheet. */
WorksheetType getSheetType() const;
/** Returns the index of the current sheet. */
sal_Int16 getSheetIndex() const;
/** Returns the XSpreadsheet interface of the current sheet. */
const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheet >&
getSheet() const;
/** Returns the XCell interface for the passed cell address. */
::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >
getCell(
const ::com::sun::star::table::CellAddress& rAddress ) const;
/** Returns the XCell interface for the passed cell address string. */
::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >
getCell(
const ::rtl::OUString& rAddressStr,
::com::sun::star::table::CellAddress* opAddress = 0 ) const;
/** Returns the XCell interface for the passed cell address. */
::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >
getCell(
const BinAddress& rBinAddress,
::com::sun::star::table::CellAddress* opAddress = 0 ) const;
/** Returns the XCellRange interface for the passed cell range address. */
::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange >
getCellRange(
const ::com::sun::star::table::CellRangeAddress& rRange ) const;
/** Returns the XCellRange interface for the passed range address string. */
::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange >
getCellRange(
const ::rtl::OUString& rRangeStr,
::com::sun::star::table::CellRangeAddress* opRange = 0 ) const;
/** Returns the XCellRange interface for the passed range address. */
::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange >
getCellRange(
const BinRange& rBinRange,
::com::sun::star::table::CellRangeAddress* opRange = 0 ) const;
/** Returns the XSheetCellRanges interface for the passed cell range addresses. */
::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSheetCellRanges >
getCellRangeList( const ApiCellRangeList& rRanges ) const;
/** Returns the XSheetCellRanges interface for the passed space-separated range list. */
::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSheetCellRanges >
getCellRangeList(
const ::rtl::OUString& rRangesStr,
ApiCellRangeList* opRanges = 0 ) const;
/** Returns the XSheetCellRanges interface for the passed range list. */
::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSheetCellRanges >
getCellRangeList(
const BinRangeList& rBinRanges,
ApiCellRangeList* opRanges = 0 ) const;
/** Returns the address of the passed cell. The cell reference must be valid. */
static ::com::sun::star::table::CellAddress
getCellAddress(
const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell );
/** Returns the address of the passed cell range. The range reference must be valid. */
static ::com::sun::star::table::CellRangeAddress
getRangeAddress(
const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange >& rxRange );
/** Returns the XCellRange interface for a column. */
::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange >
getColumn( sal_Int32 nCol ) const;
/** Returns the XCellRange interface for a row. */
::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange >
getRow( sal_Int32 nRow ) const;
/** Returns the XTableColumns interface for a range of columns. */
::com::sun::star::uno::Reference< ::com::sun::star::table::XTableColumns >
getColumns( sal_Int32 nFirstCol, sal_Int32 nLastCol ) const;
/** Returns the XTableRows interface for a range of rows. */
::com::sun::star::uno::Reference< ::com::sun::star::table::XTableRows >
getRows( sal_Int32 nFirstRow, sal_Int32 nLastRow ) const;
/** Returns the XDrawPage interface of the draw page of the current sheet. */
::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >
getDrawPage() const;
/** Returns the absolute cell position in 1/100 mm. */
::com::sun::star::awt::Point getCellPosition( sal_Int32 nCol, sal_Int32 nRow ) const;
/** Returns the cell size in 1/100 mm. */
::com::sun::star::awt::Size getCellSize( sal_Int32 nCol, sal_Int32 nRow ) const;
/** Returns the size of the entire drawing page in 1/100 mm. */
::com::sun::star::awt::Size getDrawPageSize() const;
/** Returns the worksheet settings object. */
WorksheetSettings& getWorksheetSettings() const;
/** Returns the buffer containing all shared formulas in this sheet. */
SharedFormulaBuffer& getSharedFormulas() const;
/** Returns the conditional formattings in this sheet. */
CondFormatBuffer& getCondFormats() const;
/** Returns the buffer for all cell comments in this sheet. */
CommentsBuffer& getComments() const;
/** Returns the auto filters for the sheet. */
AutoFilterBuffer& getAutoFilters() const;
/** Returns the buffer for all web query tables in this sheet. */
QueryTableBuffer& getQueryTables() const;
/** Returns the page/print settings for this sheet. */
PageSettings& getPageSettings() const;
/** Returns the view settings for this sheet. */
SheetViewSettings& getSheetViewSettings() const;
/** Returns the VML drawing page for this sheet. */
VmlDrawing& getVmlDrawing() const;
/** Sets the passed string to the cell. */
void setStringCell(
const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell,
const ::rtl::OUString& rText ) const;
/** Sets the shared string with the passed identifier to the cell. */
void setSharedStringCell(
const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell,
sal_Int32 nStringId,
sal_Int32 nXfId ) const;
/** Sets the passed date/time value to the cell and adjusts number format. */
void setDateTimeCell(
const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell,
const ::com::sun::star::util::DateTime& rDateTime ) const;
/** Sets the passed boolean value to the cell and adjusts number format. */
void setBooleanCell(
const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell,
bool bValue ) const;
/** Sets the passed BIFF error code to the cell (by converting it to a formula). */
void setErrorCell(
const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell,
const ::rtl::OUString& rErrorCode ) const;
/** Sets the passed BIFF error code to the cell (by converting it to a formula). */
void setErrorCell(
const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell,
sal_uInt8 nErrorCode ) const;
/** Sets cell contents to the cell specified in the passed cell model. */
void setCell( CellModel& orModel ) const;
/** Sets a standard number format (constant from com.sun.star.util.NumberFormat) to the passed cell. */
void setStandardNumFmt(
const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell,
sal_Int16 nStdNumFmt ) const;
/** Changes the current sheet type. */
void setSheetType( WorksheetType eSheetType );
/** Stores the cell formatting data of the current cell. */
void setCellFormat( const CellModel& rModel );
/** Merges the cells in the passed cell range. */
void setMergedRange( const ::com::sun::star::table::CellRangeAddress& rRange );
/** Sets a column or row page break described in the passed struct. */
void setPageBreak( const PageBreakModel& rModel, bool bRowBreak );
/** Inserts the hyperlink URL into the spreadsheet. */
void setHyperlink( const HyperlinkModel& rModel );
/** Inserts the data validation settings into the spreadsheet. */
void setValidation( const ValidationModel& rModel );
/** Sets a multiple table operation to the passed range. */
void setTableOperation(
const ::com::sun::star::table::CellRangeAddress& rRange,
const DataTableModel& rModel ) const;
/** Sets the passed label ranges to the current sheet. */
void setLabelRanges(
const ApiCellRangeList& rColRanges,
const ApiCellRangeList& rRowRanges );
/** Sets the path to the DrawingML fragment of this sheet. */
void setDrawingPath( const ::rtl::OUString& rDrawingPath );
/** Sets the path to the legacy VML drawing fragment of this sheet. */
void setVmlDrawingPath( const ::rtl::OUString& rVmlDrawingPath );
/** Extends the used area of this sheet by the passed cell position. */
void extendUsedArea( const ::com::sun::star::table::CellAddress& rAddress );
/** Extends the used area of this sheet by the passed cell range. */
void extendUsedArea( const ::com::sun::star::table::CellRangeAddress& rRange );
/** Extends the shape bounding box by the position and size of the passed rectangle (in 1/100 mm). */
void extendShapeBoundingBox( const ::com::sun::star::awt::Rectangle& rShapeRect );
/** Sets base width for all columns (without padding pixels). This value
is only used, if width has not been set with setDefaultColumnWidth(). */
void setBaseColumnWidth( sal_Int32 nWidth );
/** Sets default width for all columns. This function overrides the base
width set with the setBaseColumnWidth() function. */
void setDefaultColumnWidth( double fWidth );
/** Converts default cell formatting for a range of columns. */
void setDefaultColumnFormat( sal_Int32 nFirstCol, sal_Int32 nLastCol, sal_Int32 nXfId );
/** Sets column settings for a specific range of columns.
@descr Column default formatting is converted directly, other settings
are cached and converted in the finalizeWorksheetImport() call. */
void setColumnModel( const ColumnModel& rModel );
/** Sets default height and hidden state for all unused rows in the sheet. */
void setDefaultRowSettings(
double fHeight, bool bCustomHeight,
bool bHidden, bool bThickTop, bool bThickBottom );
/** Sets row settings for a specific range of rows.
@descr Row default formatting is converted directly, other settings
are cached and converted in the finalizeWorksheetImport() call. */
void setRowModel( const RowModel& rModel );
/** Initial conversion before importing the worksheet. */
void initializeWorksheetImport();
/** Final conversion after importing the worksheet. */
void finalizeWorksheetImport();
private:
WorksheetData& mrSheetData;
};
// ============================================================================
namespace prv {
typedef ::boost::shared_ptr< WorksheetData > WorksheetDataRef;
struct WorksheetDataOwner
{
explicit WorksheetDataOwner( WorksheetDataRef xSheetData );
virtual ~WorksheetDataOwner();
WorksheetDataRef mxSheetData;
};
} // namespace prv
// ----------------------------------------------------------------------------
class WorksheetHelperRoot : private prv::WorksheetDataOwner, public WorksheetHelper
{
public:
/** Returns true, if this helper refers to an existing Calc sheet. */
bool isValidSheet() const;
protected:
/** Constructs from the passed data, creates and owns a new data object. */
explicit WorksheetHelperRoot(
const WorkbookHelper& rHelper,
const ISegmentProgressBarRef& rxProgressBar,
WorksheetType eSheetType,
sal_Int16 nSheet );
/** Constructs from another sheet helper, does not create a data object. */
explicit WorksheetHelperRoot(
const WorksheetHelper& rHelper );
/** Constructs from another sheet helper, shares ownership of the passed helper. */
explicit WorksheetHelperRoot(
const WorksheetHelperRoot& rHelper );
private:
WorksheetHelperRoot& operator=( const WorksheetHelperRoot& );
};
// ============================================================================
// ============================================================================
} // namespace xls
} // namespace oox
#endif
|