Commits

Anonymous committed 7a92800

Fix for issue: 106329

  • Participants
  • Parent commits d25e15b

Comments (0)

Files changed (8)

oovbaapi/ooo/vba/excel/XQueryTable.idl

+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright IBM Corporation 2009, 2010.
+ * 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 __ooo_vba_excel_XQueryTable_idl__
+#define __ooo_vba_excel_XQueryTable_idl__
+                                                     
+#ifndef __com_sun_star_uno_XInterface_idl__
+#include <com/sun/star/uno/XInterface.idl>
+#endif
+
+#ifndef __ooo_vba__XHelperInterface_idl__
+#define __ooo_vba__XHelperInterface_idl__
+#include <ooo/vba/XHelperInterface.idl>
+#endif
+
+
+//=============================================================================
+                                                                                                                             
+module ooo {  module vba {  module excel {
+                                                                                                                             
+//=============================================================================
+
+interface XQueryTable 
+{
+	interface com::sun::star::uno::XInterface;
+	//interface ooo::vba::XHelperInterface;
+	boolean Refresh([in] any aBackgroundQuery);
+};
+                                                                                                                             
+}; }; };
+                                                                                                                             
+#endif
+

oovbaapi/ooo/vba/excel/XRange.idl

 interface XValidation;
 interface XWorksheet;
 
+interface XPivotTable;
+interface XQueryTable;
 interface XRange
 {
  	interface com::sun::star::container::XEnumerationAccess;
 	[attribute] any Style;
 	[attribute] any AddIndent;
 	[attribute] any ShowDetail;
+	[attribute, readonly] XQueryTable QueryTable;
 
 	XComment AddComment( [in] any Text ); 
 	void Clear();
 	void RemoveSubtotal() raises ( com::sun::star::script::BasicErrorException );
 	void	Subtotal( [in] long GroupBy, [in] long Function, [in]  /*Optional*/ sequence<long> TotalList, [in]  /*Optional*/ any Replace, [in]  /*Optional*/ any PageBreaks, [in] any SummaryBelowData ) raises ( com::sun::star::script::BasicErrorException );
 	XRange MergeArea( ) raises ( com::sun::star::script::BasicErrorException );
+	long   CopyFromRecordset([in] any Data, [in]  any MaxRows , [in]  any MaxColumns) raises ( com::sun::star::script::BasicErrorException );
+	XPivotTable PivotTable();
 
 };
 

oovbaapi/ooo/vba/excel/makefile.mk

  	XVPageBreaks.idl \
  	TextFrame.idl \
 
+ 	XQueryTable.idl
 
 # ------------------------------------------------------------------
 

sc/source/ui/vba/makefile.mk

 		$(SLO)$/vbainterior.obj\
 		$(SLO)$/vbawsfunction.obj\
 		$(SLO)$/vbawindow.obj\
+		$(SLO)$/vbaquerytable.obj \
 		$(SLO)$/vbachart.obj\
 		$(SLO)$/vbachartobject.obj\
 		$(SLO)$/vbachartobjects.obj\

sc/source/ui/vba/vbaquerytable.cxx

+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright IBM Corporation 2009, 2010.
+ * 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.
+ *
+ ************************************************************************/
+
+#include "vbaquerytable.hxx"
+#include "document.hxx"
+#include "docsh.hxx"
+#include "sfx2/lnkbase.hxx"
+#include "svx/linkmgr.hxx"
+#include "arealink.hxx"
+#include "vbarange.hxx"
+
+using namespace com::sun::star;
+
+
+ScVbaQueryTable::ScVbaQueryTable(const css::uno::Reference< ov::XHelperInterface >& xParent, 
+								 const css::uno::Reference< css::uno::XComponentContext > & xContext,
+								 ScDocument *pDocument , 
+								 ScVbaRange *pParent
+								 )
+//:QueryTable_Base(xParent, xContext)
+{
+	m_pDocument = pDocument;
+	m_pParent = pParent;
+}
+
+ScVbaQueryTable::~ScVbaQueryTable()
+{
+
+}
+
+::sal_Bool SAL_CALL 
+ScVbaQueryTable::Refresh( const ::com::sun::star::uno::Any& aBackgroundQuery ) throw (::com::sun::star::uno::RuntimeException) 
+{
+	
+	//Get parent Info
+	sal_Int32 nRow = m_pParent->getRow();
+	sal_Int32 nClm = m_pParent->getColumn();
+	sal_Int16 nTab = m_pParent->getWorksheet()->getIndex() - 1; //The vba index begin from 1. 
+	ScAddress crrRngAddr(nClm, nRow, nTab);
+
+	//Get link info
+	SvxLinkManager *pLinkMng = m_pDocument->GetLinkManager();
+	const ::sfx2::SvBaseLinks &rLinks = pLinkMng->GetLinks();
+	USHORT nCount = rLinks.Count();
+
+	for (USHORT i=0; i<nCount; i++)
+	{
+		::sfx2::SvBaseLink* pBase = *rLinks[i];
+		if (pBase->ISA(ScAreaLink))
+		{
+		
+			ScAreaLink *pAreaLink = (ScAreaLink *)pBase;
+			const ScRange &destRange = pAreaLink->GetDestArea();
+			if (destRange.In(crrRngAddr))
+			{
+				pBase->Update();
+			}
+		}
+	}
+	
+	return sal_True;
+}
+
+

