The following describes the way to add a function


+++ inc/compiler.hrc	2005-03-30 09:49:01.000000000 +0530
@@ -386,9 +386,10 @@
 #define	SC_OPCODE_CELL				385
 #define	SC_OPCODE_ISPMT				386
 #define	SC_OPCODE_HYPERLINK			387
-#define	SC_OPCODE_END_2_PAR			388
+#define SC_OPCODE_GETPIVOTDATA			388

The above code defines a function opcode.


diff -u -r ../../src680-m79.bak/sc/inc/opcode.hxx inc/opcode.hxx
--- ../../src680-m79.bak/sc/inc/opcode.hxx	2005-03-09 10:20:38.000000000 +0530
+++ inc/opcode.hxx	2005-03-30 11:40:11.457289727 +0530
@@ -414,7 +414,8 @@
 	// ab hier sind Extradaten drin
 		ocDataToken1		= SC_OPCODE_DATA_TOKEN_1,
 	// kein OpCode
-		ocNone				= SC_OPCODE_NONE
+		ocNone				= SC_OPCODE_NONE,
+		ocGetPivotData			= SC_OPCODE_GETPIVOTDATA

This is the internal way of using a opcode.

diff -u -r ../../src680-m79.bak/sc/inc/scfuncs.hrc inc/scfuncs.hrc
--- ../../src680-m79.bak/sc/inc/scfuncs.hrc	2005-03-09 10:20:37.000000000 +0530
+++ inc/scfuncs.hrc	2005-03-30 10:18:00.000000000 +0530
@@ -323,6 +323,7 @@
 #define HID_FUNC_TABELLE			(HID_SC_FUNC_DUMMY+(ID_FUNCTION_GRP_TABLE*ID_FUNCTION_OFFSET)+18)
 #define HID_FUNC_TABELLEN			(HID_SC_FUNC_DUMMY+(ID_FUNCTION_GRP_TABLE*ID_FUNCTION_OFFSET)+19)
 #define HID_FUNC_HYPERLINK			(HID_SC_FUNC_DUMMY+(ID_FUNCTION_GRP_TABLE*ID_FUNCTION_OFFSET)+20)
+#define HID_FUNC_GETPIVOTDATA			(HID_SC_FUNC_DUMMY+(ID_FUNCTION_GRP_TABLE*ID_FUNCTION_OFFSET)+21)

This defines the function GETPIVOTDATA under ID_FUNCTION_GRP_TABLE which is SpreadSheet tab


diff -u -r ../../src680-m79.bak/sc/source/core/inc/interpre.hxx source/core/inc/interpre.hxx
--- ../../src680-m79.bak/sc/source/core/inc/interpre.hxx	2005-03-09 10:21:07.000000000 +0530
+++ source/core/inc/interpre.hxx	2005-03-30 11:42:39.000000000 +0530
@@ -684,6 +684,7 @@
 void ScSTEXY();
 void ScSlope();
 void ScTrend();
+void ScGetPivotData();

This will  be function thatz called incase of the opcode ocGetPivotData

diff -u -r ../../src680-m79.bak/sc/source/core/src/compiler.src source/core/src/compiler.src
--- ../../src680-m79.bak/sc/source/core/src/compiler.src	2005-03-09 10:21:08.000000000 +0530
+++ source/core/src/compiler.src	2005-03-30 11:09:55.000000000 +0530
@@ -1692,6 +1692,11 @@
 		Text [ de ] = "HYPERLINK";
 		Text[ en-US ] = "HYPERLINK";
 	};
+	String SC_OPCODE_GETPIVOTDATA
+	{
+		Text [ de ] = "";
+		Text [ en-US ] = "GETPIVOTDATA" ;
+	};
 };
 Resource RID_SC_FUNCTION_NAMES_ENGLISH
 {
@@ -1987,5 +1992,6 @@
 	String SC_OPCODE_ROMAN { Text = "ROMAN" ; };
 	String SC_OPCODE_ARABIC { Text = "ARABIC" ; };
 	String SC_OPCODE_HYPERLINK { Text = "HYPERLINK" ; };
+	String SC_OPCODE_GETPIVOTDATA { Text = "GETPIVOTDATA" ; };
 };

This defines the text in resource file.



diff -u -r ../../src680-m79.bak/sc/source/core/tool/interpr4.cxx source/core/tool/interpr4.cxx
--- ../../src680-m79.bak/sc/source/core/tool/interpr4.cxx	2005-03-09 10:21:12.000000000 +0530
+++ source/core/tool/interpr4.cxx	2005-03-30 13:39:53.000000000 +0530
@@ -3530,6 +3530,7 @@
                 case ocTTT              : ScTTT();                      break;
                 case ocSpew             : ScSpewFunc();                 break;
                 case ocGame             : ScGame();                     break;
+		case ocGetPivotData	: ScGetPivotData();		break;
                 case ocNone : nFuncFmtType = NUMBERFORMAT_UNDEFINED;    break;
                 default : SetError(errUnknownOpCode); PushInt(0);       break;
             }

This is the place where the func is called incase of that opcode.



diff -u -r ../../src680-m79.bak/sc/source/ui/src/scfuncs.src source/ui/src/scfuncs.src
--- ../../src680-m79.bak/sc/source/ui/src/scfuncs.src	2005-03-09 10:20:52.000000000 +0530
+++ source/ui/src/scfuncs.src	2005-03-30 11:22:29.000000000 +0530
@@ -11015,6 +11015,74 @@
 			Text [ en-US ] = "The text that represents a Roman numeral.";
 		};
 	};
+        Resource SC_OPCODE_GETPIVOTDATA
+        {
+                String 1 // Description
+                {
+                        Text [ de ] = "" ;
+                        Text [ en-US ] = "Gets data from the pivot table.";
+                };
+                ExtraData =
+                {
+                        ID_FUNCTION_GRP_TABLE;
+                        U2S( HID_FUNC_GETPIVOTDATA );
+                        VAR_ARGS+2;      0;	0;	1;
+                };
+                String 2 // Name of Parameter 1
+                {
+                        Text [ de ] = "" ;
+                        Text [ en-US ] = "Data Field";
+                };
+                String 3 // Description of Parameter 1
+                {
+                        Text [ de ] = "" ;
+                        Text [ en-US ] = "The name of the field you want to retieve data from";
+                };
+                String 4 // Name of Parameter 2
+                {
+                        Text [ de ] = "" ;
+                        Text [ en-US ] = "Pivot Table";
+                };
+                String 5 // Description of Parameter 2
+                {
+                        Text [ de ] = "" ;
+                        Text [ en-US ] = "The reference to a cell in the Pivottable report that contains the data.";
+                };
+//              String 6 // Name of Parameter 3
+//              {
+//                      Text [ de ] = "" ;
+//                      Text [ en-US ] = "field1";
+//              };
+//              String 7 // Description of Parameter 3
+//              {
+//                      Text [ de ] = "" ;
+//                      Text [ en-US ] = "The name of the field that filters the data you want to retrieve";
+//              };
+//              String 8 // Name of Parameter 4
+//              {
+//                      Text [ de ] = "" ;
+//                      Text [ en-US ] = "Item1";
+//              };
+//              String 9 // Description of Parameter 4
+//              {
+//                      Text [ de ] = "" ;
+//                      Text [ en-US ] = "The value in the field that filters the data you want to retrieve.";
+//              };*/
+                String 6 // Name of Parameter 4
+                {
+                        Text [ de ] = "" ;
+                        Text [ en-US ] = "Field/Item ";
+                };
+                String 7 // Description of Parameter 4
+                {
+                        Text [ de ] = "" ;
+                        Text [ en-US ] = "Field name/value that filters the data you want to retrieve. ";
+                };
+
+
+
+        };
+	
 };

This is the schema of the func.. stating that 2 fixed and max of 30 variable params.
Will be refining the code later.. so ignore comments


diff -u -r ../../src680-m79.bak/sc/source/core/tool/interpr2.cxx source/core/tool/interpr2.cxx
--- ../../src680-m79.bak/sc/source/core/tool/interpr2.cxx	2005-03-09 10:21:12.000000000 +0530
+++ source/core/tool/interpr2.cxx	2005-03-30 16:24:58.860089755 +0530
@@ -2322,3 +2322,45 @@
         PushMatrix(pResMat);
     }
 }
+
+void ScInterpreter::ScGetPivotData()
+{
+    BYTE nParamCount = GetByte();
+    if (  nParamCount>= 2)
+    {
+	ScBaseCell* pCell;
+	ScAddress aCellAddress;
+	String aField; 
+	String aItem[15], aValue[15];
+	int i;
+}

This is the place where im processing the data to get the value..

Im using the filters approach.

Im getting the pivottable at cursor, copy to a new one. Create a new
ScQueryParam with the params passed and set that to the sheet and
query the reqd coln. THis is the approach. Looks like im partly
success...



