Eu converti os arquivos para csv e usei um script PHP para analisar o conteúdo, criando o que eu queria. O resultado foi salvo em um novo arquivo, em seguida, esses arquivos foram convertidos novamente em xls e depois mesclados em um bloco de anotações.
A parte de conversão e mesclagem foi feita manualmente. Não é a melhor solução, mas está funcionando por enquanto.
Aqui está o script:
// get list of files from data directory
$files = array_diff(scandir('./data'), array('.', '..'));
foreach($files as $file):
// get all data from the csv file and save in the $data array
$csvFile = file('data/'.$file);
$data = $list = [];
foreach($csvFile as $line) {
$data[] = str_getcsv($line);
}
unset($data[0]);
// parse the data array and get the different sections: name. date and time
foreach($data as $v) {
$date = strtotime($v[1]);
$list[date('d-m-Y',$date)][] = array(
'name'=>$v[0],
'date'=>date('d/m/Y',$date),
'in'=>$date
);
}
// create a new array and save parsed data in it with header columns
$new = array(array('Name','Date','Time In','Time Out'));
foreach($list as $k => $v) {
$out = max(array_column($v, 'in'));
$name = $v[0]['name'];
$new[] = array(
'name'=>ucwords(strtolower($name)),
'date'=>$v[0]['date'],
'in'=>date('h:i A', $v[0]['in']),
'out'=>date('h:i A', $out)
);
}
// The name of a new file in the new directory using this file name
$filename = str_replace('.csv', '', basename($file));
$fn = strtolower($filename.'-log.csv');
// open the file and output the new array as CSV
$out = fopen('new/'.$fn, 'w');
foreach($new as $l) {
fputcsv($out, $l, ",",'"');
}
fclose($out);
endforeach;