sc/source/ui/vba/vbaquerytable.hxx

+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright IBM Corporation 2009, 2010.
+ * 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 SC_VBA_QUERYTABLE_HXX
+#define SC_VBA_QUERYTABLE_HXX
+
+
+#include <ooo/vba/excel/XQueryTable.hpp>
+#include "vbahelper/vbahelperinterface.hxx"
+
+using namespace ::ooo::vba;
+typedef ::cppu::WeakImplHelper1<excel::XQueryTable> QueryTable_Base;
+
+class ScDocument;
+class ScVbaRange;
+
+class ScVbaQueryTable : public QueryTable_Base
+{
+private:
+	ScDocument *m_pDocument;
+	ScVbaRange *m_pParent;
+public:
+	ScVbaQueryTable(const css::uno::Reference< ov::XHelperInterface >& xParent, 
+		            const css::uno::Reference< css::uno::XComponentContext > & xContext,
+					ScDocument *pDocument = NULL, 
+					ScVbaRange *pParent = NULL
+					);
+	~ScVbaQueryTable();
+	virtual ::sal_Bool SAL_CALL Refresh( const ::com::sun::star::uno::Any& aBackgroundQuery ) 
+		throw (::com::sun::star::uno::RuntimeException);
+
+};
+
+#endif

sc/source/ui/vba/vbarange.cxx

 #include <com/sun/star/sheet/XSubTotalDescriptor.hpp>
 #include <com/sun/star/sheet/GeneralFunction.hdl>
 
+
+#include <com/sun/star/sheet/XDataPilotTable.hpp>
+#include <com/sun/star/sheet/XDataPilotTable2.hpp>
+#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
+#include <com/sun/star/sheet/DataPilotTablePositionData.hpp>
+#include <com/sun/star/sheet/DataPilotTablePositionType.hpp>
+
 #include <ooo/vba/excel/XlPasteSpecialOperation.hpp>
 #include <ooo/vba/excel/XlPasteType.hpp>
 #include <ooo/vba/excel/Constants.hpp>
 #include "vbaworksheet.hxx"
 #include "vbavalidation.hxx"
 
+#include "vbapivottable.hxx"
+
 #include "tabvwsh.hxx"
 #include "rangelst.hxx"
 #include "convuno.hxx"
 	}
 }
 
+//09-09-16 add by limingl
+::com::sun::star::uno::Reference< ::ooo::vba::excel::XQueryTable > SAL_CALL 
+ScVbaRange::getQueryTable() throw (::com::sun::star::uno::RuntimeException)
+{
+	/*
+	if (m_pQueryTable == NULL)
+	{
+		m_pQueryTable = new ScVbaQueryTable(mxParent ,mxContext, getScDocument(), this); //add by limingl
+	}
+	//*/
+	if (!m_xQueryTable.is())
+	{
+		m_xQueryTable = new ScVbaQueryTable(mxParent ,mxContext, getScDocument(), this); //add by limingl
+	}
+	
+	return m_xQueryTable;
+}
+//end add
 uno::Reference< excel::XRange > SAL_CALL 
 ScVbaRange::MergeArea() throw (script::BasicErrorException, uno::RuntimeException)
 {
     return new ScVbaRange( getParent(),mxContext,mxRange );
 }
 
+//2008-08-25 add by limingl
+//The recordset's member: Recordset.Fields.Item will get a Field obj. 
+//Field.value is the column value.
+::sal_Int32 SAL_CALL 
+ScVbaRange::CopyFromRecordset( const ::com::sun::star::uno::Any& Data,  const ::com::sun::star::uno::Any& MaxRows, const ::com::sun::star::uno::Any& MaxColumns ) 
+throw (::com::sun::star::script::BasicErrorException, ::com::sun::star::uno::RuntimeException)
+{
+ 	uno::Sequence< uno::Any > aParams;
+	uno::Sequence< uno::Any > aFieldsParams(1);
+ 	uno::Sequence< sal_Int16 > aOutParamIndex;
+ 	uno::Sequence< uno::Any > aOutParam;
+	uno::Reference< uno::XInterface > xIntRes;
+	uno::Reference< uno::XInterface > xIntFields;
+	uno::Reference< uno::XInterface > xIntFld;
+	uno::Any aRet;
+	uno::Any aPar;
+	uno::Any aCrrCol;
+	uno::Any aCrrRow;
+	sal_Int16 nCrrCol = 0;
+	sal_Int32 nCrrRow = 0;
+	sal_Int32  nCol;
+	sal_Int32 nMaxRows = 0;
+	sal_Int32 nMaxColumns = 0;
+	sal_Bool bEof;
+// 	sal_Bool bColName = sal_True;
+	long lColCnt = 0;
+	if (MaxColumns.hasValue())
+	{
+		MaxColumns >>= nMaxColumns;
+	}
+	
+	long lMaxCol = nMaxColumns;
+	
+	if (MaxRows.hasValue())
+	{
+		MaxRows >>= nMaxRows;
+	}
+	
+
+	Data >>= xIntRes;
+	uno::Reference< script::XInvocation > xInvRes(xIntRes, uno::UNO_QUERY_THROW);
+	rtl::OUString oMoveNext = rtl::OUString::createFromAscii("MoveNext") ;
+	rtl::OUString oEof  = rtl::OUString::createFromAscii("EOF") ;
+	rtl::OUString oFields  = rtl::OUString::createFromAscii("Fields") ;
+
+	if( !xInvRes->hasMethod(oMoveNext))
+	{
+		return -1;
+	}
+	
+	//Get columns count
+	aRet = xInvRes->getValue(oFields);
+	aRet >>= xIntFields;
+	uno::Reference< script::XInvocation > xInvFields(xIntFields, uno::UNO_QUERY_THROW);
+	aRet = xInvFields->getValue( rtl::OUString::createFromAscii("Count")) ;
+	aRet >>= lColCnt;
+
+	//Set the assign column number
+	if (lMaxCol != 0)
+	{
+		if (lColCnt > lMaxCol)
+		{
+			lColCnt = lMaxCol;
+		}		
+	}
+	
+	aCrrRow <<= nCrrRow;
+	aCrrCol <<= nCrrCol;
+
+
+	//Get start position
+	uno::Reference< excel::XRange > xRngStartRow = Rows(uno::Any(sal_Int32(1)) );
+	uno::Reference< excel::XRange > xRngPos = xRngStartRow->Columns( uno::Any(sal_Int32(1)) );
+
+	while(1)
+	{//travel recordset
+		//get every column
+		for (long l = 0; l < lColCnt ; l++)
+		{
+			nCol = l;
+			aPar <<= nCol;
+			//get every field
+			aRet = xInvFields->invoke( rtl::OUString::createFromAscii("Item"), uno::Sequence< uno::Any >(&aPar,1) , aOutParamIndex,aOutParam);
+			aRet >>= xIntFld;
+			uno::Reference< script::XInvocation > xInvFld(xIntFld, uno::UNO_QUERY_THROW); //Get the Field obj
+
+			//set the field value
+			aRet = xInvFld->getValue( rtl::OUString::createFromAscii("Value") );
+ 			uno::Reference< excel::XRange > xRngToFill = xRngPos->Offset(aCrrRow,aCrrCol );
+			
+			xRngToFill->setValue(aRet);
+			nCrrCol++;
+			aCrrCol <<= nCrrCol;
+		}
+		
+		aRet = xInvRes->invoke(oMoveNext, aParams,aOutParamIndex,aOutParam );
+		aRet = xInvRes->getValue(oEof);
+		aRet >>= bEof;
+		if (bEof || ( nCrrRow >= nMaxRows && nMaxRows != 0) )
+		{//Arrive the end of recordset
+			break;
+		}
+		
+ 		nCrrRow++;
+ 		aCrrRow <<= nCrrRow;
+		nCrrCol = 0;
+		aCrrCol <<= nCrrCol;
+	}
+
+	return 0;
+}
+//end add
 void SAL_CALL 
 ScVbaRange::PrintOut( const uno::Any& From, const uno::Any& To, const uno::Any& Copies, const uno::Any& Preview, const uno::Any& ActivePrinter, const uno::Any& PrintToFile, const uno::Any& Collate, const uno::Any& PrToFileName ) throw (uno::RuntimeException)
 {
 	}
 }
 
