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_WORKSHEETBUFFER_HXX 25 #define OOX_XLS_WORKSHEETBUFFER_HXX 26 27 #include <utility> 28 #include "oox/helper/refmap.hxx" 29 #include "oox/helper/refvector.hxx" 30 #include "oox/xls/workbookhelper.hxx" 31 32 namespace com { namespace sun { namespace star { 33 namespace i18n { class XCharacterClassification; } 34 } } } 35 36 namespace oox { 37 namespace xls { 38 39 // ============================================================================ 40 41 /** Contains data from the 'sheet' element describing a sheet in the workbook. */ 42 struct SheetInfoModel 43 { 44 ::rtl::OUString maRelId; /// Relation identifier for the sheet substream. 45 ::rtl::OUString maName; /// Original name of the sheet. 46 sal_Int64 mnBiffHandle; /// BIFF record handle of the sheet substream. 47 sal_Int32 mnSheetId; /// Sheet identifier. 48 sal_Int32 mnState; /// Visibility state. 49 50 explicit SheetInfoModel(); 51 }; 52 53 // ============================================================================ 54 55 /** Stores information about all sheets in a spreadsheet document. 56 57 Information about sheets includes the sheet name, the visibility state, and 58 for the OOXML filter, the relation identifier of the sheet used to obtain 59 the related worksheet fragment. 60 */ 61 class WorksheetBuffer : public WorkbookHelper 62 { 63 public: 64 explicit WorksheetBuffer( const WorkbookHelper& rHelper ); 65 66 /** Returns the base file name without path and file extension. */ 67 static ::rtl::OUString getBaseFileName( const ::rtl::OUString& rUrl ); 68 69 /** Initializes the buffer for single sheet files (BIFF2-BIFF4). */ 70 void initializeSingleSheet(); 71 72 /** Imports the attributes of a sheet element. */ 73 void importSheet( const AttributeList& rAttribs ); 74 /** Imports the SHEET record from the passed BIFF12 stream. */ 75 void importSheet( SequenceInputStream& rStrm ); 76 /** Imports the SHEET record from the passed BIFF stream. */ 77 void importSheet( BiffInputStream& rStrm ); 78 /** Inserts a new empty sheet into the document. Looks for an unused name. 79 @return Index of the new sheet in the Calc document. */ 80 sal_Int16 insertEmptySheet( const ::rtl::OUString& rPreferredName, bool bVisible ); 81 82 /** Returns the number of original sheets contained in the workbook. */ 83 sal_Int32 getWorksheetCount() const; 84 /** Returns the OOXML relation identifier of the specified worksheet. */ 85 ::rtl::OUString getWorksheetRelId( sal_Int32 nWorksheet ) const; 86 /** Returns the BIFF record handle of the associated sheet substream. */ 87 sal_Int64 getBiffRecordHandle( sal_Int32 nWorksheet ) const; 88 89 /** Returns the Calc index of the specified worksheet. */ 90 sal_Int16 getCalcSheetIndex( sal_Int32 nWorksheet ) const; 91 /** Returns the finalized name of the specified worksheet. */ 92 ::rtl::OUString getCalcSheetName( sal_Int32 nWorksheet ) const; 93 94 /** Returns the Calc index of the sheet with the passed original worksheet name. */ 95 sal_Int16 getCalcSheetIndex( const ::rtl::OUString& rWorksheetName ) const; 96 /** Returns the finalized name of the sheet with the passed worksheet name. */ 97 ::rtl::OUString getCalcSheetName( const ::rtl::OUString& rWorksheetName ) const; 98 99 private: 100 struct SheetInfo : public SheetInfoModel 101 { 102 ::rtl::OUString maCalcName; 103 ::rtl::OUString maCalcQuotedName; 104 sal_Int16 mnCalcSheet; 105 106 explicit SheetInfo( const SheetInfoModel& rModel, sal_Int16 nCalcSheet, const ::rtl::OUString& rCalcName ); 107 }; 108 109 typedef ::std::pair< sal_Int16, ::rtl::OUString > IndexNamePair; 110 111 /** Creates a new sheet in the Calc document. Does not insert anything in the own lists. */ 112 IndexNamePair createSheet( const ::rtl::OUString& rPreferredName, sal_Int32 nSheetPos, bool bVisible ); 113 /** Creates a new sheet in the Calc document and inserts the related SheetInfo. */ 114 void insertSheet( const SheetInfoModel& rModel ); 115 116 private: 117 typedef RefVector< SheetInfo > SheetInfoVector; 118 SheetInfoVector maSheetInfos; 119 120 typedef RefMap< ::rtl::OUString, SheetInfo, IgnoreCaseCompare > SheetInfoMap; 121 SheetInfoMap maSheetInfosByName; 122 }; 123 124 // ============================================================================ 125 126 } // namespace xls 127 } // namespace oox 128 129 #endif 130