[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice
Subject:    kspread
From:       Tony =?iso-8859-1?q?Bj=F6rkenius?= <tony.bjorkenius () linux ! nu>
Date:       2001-04-24 20:53:04
[Download RAW message or body]

Hello

I have written a findrow and findcol function for kspread, see diffs made 
against koffice 1.1 beta1.

I'm not sure I have done it the right way since this is my first attempt at 
coding for koffice, but it works for me :)

// Tony

["kspread_interpreter.cc.diff" (text/plain)]

--- kspread/kspread_interpreter.cc.org	Wed Apr 25 00:21:28 2001
+++ kspread/kspread_interpreter.cc	Wed Apr 25 00:00:09 2001
@@ -569,6 +569,95 @@
   return true;
 }
 
+static bool kspreadfunc_findrow( KSContext& context )
+{
+  QValueList<KSValue::Ptr>& args = context.value()->listValue();
+
+  if ( !KSUtil::checkArgumentsCount( context, 3, "findrow", true ) )
+    return false;
+
+  if ( !KSUtil::checkType( context, args[0], KSValue::StringType, true ) )
+    return false;
+
+  if ( !KSUtil::checkType( context, args[1], KSValue::ListType, true ) )
+    return false;
+
+  if ( !KSUtil::checkType( context, args[2], KSValue::IntType, true ) )
+    return false;
+
+  QValueList<KSValue::Ptr>::Iterator it = args[1]->listValue().begin();
+  QValueList<KSValue::Ptr>::Iterator end = args[1]->listValue().end();
+
+  QString str;
+
+  QValueList<KSValue::Ptr>::Iterator it2;
+  QValueList<KSValue::Ptr>::Iterator end2;
+
+  for (;it != end; ++it) {
+    it2 = (*it)->listValue().begin();
+    end2 = (*it)->listValue().end();
+    
+    if (args[0]->cmp( (*(*it2)))) {
+      for (int i = args[2]->intValue();i > 0 && it2 != end2; i--)
+	it2++;
+      if (it2==end2)
+	return false;
+      context.setValue( new KSValue( (*(*it2)) ) );
+      return true;
+    }
+  }
+  return false;
+}
+
+static bool kspreadfunc_findcol( KSContext& context )
+{
+  QValueList<KSValue::Ptr>& args = context.value()->listValue();
+
+  if ( !KSUtil::checkArgumentsCount( context, 3, "findcol", true ) )
+    return false;
+
+  if ( !KSUtil::checkType( context, args[0], KSValue::StringType, true ) )
+    return false;
+
+  if ( !KSUtil::checkType( context, args[1], KSValue::ListType, true ) )
+    return false;
+
+  if ( !KSUtil::checkType( context, args[2], KSValue::IntType, true ) )
+    return false;
+
+  QValueList<KSValue::Ptr>::Iterator it = args[1]->listValue().begin();
+  QValueList<KSValue::Ptr>::Iterator end = args[1]->listValue().end();
+
+  QString str;
+
+  QValueList<KSValue::Ptr>::Iterator it2;
+  QValueList<KSValue::Ptr>::Iterator end2;
+
+  it2 = (*it)->listValue().begin();
+  end2 = (*it)->listValue().end();
+  
+  int pos=0;
+  for ( ; it2 != end2; ++it2) {
+    if (args[0]->cmp( (*(*it2))))
+      break;
+    pos++;
+  }
+  if (it2 == end2)
+    return false;
+      
+  for(int i = args[2]->intValue(); i > 0 && it != end; i--)
+    it++;
+  if (it==end)
+    return false;
+  
+  it2 = (*it)->listValue().begin();
+  for (;pos > 0; pos--)
+    it2++;
+
+  context.setValue( new KSValue( (*(*it2)) ) );
+  return true;
+}
+
 static bool kspreadfunc_degree( KSContext& context )
 {
   QValueList<KSValue::Ptr>& args = context.value()->listValue();
@@ -4354,6 +4443,8 @@
   module->addObject( "weeksInYear", new KSValue( new KSBuiltinFunction( module, \
"weeksInYear", kspreadfunc_weeksInYear) ) );  module->addObject( "seconds", new \
KSValue( new KSBuiltinFunction( module, "seconds", kspreadfunc_seconds) ) );  \
module->addObject( "ROMAN", new KSValue( new KSBuiltinFunction( module, "ROMAN", \
kspreadfunc_roman) ) ); +  module->addObject( "findrow", new KSValue( new \
KSBuiltinFunction( module, "findrow", kspreadfunc_findrow) ) ); +  module->addObject( \
"findcol", new KSValue( new KSBuiltinFunction( module, "findcol", \
kspreadfunc_findcol) ) );  return module;
 }
 


["builtin.xml.diff" (text/plain)]

--- kspread/extensions/builtin.xml.org	Wed Apr 25 00:21:58 2001
+++ kspread/extensions/builtin.xml	Wed Apr 25 00:05:43 2001
@@ -789,6 +789,50 @@
     <GroupName>Text</GroupName>
 
     <Function>
+      <Name>findrow</Name>
+      <Type>String</Type>
+      <Parameter>
+        <Comment>Search string</Comment>
+ 	<Type>String</Type>
+      </Parameter>
+      <Parameter>
+        <Comment>Range</Comment>
+	<Type>Range</Type>
+      </Parameter>
+      <Parameter>
+        <Comment>Index</Comment>
+ 	<Type>Int</Type>
+      </Parameter>
+      <Help>
+ 	<Text>The findrow funktion search the first item in every row in a range and \
returns the value in cell index columns to the right</Text> + \
<Syntax>findrow(String;Range;Int)</Syntax> + 	<Example>findrow("Test";B2:D6;2) \
returns cell(D2) if B2="Test"</Example> +      </Help>
+    </Function>
+       
+    <Function>
+      <Name>findcol</Name>
+      <Type>String</Type>
+      <Parameter>
+        <Comment>Search string</Comment>
+ 	<Type>String</Type>
+      </Parameter>
+      <Parameter>
+        <Comment>Range</Comment>
+ 	<Type>Range</Type>
+      </Parameter>
+      <Parameter>
+        <Comment>Index</Comment>
+	<Type>Int</Type>
+      </Parameter>
+      <Help>
+        <Text>The findcol funktion search the first item in every column in a range \
and returns the value in cell index rows below</Text> + \
<Syntax>findcol(String;Range;Int)</Syntax> + 	<Example>findcol("Test";B2:D6;2) \
returns cell(D4) if D2="Test"</Example> +      </Help>
+    </Function>
+       
+    <Function>
       <Name>EXACT</Name>
       <Type>Boolean</Type>
       <Parameter>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic