Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Attempting to sort from multiple arrays and input into Excel

$
0
0

I have been working on a project for an insurance customer to connect to an Oracle db and pull a bunch of policy holder info. They would then like the data placed into an Excel spreadsheet. Unfortunately, because the data sets that I need to work from will be different each time, I'm finding it difficult to fulfill the objectives.

 

1. I pull the data from the database and plug it into a temp excel spreadsheet, performing some minor formatting. The temp worksheet looks like this:

 

1.png

 

2. I create an array of unique effective dates, and an array of unique class codes. Always 7 effective dates (not always the same dates), but anywhere from 1 to 16 Class Codes. These numbers are then plugged into the Master worksheet:

 

2.png

 

3. I then need to iterate through each row in the temp worksheet. I need to plug the sum value into the correct cell, by both the class code and the effective date. I was able to create something that works very well (below), but only when I know the value and number of class codes:

AutoIt         
  1.     $b = 32
  2.     $c = 32
  3.  
  4.     For $i = 2 To 500
  5.         $ccode = _ExcelReadCell($oExcel, $i, 1)
  6.             Select
  7.                 Case $ccode = ""
  8.                     ExitLoop
  9.                 Case $ccode = "0042"
  10.                     $line = $b
  11.                     $effDate = _ExcelReadCell($oExcel, $i, 5)
  12.                     $sum = _ExcelReadCell($oExcel, $i, 3)
  13.                     _ExcelWriteCell($oExcel1, $effDate, $b, 1)
  14.                     _ExcelWriteCell($oExcel1, $sum, $b, 3)
  15.                     $b += 1
  16.                 Case $ccode = 5183
  17.                     $line1 = $b
  18.                     $effDate = _ExcelReadCell($oExcel, $i, 5)
  19.                     $sum = _ExcelReadCell($oExcel, $i, 3)
  20.                     _ExcelWriteCell($oExcel1, $effDate, $c, 1)
  21.                     _ExcelWriteCell($oExcel1, $sum, $c, 4)
  22.                     $c += 1
  23.             EndSelect
  24.     Next
  25.  
  26.     _ExcelBookSaveAs($oExcel1, @DesktopDir & "\Output.xls", "xls", 0, 1)

I'm guessing I would need to do something like this, but have yet to get it to work:

 

   Start with the array of class codes.

   Loop through each row in the temp workbook.

   On each row, find the effective date and jump to that row in the Master Workbook.

   On each row, find the class code and jump to that column in the Master Workbook.

   Write that row's SUM value to the corresponding cell in the Master Workbook.

 

Any suggestions would be greatly appreciated, or if there is another way to do this logically.


Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>