Advertisement
ramkesheoran

Job Multiply two matrix data from excel

Dec 23rd, 2011
2,943
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XPP 2.53 KB | None | 0 0
  1. static void Mat_Multiply(Args _args)
  2. {
  3.     CCADOConnection  adoConnection;
  4.     CCADOCommand    adoCommand,adoCommands2;
  5.     CCADORecordSet   adoRecordSet,adoRecordSets2;
  6.     CCADOFields      adoFields,adoFields2;
  7.     CCADOField       adoField;
  8.     int               i,j,k,mno1,mno2,mul;
  9.     int               noofrows1,noofcols1, noofrows2,noofcols2;
  10.     ;
  11.  
  12.     adoConnection = new CCADOConnection();
  13.     adoRecordSet = new CCADORecordSet();
  14.     adoConnection.open("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + 'D:\Testing.xlsx' + ";Extended Properties='Excel 12.0;HDR=No;IMEX=1'"); // for excel 2010
  15.     adoCommand = new CCADOCommand();
  16.     adoCommand.activeConnection(adoConnection);
  17.     adoCommand.commandText(@"SELECT * FROM [SHEET1$]");
  18.     adoRecordSet = adoCommand.execute();
  19.     adoCommands2 = new CCADOCommand();
  20.     adoCommands2.activeConnection(adoConnection);
  21.     adoCommands2.commandText(@"SELECT * FROM [SHEET2$]");
  22.     adoRecordSets2 = adoCommands2.execute();
  23.         //Calculate rows and columns
  24.         noofcols1 = adoRecordSet.fields().count();
  25.         while(!adoRecordSet.EOF())
  26.         {
  27.         adoRecordSet.recordSet().MoveNext();
  28.         noofrows1++;
  29.         }
  30.         noofcols2 = adoRecordSets2.fields().count();
  31.         while(!adoRecordSets2.EOF())
  32.         {
  33.         adoRecordSets2.recordSet().MoveNext();
  34.         noofrows2++;
  35.         }
  36.         //Calculate rows and columns
  37.         if(noofcols1==noofrows2)
  38.         {
  39.         adoCommand.commandText(@"SELECT * FROM [SHEET1$]");
  40.         adoRecordSet = adoCommand.execute();
  41.         adoCommands2.commandText(@"SELECT * FROM [SHEET2$]");
  42.         adoRecordSets2 = adoCommands2.execute();
  43.         adoFields = adoRecordSet.fields();
  44.         adoFields2 = adoRecordSets2.fields();
  45.  
  46.         for(i=0;i<noofrows1;i++)
  47.         {
  48.             for(j=0;j<noofcols1;j++)
  49.             {
  50.                 mul = 0;
  51.                 for(k=0;k<noofrows2;k++)
  52.                 {
  53.                  mno1=adoFields.itemIdx(k).value();
  54.                  mno2 = adoFields2.itemIdx(j).value();
  55.                  mul+=mno1*mno2;
  56.                  adoRecordSets2.recordSet().moveNext();
  57.                 }
  58.  
  59.                 adoCommands2.commandText(@"SELECT * FROM [SHEET2$]");
  60.                 adoRecordSets2 = adoCommands2.execute();
  61.                  adoFields2 = adoRecordSets2.fields();
  62.                  print mul;
  63.             }
  64.              adoRecordSet.recordSet().moveNext();
  65.         }
  66.          pause;
  67.      }
  68.      else
  69.      {
  70.         info("Mul not possible");
  71.      }
  72.    
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement