Summary:
I'm looking for a proper way to sort a 2D (multidimensional) array by the column sequence in AutoIt. I'm quite familiar with AutoIt and there is the _ArraySort
function which provides a sorting by columns which leads to sorted rows. But what I need is to sort the column order/sequence in column direction (in alphabetical way).
Background and goal:
For a test case report which I create (a HTML file), I need to display a table in it. This table should contain data of a part of the test case result.
What I already achieved is:
I read a CSV file into an array (by defined separator) which is not the problem. I can sort the 2D array for the row sequence and the parsing and convertion to HTML structure for the report is also not a problem.
But what I want to achieve is displayed in the example table at the bottom. Please notice that the example only contain example data. The real array content will have much more columns and rows in the array as test case result. But this should be enough for getting the idea.
Code:
That's just the example array data like below:
Global $a2dData[6][6]
$a2dData[0][0] = 'fruits'
$a2dData[0][1] = 'IT manufactures'
$a2dData[0][2] = 'painters'
$a2dData[0][3] = 'music genres'
$a2dData[0][4] = 'days'
$a2dData[1][0] = 'apple'
$a2dData[1][1] = 'Google'
$a2dData[1][2] = 'Picasso'
$a2dData[1][3] = 'Jazz'
$a2dData[1][4] = 'Monday'
$a2dData[2][0] = 'Orange'
$a2dData[2][1] = 'Microsoft'
$a2dData[2][2] = 'Van Gogh'
$a2dData[2][3] = 'Blues'
$a2dData[2][4] = 'Thursday'
$a2dData[3][0] = 'Pear'
$a2dData[3][1] = ''
$a2dData[3][2] = 'Da Vinci'
$a2dData[3][3] = 'Hip Hop'
$a2dData[3][4] = 'Friday'
$a2dData[4][0] = ''
$a2dData[4][1] = 'Apple'
$a2dData[4][2] = 'Monet'
$a2dData[4][3] = 'Rap'
$a2dData[4][4] = 'Sunday'
$a2dData[5][0] = 'Cherry'
$a2dData[5][1] = 'Adobe'
$a2dData[5][2] = 'Michelangelo'
$a2dData[5][3] = 'Classic'
$a2dData[5][4] = ''
_ArrayDisplay( $a2dData )
And now, how to sort the column sequence of 2D array in AutoIt?
Actual array data before sorting column sequence:
| fruits | IT manufactures | painters | music genres | days |
| apple | Google | Picasso | Jazz | Monday |
| Orange | Microsoft | Van Gogh | Blues | Thursday |
| Pear | | Da Vinci | Hip Hop | Friday |
| | Apple | Monet | Rap | Sunday |
| Cherry | Adobe | Michelangelo | Classic | |
Expected array data after sorting column sequence:
| days | fruits | IT manufactures | music genres | painters |
| Monday | apple | Google | Jazz | Picasso |
| Thursday | Orange | Microsoft | Blues | Van Gogh |
| Friday | Pear | | Hip Hop | Da Vinci |
| Sunday | | Apple | Rap | Monet |
| | Cherry | Adobe | Classic | Michelangelo |
Is there already a function to do that or do I have to do it on my own?
Does this fit your expectations?
#include <Array.au3>
Global $a2dData[6][5]
$a2dData[0][0] = 'fruits'
$a2dData[0][1] = 'IT manufactures'
$a2dData[0][2] = 'painters'
$a2dData[0][3] = 'music genres'
$a2dData[0][4] = 'days'
$a2dData[1][0] = 'apple'
$a2dData[1][1] = 'Google'
$a2dData[1][2] = 'Picasso'
$a2dData[1][3] = 'Jazz'
$a2dData[1][4] = 'Monday'
$a2dData[2][0] = 'Orange'
$a2dData[2][1] = 'Microsoft'
$a2dData[2][2] = 'Van Gogh'
$a2dData[2][3] = 'Blues'
$a2dData[2][4] = 'Thursday'
$a2dData[3][0] = 'Pear'
$a2dData[3][1] = ''
$a2dData[3][2] = 'Da Vinci'
$a2dData[3][3] = 'Hip Hop'
$a2dData[3][4] = 'Friday'
$a2dData[4][0] = ''
$a2dData[4][1] = 'Apple'
$a2dData[4][2] = 'Monet'
$a2dData[4][3] = 'Rap'
$a2dData[4][4] = 'Sunday'
$a2dData[5][0] = 'Cherry'
$a2dData[5][1] = 'Adobe'
$a2dData[5][2] = 'Michelangelo'
$a2dData[5][3] = 'Classic'
$a2dData[5][4] = ''
_ArrayDisplay($a2dData, 'BEFORE')
_ArrayTranspose($a2dData)
_ArraySort($a2dData)
_ArrayTranspose($a2dData)
_ArrayDisplay($a2dData, 'AFTER' )
So long, Mega