+//Add by minz@cn.ibm.com. Range.PivotTable.
+//Returns a PivotTable object that represents the PivotTable report containing the upper-left corner of the specified range.
+uno::Reference< excel::XPivotTable >
+ScVbaRange::PivotTable() throw (uno::RuntimeException)
+{
+	uno::Reference< excel::XPivotTable > xDestPVTable;
+
+	RangeHelper thisRange( mxRange );
+	uno::Reference< sheet::XSpreadsheet > xSheet = thisRange.getSpreadSheet();
+	uno::Reference< sheet::XDataPilotTablesSupplier > xTables(xSheet, uno::UNO_QUERY_THROW ) ;
+	uno::Reference< container::XIndexAccess > xIndexAccess( xTables->getDataPilotTables(), uno::UNO_QUERY_THROW );
+	if ( xIndexAccess.is() )
+	{
+		//get the upper-left cell address
+		uno::Reference< sheet::XCellAddressable > xCellAddr(mxRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW );
+		table::CellAddress aAddress = xCellAddr->getCellAddress();
+
+		sal_Int32 nCount = xIndexAccess->getCount();
+		for (sal_Int32 i=0; i < nCount; i++)
+		{
+			uno::Reference< sheet::XDataPilotTable > xDPTable(xIndexAccess->getByIndex(i), uno::UNO_QUERY);
+			uno::Reference< sheet::XDataPilotTable2 > xDPTable2(xDPTable, uno::UNO_QUERY);
+
+			//check if the cell is in the pivot table
+			sheet::DataPilotTablePositionData posData = xDPTable2->getPositionData(aAddress);
+			if( !(posData.PositionType == sheet::DataPilotTablePositionType::NOT_IN_TABLE) )
+			{
+				xDestPVTable = new ScVbaPivotTable( mxContext, xDPTable );
+				break;
+			}
+		}
+	}
+	return xDestPVTable;
+}
+
+
 rtl::OUString& 
 ScVbaRange::getServiceImplName()
 {

sc/source/ui/vba/vbarange.hxx

 #include <ooo/vba/excel/XFont.hpp>
 #include <ooo/vba/excel/XComment.hpp>
 #include <ooo/vba/XCollection.hpp>
+#include <ooo/vba/excel/XPivotTable.hpp>
 #include <ooo/vba/excel/XlPasteType.hdl>
 #include <ooo/vba/excel/XlPasteSpecialOperation.hdl>
 
 #include <com/sun/star/sheet/FillDirection.hpp>
 #include <com/sun/star/sheet/XSpreadsheet.hpp>
 #include <com/sun/star/sheet/XSheetCellRangeContainer.hpp>
+#include "vbaquerytable.hxx" //09-09-18 add by limingl
 
 //#include <vbahelper/vbahelperinterface.hxx>
 #include "vbaformat.hxx"
 	sal_Bool mbIsRows;
 	sal_Bool mbIsColumns;
 	css::uno::Reference< ov::excel::XValidation > m_xValidation;
+	css::uno::Reference<excel::XQueryTable> m_xQueryTable; //09-09-16 add by limingl
 	double getCalcColWidth( const css::table::CellRangeAddress& ) throw (css::uno::RuntimeException);
 	double getCalcRowHeight( const css::table::CellRangeAddress& ) throw (css::uno::RuntimeException);
 	void visitArray( ArrayVisitor& vistor );
 	//virtual void SAL_CALL setLocked(const css::uno::Any& aLocked) throw (css::script::BasicErrorException, css::uno::RuntimeException);	
 	virtual css::uno::Any SAL_CALL getShowDetail() throw (css::uno::RuntimeException);
 	virtual void SAL_CALL setShowDetail(const css::uno::Any& aShowDetail) throw (css::uno::RuntimeException);	
+	virtual ::com::sun::star::uno::Reference< ::ooo::vba::excel::XQueryTable > SAL_CALL getQueryTable() throw (::com::sun::star::uno::RuntimeException); //09-09-16 add by limingl
 	// Methods
 	sal_Bool IsRows() { return mbIsRows; }
 	sal_Bool IsColumns() { return mbIsColumns; }
 	virtual void SAL_CALL RemoveSubtotal(  ) throw (css::script::BasicErrorException, css::uno::RuntimeException);
 	virtual css::uno::Reference< ov::excel::XRange > SAL_CALL MergeArea() throw (css::script::BasicErrorException, css::uno::RuntimeException);
 	virtual void SAL_CALL Subtotal( ::sal_Int32 GroupBy, ::sal_Int32 Function, const css::uno::Sequence< ::sal_Int32 >& TotalList, const css::uno::Any& Replace, const css::uno::Any& PageBreaks, const css::uno::Any& SummaryBelowData ) throw (css::script::BasicErrorException, css::uno::RuntimeException);
+	
+	virtual css::uno::Reference< ov::excel::XPivotTable > SAL_CALL PivotTable(  ) throw (css::uno::RuntimeException);
+
+	virtual ::sal_Int32 SAL_CALL CopyFromRecordset( const ::com::sun::star::uno::Any& Data,  const ::com::sun::star::uno::Any& MaxRows, const ::com::sun::star::uno::Any& MaxColumns ) throw (::com::sun::star::script::BasicErrorException, ::com::sun::star::uno::RuntimeException); //2008-08-25 add by limingl
 	// XEnumerationAccess
 	virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException);
 	// XElementAccess