1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include "oox/xls/querytablebuffer.hxx" 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include <com/sun/star/container/XEnumerationAccess.hpp> 31*cdf0e10cSrcweir #include <com/sun/star/sheet/XAreaLink.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/sheet/XAreaLinks.hpp> 33*cdf0e10cSrcweir #include "oox/core/filterbase.hxx" 34*cdf0e10cSrcweir #include "oox/helper/attributelist.hxx" 35*cdf0e10cSrcweir #include "oox/xls/addressconverter.hxx" 36*cdf0e10cSrcweir #include "oox/xls/biffinputstream.hxx" 37*cdf0e10cSrcweir #include "oox/xls/connectionsbuffer.hxx" 38*cdf0e10cSrcweir #include "oox/xls/defnamesbuffer.hxx" 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir namespace oox { 41*cdf0e10cSrcweir namespace xls { 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir // ============================================================================ 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir using namespace ::com::sun::star::container; 46*cdf0e10cSrcweir using namespace ::com::sun::star::sheet; 47*cdf0e10cSrcweir using namespace ::com::sun::star::table; 48*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir using ::rtl::OUString; 51*cdf0e10cSrcweir using ::rtl::OUStringBuffer; 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir // ============================================================================ 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir namespace { 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir const sal_uInt32 BIFF12_QUERYTABLE_HEADERS = 0x00000001; 58*cdf0e10cSrcweir const sal_uInt32 BIFF12_QUERYTABLE_ROWNUMBERS = 0x00000002; 59*cdf0e10cSrcweir const sal_uInt32 BIFF12_QUERYTABLE_DISABLEREFRESH = 0x00000004; 60*cdf0e10cSrcweir const sal_uInt32 BIFF12_QUERYTABLE_BACKGROUND = 0x00000008; 61*cdf0e10cSrcweir const sal_uInt32 BIFF12_QUERYTABLE_FIRSTBACKGROUND = 0x00000010; 62*cdf0e10cSrcweir const sal_uInt32 BIFF12_QUERYTABLE_REFRESHONLOAD = 0x00000020; 63*cdf0e10cSrcweir const sal_uInt32 BIFF12_QUERYTABLE_FILLFORMULAS = 0x00000100; 64*cdf0e10cSrcweir const sal_uInt32 BIFF12_QUERYTABLE_SAVEDATA = 0x00000200; 65*cdf0e10cSrcweir const sal_uInt32 BIFF12_QUERYTABLE_DISABLEEDIT = 0x00000400; 66*cdf0e10cSrcweir const sal_uInt32 BIFF12_QUERYTABLE_PRESERVEFORMAT = 0x00000800; 67*cdf0e10cSrcweir const sal_uInt32 BIFF12_QUERYTABLE_ADJUSTCOLWIDTH = 0x00001000; 68*cdf0e10cSrcweir const sal_uInt32 BIFF12_QUERYTABLE_INTERMEDIATE = 0x00002000; 69*cdf0e10cSrcweir const sal_uInt32 BIFF12_QUERYTABLE_APPLYNUMFMT = 0x00004000; 70*cdf0e10cSrcweir const sal_uInt32 BIFF12_QUERYTABLE_APPLYFONT = 0x00008000; 71*cdf0e10cSrcweir const sal_uInt32 BIFF12_QUERYTABLE_APPLYALIGNMENT = 0x00010000; 72*cdf0e10cSrcweir const sal_uInt32 BIFF12_QUERYTABLE_APPLYBORDER = 0x00020000; 73*cdf0e10cSrcweir const sal_uInt32 BIFF12_QUERYTABLE_APPLYFILL = 0x00040000; 74*cdf0e10cSrcweir const sal_uInt32 BIFF12_QUERYTABLE_APPLYPROTECTION = 0x00080000; 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir const sal_uInt16 BIFF_QUERYTABLE_HEADERS = 0x0001; 77*cdf0e10cSrcweir const sal_uInt16 BIFF_QUERYTABLE_ROWNUMBERS = 0x0002; 78*cdf0e10cSrcweir const sal_uInt16 BIFF_QUERYTABLE_DISABLEREFRESH = 0x0004; 79*cdf0e10cSrcweir const sal_uInt16 BIFF_QUERYTABLE_BACKGROUND = 0x0008; 80*cdf0e10cSrcweir const sal_uInt16 BIFF_QUERYTABLE_FIRSTBACKGROUND = 0x0010; 81*cdf0e10cSrcweir const sal_uInt16 BIFF_QUERYTABLE_REFRESHONLOAD = 0x0020; 82*cdf0e10cSrcweir const sal_uInt16 BIFF_QUERYTABLE_DELETEUNUSED = 0x0040; 83*cdf0e10cSrcweir const sal_uInt16 BIFF_QUERYTABLE_FILLFORMULAS = 0x0080; 84*cdf0e10cSrcweir const sal_uInt16 BIFF_QUERYTABLE_ADJUSTCOLWIDTH = 0x0100; 85*cdf0e10cSrcweir const sal_uInt16 BIFF_QUERYTABLE_SAVEDATA = 0x0200; 86*cdf0e10cSrcweir const sal_uInt16 BIFF_QUERYTABLE_DISABLEEDIT = 0x0400; 87*cdf0e10cSrcweir const sal_uInt16 BIFF_QUERYTABLE_OVERWRITEEXISTING = 0x2000; 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir const sal_uInt16 BIFF_QUERYTABLE_APPLYNUMFMT = 0x0001; 90*cdf0e10cSrcweir const sal_uInt16 BIFF_QUERYTABLE_APPLYFONT = 0x0002; 91*cdf0e10cSrcweir const sal_uInt16 BIFF_QUERYTABLE_APPLYALIGNMENT = 0x0004; 92*cdf0e10cSrcweir const sal_uInt16 BIFF_QUERYTABLE_APPLYBORDER = 0x0008; 93*cdf0e10cSrcweir const sal_uInt16 BIFF_QUERYTABLE_APPLYFILL = 0x0010; 94*cdf0e10cSrcweir const sal_uInt16 BIFF_QUERYTABLE_APPLYPROTECTION = 0x0020; 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir const sal_uInt32 BIFF_QTREFRESH_PRESERVEFORMAT = 0x00000001; 97*cdf0e10cSrcweir const sal_uInt32 BIFF_QTREFRESH_ADJUSTCOLWIDTH = 0x00000002; 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir // ---------------------------------------------------------------------------- 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir void lclAppendWebQueryTableName( OUStringBuffer& rTables, const OUString& rTableName ) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir if( rTableName.getLength() > 0 ) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir if( rTables.getLength() > 0 ) 106*cdf0e10cSrcweir rTables.append( sal_Unicode( ';' ) ); 107*cdf0e10cSrcweir rTables.appendAscii( RTL_CONSTASCII_STRINGPARAM( "HTML__" ) ).append( rTableName ); 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir void lclAppendWebQueryTableIndex( OUStringBuffer& rTables, sal_Int32 nTableIndex ) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir if( nTableIndex > 0 ) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir if( rTables.getLength() > 0 ) 116*cdf0e10cSrcweir rTables.append( sal_Unicode( ';' ) ); 117*cdf0e10cSrcweir rTables.appendAscii( RTL_CONSTASCII_STRINGPARAM( "HTML_" ) ).append( nTableIndex ); 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir OUString lclBuildWebQueryTables( const WebPrModel::TablesVector& rTables ) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir if( rTables.empty() ) 124*cdf0e10cSrcweir return CREATE_OUSTRING( "HTML_tables" ); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir OUStringBuffer aTables; 127*cdf0e10cSrcweir for( WebPrModel::TablesVector::const_iterator aIt = rTables.begin(), aEnd = rTables.end(); aIt != aEnd; ++aIt ) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir if( aIt->has< OUString >() ) 130*cdf0e10cSrcweir lclAppendWebQueryTableName( aTables, aIt->get< OUString >() ); 131*cdf0e10cSrcweir else if( aIt->has< sal_Int32 >() ) 132*cdf0e10cSrcweir lclAppendWebQueryTableIndex( aTables, aIt->get< sal_Int32 >() ); 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir return aTables.makeStringAndClear(); 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir Reference< XAreaLink > lclFindAreaLink( 138*cdf0e10cSrcweir const Reference< XAreaLinks >& rxAreaLinks, const CellAddress& rDestPos, 139*cdf0e10cSrcweir const OUString& rFileUrl, const OUString& rTables, const OUString& rFilterName, const OUString& rFilterOptions ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir try 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir Reference< XEnumerationAccess > xAreaLinksEA( rxAreaLinks, UNO_QUERY_THROW ); 144*cdf0e10cSrcweir Reference< XEnumeration > xAreaLinksEnum( xAreaLinksEA->createEnumeration(), UNO_SET_THROW ); 145*cdf0e10cSrcweir while( xAreaLinksEnum->hasMoreElements() ) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir Reference< XAreaLink > xAreaLink( xAreaLinksEnum->nextElement(), UNO_QUERY_THROW ); 148*cdf0e10cSrcweir PropertySet aPropSet( xAreaLink ); 149*cdf0e10cSrcweir CellRangeAddress aDestArea = xAreaLink->getDestArea(); 150*cdf0e10cSrcweir OUString aString; 151*cdf0e10cSrcweir if( (rDestPos.Sheet == aDestArea.Sheet) && (rDestPos.Column == aDestArea.StartColumn) && (rDestPos.Row == aDestArea.StartRow) && 152*cdf0e10cSrcweir (rTables == xAreaLink->getSourceArea()) && 153*cdf0e10cSrcweir aPropSet.getProperty( aString, PROP_Url ) && (rFileUrl == aString) && 154*cdf0e10cSrcweir aPropSet.getProperty( aString, PROP_Filter ) && (rFilterName == aString) && 155*cdf0e10cSrcweir aPropSet.getProperty( aString, PROP_FilterOptions ) && (rFilterOptions == aString) ) 156*cdf0e10cSrcweir return xAreaLink; 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir catch( Exception& ) 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir return Reference< XAreaLink >(); 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir } // namespace 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir // ============================================================================ 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir QueryTableModel::QueryTableModel() : 170*cdf0e10cSrcweir mnConnId( -1 ), 171*cdf0e10cSrcweir mnGrowShrinkType( XML_insertDelete ), 172*cdf0e10cSrcweir mbHeaders( true ), 173*cdf0e10cSrcweir mbRowNumbers( false ), 174*cdf0e10cSrcweir mbDisableRefresh( false ), 175*cdf0e10cSrcweir mbBackground( true ), 176*cdf0e10cSrcweir mbFirstBackground( false ), 177*cdf0e10cSrcweir mbRefreshOnLoad( false ), 178*cdf0e10cSrcweir mbFillFormulas( false ), 179*cdf0e10cSrcweir mbRemoveDataOnSave( false ), 180*cdf0e10cSrcweir mbDisableEdit( false ), 181*cdf0e10cSrcweir mbPreserveFormat( true ), 182*cdf0e10cSrcweir mbAdjustColWidth( true ), 183*cdf0e10cSrcweir mbIntermediate( false ) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir // ---------------------------------------------------------------------------- 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir QueryTable::QueryTable( const WorksheetHelper& rHelper ) : 190*cdf0e10cSrcweir WorksheetHelper( rHelper ) 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir void QueryTable::importQueryTable( const AttributeList& rAttribs ) 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir maModel.maDefName = rAttribs.getXString( XML_name, OUString() ); 197*cdf0e10cSrcweir maModel.mnConnId = rAttribs.getInteger( XML_connectionId, -1 ); 198*cdf0e10cSrcweir maModel.mnGrowShrinkType = rAttribs.getToken( XML_growShrinkType, XML_insertDelete ); 199*cdf0e10cSrcweir maModel.mnAutoFormatId = rAttribs.getInteger( XML_autoFormatId, 0 ); 200*cdf0e10cSrcweir maModel.mbHeaders = rAttribs.getBool( XML_headers, true ); 201*cdf0e10cSrcweir maModel.mbRowNumbers = rAttribs.getBool( XML_rowNumbers, false ); 202*cdf0e10cSrcweir maModel.mbDisableRefresh = rAttribs.getBool( XML_disableRefresh, false ); 203*cdf0e10cSrcweir maModel.mbBackground = rAttribs.getBool( XML_backgroundRefresh, true ); 204*cdf0e10cSrcweir maModel.mbFirstBackground = rAttribs.getBool( XML_firstBackgroundRefresh, false ); 205*cdf0e10cSrcweir maModel.mbRefreshOnLoad = rAttribs.getBool( XML_refreshOnLoad, false ); 206*cdf0e10cSrcweir maModel.mbFillFormulas = rAttribs.getBool( XML_fillFormulas, false ); 207*cdf0e10cSrcweir maModel.mbRemoveDataOnSave = rAttribs.getBool( XML_removeDataOnSave, false ); 208*cdf0e10cSrcweir maModel.mbDisableEdit = rAttribs.getBool( XML_disableEdit, false ); 209*cdf0e10cSrcweir maModel.mbPreserveFormat = rAttribs.getBool( XML_preserveFormatting, true ); 210*cdf0e10cSrcweir maModel.mbAdjustColWidth = rAttribs.getBool( XML_adjustColumnWidth, true ); 211*cdf0e10cSrcweir maModel.mbIntermediate = rAttribs.getBool( XML_intermediate, false ); 212*cdf0e10cSrcweir maModel.mbApplyNumFmt = rAttribs.getBool( XML_applyNumberFormats, false ); 213*cdf0e10cSrcweir maModel.mbApplyFont = rAttribs.getBool( XML_applyFontFormats, false ); 214*cdf0e10cSrcweir maModel.mbApplyAlignment = rAttribs.getBool( XML_applyAlignmentFormats, false ); 215*cdf0e10cSrcweir maModel.mbApplyBorder = rAttribs.getBool( XML_applyBorderFormats, false ); 216*cdf0e10cSrcweir maModel.mbApplyFill = rAttribs.getBool( XML_applyPatternFormats, false ); 217*cdf0e10cSrcweir // OOXML and BIFF12 documentation differ: OOXML mentions width/height, BIFF12 mentions protection 218*cdf0e10cSrcweir maModel.mbApplyProtection = rAttribs.getBool( XML_applyWidthHeightFormats, false ); 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir void QueryTable::importQueryTable( SequenceInputStream& rStrm ) 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir sal_uInt32 nFlags; 224*cdf0e10cSrcweir rStrm >> nFlags; 225*cdf0e10cSrcweir maModel.mnAutoFormatId = rStrm.readuInt16(); 226*cdf0e10cSrcweir rStrm >> maModel.mnConnId >> maModel.maDefName; 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir static const sal_Int32 spnGrowShrinkTypes[] = { XML_insertClear, XML_insertDelete, XML_overwriteClear }; 229*cdf0e10cSrcweir maModel.mnGrowShrinkType = STATIC_ARRAY_SELECT( spnGrowShrinkTypes, extractValue< sal_uInt8 >( nFlags, 6, 2 ), XML_insertDelete ); 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir maModel.mbHeaders = getFlag( nFlags, BIFF12_QUERYTABLE_HEADERS ); 232*cdf0e10cSrcweir maModel.mbRowNumbers = getFlag( nFlags, BIFF12_QUERYTABLE_ROWNUMBERS ); 233*cdf0e10cSrcweir maModel.mbDisableRefresh = getFlag( nFlags, BIFF12_QUERYTABLE_DISABLEREFRESH ); 234*cdf0e10cSrcweir maModel.mbBackground = getFlag( nFlags, BIFF12_QUERYTABLE_BACKGROUND ); 235*cdf0e10cSrcweir maModel.mbFirstBackground = getFlag( nFlags, BIFF12_QUERYTABLE_FIRSTBACKGROUND ); 236*cdf0e10cSrcweir maModel.mbRefreshOnLoad = getFlag( nFlags, BIFF12_QUERYTABLE_REFRESHONLOAD ); 237*cdf0e10cSrcweir maModel.mbFillFormulas = getFlag( nFlags, BIFF12_QUERYTABLE_FILLFORMULAS ); 238*cdf0e10cSrcweir maModel.mbRemoveDataOnSave = !getFlag( nFlags, BIFF12_QUERYTABLE_SAVEDATA ); // flag negated in BIFF12 239*cdf0e10cSrcweir maModel.mbDisableEdit = getFlag( nFlags, BIFF12_QUERYTABLE_DISABLEEDIT ); 240*cdf0e10cSrcweir maModel.mbPreserveFormat = getFlag( nFlags, BIFF12_QUERYTABLE_PRESERVEFORMAT ); 241*cdf0e10cSrcweir maModel.mbAdjustColWidth = getFlag( nFlags, BIFF12_QUERYTABLE_ADJUSTCOLWIDTH ); 242*cdf0e10cSrcweir maModel.mbIntermediate = getFlag( nFlags, BIFF12_QUERYTABLE_INTERMEDIATE ); 243*cdf0e10cSrcweir maModel.mbApplyNumFmt = getFlag( nFlags, BIFF12_QUERYTABLE_APPLYNUMFMT ); 244*cdf0e10cSrcweir maModel.mbApplyFont = getFlag( nFlags, BIFF12_QUERYTABLE_APPLYFONT ); 245*cdf0e10cSrcweir maModel.mbApplyAlignment = getFlag( nFlags, BIFF12_QUERYTABLE_APPLYALIGNMENT ); 246*cdf0e10cSrcweir maModel.mbApplyBorder = getFlag( nFlags, BIFF12_QUERYTABLE_APPLYBORDER ); 247*cdf0e10cSrcweir maModel.mbApplyFill = getFlag( nFlags, BIFF12_QUERYTABLE_APPLYFILL ); 248*cdf0e10cSrcweir maModel.mbApplyProtection = getFlag( nFlags, BIFF12_QUERYTABLE_APPLYPROTECTION ); 249*cdf0e10cSrcweir } 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir void QueryTable::importQueryTable( BiffInputStream& rStrm ) 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir sal_uInt16 nFlags, nAutoFormatFlags; 254*cdf0e10cSrcweir rStrm >> nFlags; 255*cdf0e10cSrcweir maModel.mnAutoFormatId = rStrm.readuInt16(); 256*cdf0e10cSrcweir rStrm >> nAutoFormatFlags; 257*cdf0e10cSrcweir rStrm.skip( 4 ); 258*cdf0e10cSrcweir maModel.maDefName = rStrm.readUniString(); 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir bool bDeleteUnused = getFlag( nFlags, BIFF_QUERYTABLE_DELETEUNUSED ); 261*cdf0e10cSrcweir bool bOverwriteExisting = getFlag( nFlags, BIFF_QUERYTABLE_OVERWRITEEXISTING ); 262*cdf0e10cSrcweir OSL_ENSURE( !bDeleteUnused || !bOverwriteExisting, "QueryTable::importQueryTable - invalid flags" ); 263*cdf0e10cSrcweir maModel.mnGrowShrinkType = bDeleteUnused ? XML_insertDelete : (bOverwriteExisting ? XML_overwriteClear : XML_insertClear); 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir maModel.mbHeaders = getFlag( nFlags, BIFF_QUERYTABLE_HEADERS ); 266*cdf0e10cSrcweir maModel.mbRowNumbers = getFlag( nFlags, BIFF_QUERYTABLE_ROWNUMBERS ); 267*cdf0e10cSrcweir maModel.mbDisableRefresh = getFlag( nFlags, BIFF_QUERYTABLE_DISABLEREFRESH ); 268*cdf0e10cSrcweir maModel.mbBackground = getFlag( nFlags, BIFF_QUERYTABLE_BACKGROUND ); 269*cdf0e10cSrcweir maModel.mbFirstBackground = getFlag( nFlags, BIFF_QUERYTABLE_FIRSTBACKGROUND ); 270*cdf0e10cSrcweir maModel.mbRefreshOnLoad = getFlag( nFlags, BIFF_QUERYTABLE_REFRESHONLOAD ); 271*cdf0e10cSrcweir maModel.mbFillFormulas = getFlag( nFlags, BIFF_QUERYTABLE_FILLFORMULAS ); 272*cdf0e10cSrcweir maModel.mbRemoveDataOnSave = !getFlag( nFlags, BIFF_QUERYTABLE_SAVEDATA ); // flag negated in BIFF 273*cdf0e10cSrcweir maModel.mbDisableEdit = getFlag( nFlags, BIFF_QUERYTABLE_DISABLEEDIT ); 274*cdf0e10cSrcweir maModel.mbAdjustColWidth = getFlag( nFlags, BIFF_QUERYTABLE_ADJUSTCOLWIDTH ); 275*cdf0e10cSrcweir maModel.mbApplyNumFmt = getFlag( nAutoFormatFlags, BIFF_QUERYTABLE_APPLYNUMFMT ); 276*cdf0e10cSrcweir maModel.mbApplyFont = getFlag( nAutoFormatFlags, BIFF_QUERYTABLE_APPLYFONT ); 277*cdf0e10cSrcweir maModel.mbApplyAlignment = getFlag( nAutoFormatFlags, BIFF_QUERYTABLE_APPLYALIGNMENT ); 278*cdf0e10cSrcweir maModel.mbApplyBorder = getFlag( nAutoFormatFlags, BIFF_QUERYTABLE_APPLYBORDER ); 279*cdf0e10cSrcweir maModel.mbApplyFill = getFlag( nAutoFormatFlags, BIFF_QUERYTABLE_APPLYFILL ); 280*cdf0e10cSrcweir maModel.mbApplyProtection = getFlag( nAutoFormatFlags, BIFF_QUERYTABLE_APPLYPROTECTION ); 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir // create a new connection object that will store settings from following records 283*cdf0e10cSrcweir OSL_ENSURE( maModel.mnConnId == -1, "QueryTable::importQueryTable - multiple call" ); 284*cdf0e10cSrcweir Connection& rConnection = getConnections().createConnectionWithId(); 285*cdf0e10cSrcweir maModel.mnConnId = rConnection.getConnectionId(); 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir // a DBQUERY record with some PCITEM_STRING records must follow 288*cdf0e10cSrcweir bool bHasDbQuery = (rStrm.getNextRecId() == BIFF_ID_DBQUERY) && rStrm.startNextRecord(); 289*cdf0e10cSrcweir OSL_ENSURE( bHasDbQuery, "QueryTable::importQueryTable - missing DBQUERY record" ); 290*cdf0e10cSrcweir if( bHasDbQuery ) 291*cdf0e10cSrcweir rConnection.importDbQuery( rStrm ); 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir void QueryTable::importQueryTableRefresh( BiffInputStream& rStrm ) 295*cdf0e10cSrcweir { 296*cdf0e10cSrcweir rStrm.skip( 4 ); 297*cdf0e10cSrcweir bool bPivot = rStrm.readuInt16() != 0; 298*cdf0e10cSrcweir OSL_ENSURE( !bPivot, "QueryTable::importQueryTableRefresh - unexpected pivot flag" ); 299*cdf0e10cSrcweir if( !bPivot ) 300*cdf0e10cSrcweir { 301*cdf0e10cSrcweir rStrm.skip( 2 ); 302*cdf0e10cSrcweir sal_uInt32 nFlags = rStrm.readuInt32(); 303*cdf0e10cSrcweir maModel.mbPreserveFormat = getFlag( nFlags, BIFF_QTREFRESH_PRESERVEFORMAT ); 304*cdf0e10cSrcweir maModel.mbAdjustColWidth = getFlag( nFlags, BIFF_QTREFRESH_ADJUSTCOLWIDTH ); 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir void QueryTable::importQueryTableSettings( BiffInputStream& rStrm ) 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir ConnectionRef xConnection = getConnections().getConnection( maModel.mnConnId ); 311*cdf0e10cSrcweir OSL_ENSURE( xConnection.get(), "QueryTable::importQueryTableSettings - missing connection object" ); 312*cdf0e10cSrcweir if( xConnection.get() ) 313*cdf0e10cSrcweir xConnection->importQueryTableSettings( rStrm ); 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir void QueryTable::finalizeImport() 317*cdf0e10cSrcweir { 318*cdf0e10cSrcweir ConnectionRef xConnection = getConnections().getConnection( maModel.mnConnId ); 319*cdf0e10cSrcweir OSL_ENSURE( xConnection.get(), "QueryTable::finalizeImport - missing connection object" ); 320*cdf0e10cSrcweir if( xConnection.get() && (xConnection->getConnectionType() == BIFF12_CONNECTION_HTML) ) 321*cdf0e10cSrcweir { 322*cdf0e10cSrcweir // check that valid web query properties exist 323*cdf0e10cSrcweir const WebPrModel* pWebPr = xConnection->getModel().mxWebPr.get(); 324*cdf0e10cSrcweir if( pWebPr && !pWebPr->mbXml ) 325*cdf0e10cSrcweir { 326*cdf0e10cSrcweir OUString aFileUrl = getBaseFilter().getAbsoluteUrl( pWebPr->maUrl ); 327*cdf0e10cSrcweir if( aFileUrl.getLength() > 0 ) 328*cdf0e10cSrcweir { 329*cdf0e10cSrcweir // resolve destination cell range (stored as defined name containing the range) 330*cdf0e10cSrcweir OUString aDefName = maModel.maDefName.replace( ' ', '_' ).replace( '-', '_' ); 331*cdf0e10cSrcweir DefinedNameRef xDefName = getDefinedNames().getByModelName( aDefName, getSheetIndex() ); 332*cdf0e10cSrcweir OSL_ENSURE( xDefName.get(), "QueryTable::finalizeImport - missing defined name" ); 333*cdf0e10cSrcweir if( xDefName.get() ) 334*cdf0e10cSrcweir { 335*cdf0e10cSrcweir CellRangeAddress aDestRange; 336*cdf0e10cSrcweir bool bIsRange = xDefName->getAbsoluteRange( aDestRange ) && (aDestRange.Sheet == getSheetIndex()); 337*cdf0e10cSrcweir OSL_ENSURE( bIsRange, "QueryTable::finalizeImport - defined name does not contain valid cell range" ); 338*cdf0e10cSrcweir if( bIsRange && getAddressConverter().checkCellRange( aDestRange, false, true ) ) 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir CellAddress aDestPos( aDestRange.Sheet, aDestRange.StartColumn, aDestRange.StartRow ); 341*cdf0e10cSrcweir // find tables mode: entire document, all tables, or specific tables 342*cdf0e10cSrcweir OUString aTables = pWebPr->mbHtmlTables ? lclBuildWebQueryTables( pWebPr->maTables ) : CREATE_OUSTRING( "HTML_all" ); 343*cdf0e10cSrcweir if( aTables.getLength() > 0 ) try 344*cdf0e10cSrcweir { 345*cdf0e10cSrcweir PropertySet aDocProps( getDocument() ); 346*cdf0e10cSrcweir Reference< XAreaLinks > xAreaLinks( aDocProps.getAnyProperty( PROP_AreaLinks ), UNO_QUERY_THROW ); 347*cdf0e10cSrcweir OUString aFilterName = CREATE_OUSTRING( "calc_HTML_WebQuery" ); 348*cdf0e10cSrcweir OUString aFilterOptions; 349*cdf0e10cSrcweir xAreaLinks->insertAtPosition( aDestPos, aFileUrl, aTables, aFilterName, aFilterOptions ); 350*cdf0e10cSrcweir // set refresh interval (convert minutes to seconds) 351*cdf0e10cSrcweir sal_Int32 nRefreshPeriod = xConnection->getModel().mnInterval * 60; 352*cdf0e10cSrcweir if( nRefreshPeriod > 0 ) 353*cdf0e10cSrcweir { 354*cdf0e10cSrcweir PropertySet aPropSet( lclFindAreaLink( xAreaLinks, aDestPos, aFileUrl, aTables, aFilterName, aFilterOptions ) ); 355*cdf0e10cSrcweir aPropSet.setProperty( PROP_RefreshPeriod, nRefreshPeriod ); 356*cdf0e10cSrcweir } 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir catch( Exception& ) 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir } 361*cdf0e10cSrcweir } 362*cdf0e10cSrcweir } 363*cdf0e10cSrcweir } 364*cdf0e10cSrcweir } 365*cdf0e10cSrcweir } 366*cdf0e10cSrcweir } 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir // ============================================================================ 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir QueryTableBuffer::QueryTableBuffer( const WorksheetHelper& rHelper ) : 371*cdf0e10cSrcweir WorksheetHelper( rHelper ) 372*cdf0e10cSrcweir { 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir QueryTable& QueryTableBuffer::createQueryTable() 376*cdf0e10cSrcweir { 377*cdf0e10cSrcweir QueryTableVector::value_type xQueryTable( new QueryTable( *this ) ); 378*cdf0e10cSrcweir maQueryTables.push_back( xQueryTable ); 379*cdf0e10cSrcweir return *xQueryTable; 380*cdf0e10cSrcweir } 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir void QueryTableBuffer::finalizeImport() 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir maQueryTables.forEachMem( &QueryTable::finalizeImport ); 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir // ============================================================================ 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir } // namespace xls 390*cdf0e10cSrcweir } // namespace oox 391