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 #ifndef OOX_XLS_WORKSHEETHELPER_HXX 25 #define OOX_XLS_WORKSHEETHELPER_HXX 26 27 #include "oox/helper/containerhelper.hxx" 28 #include "oox/helper/progressbar.hxx" 29 #include "oox/ole/olehelper.hxx" 30 #include "oox/xls/addressconverter.hxx" 31 #include "oox/xls/formulabase.hxx" 32 33 namespace com { namespace sun { namespace star { 34 namespace awt { struct Point; } 35 namespace awt { struct Rectangle; } 36 namespace awt { struct Size; } 37 namespace drawing { class XDrawPage; } 38 namespace sheet { class XSheetCellRanges; } 39 namespace sheet { class XSpreadsheet; } 40 namespace table { class XCell; } 41 namespace table { class XCellRange; } 42 namespace table { class XTableColumns; } 43 namespace table { class XTableRows; } 44 } } } 45 46 namespace oox { 47 namespace xls { 48 49 class AutoFilterBuffer; 50 struct BinAddress; 51 struct BinRange; 52 class BiffSheetDrawing; 53 class BinRangeList; 54 class CommentsBuffer; 55 class CondFormatBuffer; 56 class Font; 57 class PageSettings; 58 class QueryTableBuffer; 59 class RichString; 60 class SheetDataBuffer; 61 class SheetViewSettings; 62 class VmlDrawing; 63 class WorksheetSettings; 64 65 // ============================================================================ 66 // ============================================================================ 67 68 /** An enumeration for all types of sheets in a workbook. */ 69 enum WorksheetType 70 { 71 SHEETTYPE_WORKSHEET, /// Worksheet. 72 SHEETTYPE_CHARTSHEET, /// Chart sheet. 73 SHEETTYPE_MACROSHEET, /// Macro sheet. 74 SHEETTYPE_DIALOGSHEET, /// Dialog sheet (BIFF5+). 75 SHEETTYPE_MODULESHEET, /// VB module sheet (BIFF5 only). 76 SHEETTYPE_EMPTYSHEET /// Other (unsupported) sheet type. 77 }; 78 79 // ============================================================================ 80 81 /** Stores settings and formatting data about a range of sheet columns. */ 82 struct ColumnModel 83 { 84 ValueRange maRange; /// 1-based (!) range of the described columns. 85 double mfWidth; /// Column width in number of characters. 86 sal_Int32 mnXfId; /// Column default formatting. 87 sal_Int32 mnLevel; /// Column outline level. 88 bool mbShowPhonetic; /// True = cells in column show phonetic settings. 89 bool mbHidden; /// True = column is hidden. 90 bool mbCollapsed; /// True = column outline is collapsed. 91 92 explicit ColumnModel(); 93 94 /** Returns true, if this entry can be merged with the passed column range (column settings are equal). */ 95 bool isMergeable( const ColumnModel& rModel ) const; 96 }; 97 98 // ---------------------------------------------------------------------------- 99 100 /** Stores settings and formatting data about a sheet row. */ 101 struct RowModel 102 { 103 sal_Int32 mnRow; /// 1-based (!) index of the described row. 104 ValueRangeSet maColSpans; /// 0-based (!) column ranges of used cells. 105 double mfHeight; /// Row height in points. 106 sal_Int32 mnXfId; /// Row default formatting (see mbIsFormatted). 107 sal_Int32 mnLevel; /// Row outline level. 108 bool mbCustomHeight; /// True = row has custom height. 109 bool mbCustomFormat; /// True = cells in row have explicit formatting. 110 bool mbShowPhonetic; /// True = cells in row show phonetic settings. 111 bool mbHidden; /// True = row is hidden. 112 bool mbCollapsed; /// True = row outline is collapsed. 113 bool mbThickTop; /// True = row has extra space above text. 114 bool mbThickBottom; /// True = row has extra space below text. 115 116 explicit RowModel(); 117 118 /** Inserts the passed column span into the row model. */ 119 void insertColSpan( const ValueRange& rColSpan ); 120 /** Returns true, if this entry can be merged with the passed row range (row settings are equal). */ 121 bool isMergeable( const RowModel& rModel ) const; 122 }; 123 124 // ---------------------------------------------------------------------------- 125 126 /** Stores formatting data about a page break. */ 127 struct PageBreakModel 128 { 129 sal_Int32 mnColRow; /// 0-based (!) index of column/row. 130 sal_Int32 mnMin; /// Start of limited break. 131 sal_Int32 mnMax; /// End of limited break. 132 bool mbManual; /// True = manual page break. 133 134 explicit PageBreakModel(); 135 }; 136 137 // ---------------------------------------------------------------------------- 138 139 /** Stores data about a hyperlink range. */ 140 struct HyperlinkModel : public ::oox::ole::StdHlinkInfo 141 { 142 ::com::sun::star::table::CellRangeAddress 143 maRange; /// The cell area containing the hyperlink. 144 ::rtl::OUString maTooltip; /// Additional tooltip text. 145 146 explicit HyperlinkModel(); 147 }; 148 149 // ---------------------------------------------------------------------------- 150 151 /** Stores data about ranges with data validation settings. */ 152 struct ValidationModel 153 { 154 ApiCellRangeList maRanges; 155 ApiTokenSequence maTokens1; 156 ApiTokenSequence maTokens2; 157 ::rtl::OUString msRef; 158 ::rtl::OUString maInputTitle; 159 ::rtl::OUString maInputMessage; 160 ::rtl::OUString maErrorTitle; 161 ::rtl::OUString maErrorMessage; 162 sal_Int32 mnType; 163 sal_Int32 mnOperator; 164 sal_Int32 mnErrorStyle; 165 bool mbShowInputMsg; 166 bool mbShowErrorMsg; 167 bool mbNoDropDown; 168 bool mbAllowBlank; 169 170 explicit ValidationModel(); 171 172 /** Sets the passed BIFF validation type. */ 173 void setBiffType( sal_uInt8 nType ); 174 /** Sets the passed BIFF operator. */ 175 void setBiffOperator( sal_uInt8 nOperator ); 176 /** Sets the passed BIFF error style. */ 177 void setBiffErrorStyle( sal_uInt8 nErrorStyle ); 178 }; 179 180 // ============================================================================ 181 // ============================================================================ 182 183 class WorksheetGlobals; 184 typedef ::boost::shared_ptr< WorksheetGlobals > WorksheetGlobalsRef; 185 186 class WorksheetHelper : public WorkbookHelper 187 { 188 public: 189 /*implicit*/ WorksheetHelper( WorksheetGlobals& rSheetGlob ); 190 191 static WorksheetGlobalsRef constructGlobals( 192 const WorkbookHelper& rHelper, 193 const ISegmentProgressBarRef& rxProgressBar, 194 WorksheetType eSheetType, 195 sal_Int16 nSheet ); 196 197 // ------------------------------------------------------------------------ 198 199 /** Returns the type of this sheet. */ 200 WorksheetType getSheetType() const; 201 /** Returns the index of the current sheet. */ 202 sal_Int16 getSheetIndex() const; 203 /** Returns the XSpreadsheet interface of the current sheet. */ 204 const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheet >& 205 getSheet() const; 206 207 /** Returns the XCell interface for the passed cell address. */ 208 ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell > 209 getCell( const ::com::sun::star::table::CellAddress& rAddress ) const; 210 /** Returns the XCellRange interface for the passed cell range address. */ 211 ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange > 212 getCellRange( const ::com::sun::star::table::CellRangeAddress& rRange ) const; 213 /** Returns the XSheetCellRanges interface for the passed cell range addresses. */ 214 ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSheetCellRanges > 215 getCellRangeList( const ApiCellRangeList& rRanges ) const; 216 217 /** Returns the address of the passed cell. The cell reference must be valid. */ 218 static ::com::sun::star::table::CellAddress 219 getCellAddress( 220 const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell ); 221 /** Returns the address of the passed cell range. The range reference must be valid. */ 222 static ::com::sun::star::table::CellRangeAddress 223 getRangeAddress( 224 const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange >& rxRange ); 225 226 /** Returns the XCellRange interface for a column. */ 227 ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange > 228 getColumn( sal_Int32 nCol ) const; 229 /** Returns the XCellRange interface for a row. */ 230 ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange > 231 getRow( sal_Int32 nRow ) const; 232 233 /** Returns the XTableColumns interface for a range of columns. */ 234 ::com::sun::star::uno::Reference< ::com::sun::star::table::XTableColumns > 235 getColumns( const ValueRange& rColRange ) const; 236 /** Returns the XTableRows interface for a range of rows. */ 237 ::com::sun::star::uno::Reference< ::com::sun::star::table::XTableRows > 238 getRows( const ValueRange& rRowRange ) const; 239 240 /** Returns the XDrawPage interface of the draw page of the current sheet. */ 241 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage > 242 getDrawPage() const; 243 244 /** Returns the absolute cell position in 1/100 mm. */ 245 ::com::sun::star::awt::Point getCellPosition( sal_Int32 nCol, sal_Int32 nRow ) const; 246 /** Returns the cell size in 1/100 mm. */ 247 ::com::sun::star::awt::Size getCellSize( sal_Int32 nCol, sal_Int32 nRow ) const; 248 /** Returns the size of the entire drawing page in 1/100 mm. */ 249 ::com::sun::star::awt::Size getDrawPageSize() const; 250 251 /** Returns the buffer for cell contents and cell formatting. */ 252 SheetDataBuffer& getSheetData() const; 253 /** Returns the conditional formattings in this sheet. */ 254 CondFormatBuffer& getCondFormats() const; 255 /** Returns the buffer for all cell comments in this sheet. */ 256 CommentsBuffer& getComments() const; 257 /** Returns the auto filters for the sheet. */ 258 AutoFilterBuffer& getAutoFilters() const; 259 /** Returns the buffer for all web query tables in this sheet. */ 260 QueryTableBuffer& getQueryTables() const; 261 /** Returns the worksheet settings object. */ 262 WorksheetSettings& getWorksheetSettings() const; 263 /** Returns the page/print settings for this sheet. */ 264 PageSettings& getPageSettings() const; 265 /** Returns the view settings for this sheet. */ 266 SheetViewSettings& getSheetViewSettings() const; 267 /** Returns the VML drawing page for this sheet (OOXML/BIFF12 only). */ 268 VmlDrawing& getVmlDrawing() const; 269 /** Returns the BIFF drawing page for this sheet (BIFF2-BIFF8 only). */ 270 BiffSheetDrawing& getBiffDrawing() const; 271 272 /** Changes the current sheet type. */ 273 void setSheetType( WorksheetType eSheetType ); 274 /** Sets a column or row page break described in the passed struct. */ 275 void setPageBreak( const PageBreakModel& rModel, bool bRowBreak ); 276 /** Inserts the hyperlink URL into the spreadsheet. */ 277 void setHyperlink( const HyperlinkModel& rModel ); 278 /** Inserts the data validation settings into the spreadsheet. */ 279 void setValidation( const ValidationModel& rModel ); 280 /** Sets the passed label ranges to the current sheet. */ 281 void setLabelRanges( const ApiCellRangeList& rColRanges, const ApiCellRangeList& rRowRanges ); 282 /** Sets the path to the DrawingML fragment of this sheet. */ 283 void setDrawingPath( const ::rtl::OUString& rDrawingPath ); 284 /** Sets the path to the legacy VML drawing fragment of this sheet. */ 285 void setVmlDrawingPath( const ::rtl::OUString& rVmlDrawingPath ); 286 287 /** Extends the used area of this sheet by the passed cell position. */ 288 void extendUsedArea( const ::com::sun::star::table::CellAddress& rAddress ); 289 /** Extends the used area of this sheet by the passed cell range. */ 290 void extendUsedArea( const ::com::sun::star::table::CellRangeAddress& rRange ); 291 /** Extends the shape bounding box by the position and size of the passed rectangle (in 1/100 mm). */ 292 void extendShapeBoundingBox( const ::com::sun::star::awt::Rectangle& rShapeRect ); 293 294 /** Sets base width for all columns (without padding pixels). This value 295 is only used, if width has not been set with setDefaultColumnWidth(). */ 296 void setBaseColumnWidth( sal_Int32 nWidth ); 297 /** Sets default width for all columns. This function overrides the base 298 width set with the setBaseColumnWidth() function. */ 299 void setDefaultColumnWidth( double fWidth ); 300 /** Converts default cell formatting for a range of columns. */ 301 void setDefaultColumnFormat( sal_Int32 nFirstCol, sal_Int32 nLastCol, sal_Int32 nXfId ); 302 /** Sets column settings for a specific range of columns. 303 @descr Column default formatting is converted directly, other settings 304 are cached and converted in the finalizeWorksheetImport() call. */ 305 void setColumnModel( const ColumnModel& rModel ); 306 307 /** Sets default height and hidden state for all unused rows in the sheet. */ 308 void setDefaultRowSettings( 309 double fHeight, bool bCustomHeight, 310 bool bHidden, bool bThickTop, bool bThickBottom ); 311 /** Sets row settings for a specific range of rows. 312 @descr Row default formatting is converted directly, other settings 313 are cached and converted in the finalizeWorksheetImport() call. */ 314 void setRowModel( const RowModel& rModel ); 315 /** Specifies that the passed row needs to set its height manually. */ 316 void setManualRowHeight( sal_Int32 nRow ); 317 318 /** Inserts a value cell directly into the Calc sheet. */ 319 void putValue( 320 const ::com::sun::star::table::CellAddress& rAddress, 321 double fValue ) const; 322 /** Inserts a string cell directly into the Calc sheet. */ 323 void putString( 324 const ::com::sun::star::table::CellAddress& rAddress, 325 const ::rtl::OUString& rText ) const; 326 /** Inserts a rich-string cell directly into the Calc sheet. */ 327 void putRichString( 328 const ::com::sun::star::table::CellAddress& rAddress, 329 const RichString& rString, 330 const Font* pFirstPortionFont ) const; 331 /** Inserts a formula cell directly into the Calc sheet. */ 332 void putFormulaTokens( 333 const ::com::sun::star::table::CellAddress& rAddress, 334 const ApiTokenSequence& rTokens ) const; 335 336 /** Initial conversion before importing the worksheet. */ 337 void initializeWorksheetImport(); 338 /** Final conversion after importing the worksheet. */ 339 void finalizeWorksheetImport(); 340 341 private: 342 WorksheetGlobals& mrSheetGlob; 343 }; 344 345 // ============================================================================ 346 // ============================================================================ 347 348 } // namespace xls 349 } // namespace oox 350 351 #endif 352