Skip to content

Commit

Permalink
Merge pull request #2 from red-freak/develop
Browse files Browse the repository at this point in the history
Some MarkUp
  • Loading branch information
red-freak authored Nov 5, 2022
2 parents 1e0b289 + a65b546 commit 4118290
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
APP_NAME="MAXQDA HTML to Excel"
APP_NAME="MAXQDA-Paraphrase-Matrix HTML to Excel"
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=https://maxqda-html-to-excel.test
APP_URL=https://maxqda-paraphrase-matrix_html-to-excel.test

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
Expand Down
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# MAXQDA HTML to Ecel
# MAXQDA-Paraphrase-Matrix HTML to Excel
The aim of this project is to create a propper excel-file from the html output of the paraphrases.

The project does not need a database-server. It is able to work ith SQLite.
Expand All @@ -7,7 +7,19 @@ The project does not need a database-server. It is able to work ith SQLite.
- Laravel 8
- spatie/simple-excel
- PHP 8.1
- SQLite
- SQLite (or any other database)

## How to use
1. clone the project
2. setup your environment (no server needed)
3. Export MAXQDA Paraphrases as HTML ([see MAXQDA-FAQ](https://www.maxqda.de/hilfe-mx20/12-paraphrasieren/paraphrasen-matrix))
4. copy the HTML-file(s) into the `storage/sources`-folder
5. run `php artisan maxqda:import`
6. run `php artisan maxqda:export`
7. the excel-file is in the `storage/exports`-folder

## tested with
- MAXQDA 2022

## Licence
This package is free to use as stated by the [LICENCE.md](LICENSE.md) under the MIT License, but you can [buy me a coffee](https://www.buymeacoffee.com/redFreak) if you want :D.
56 changes: 48 additions & 8 deletions app/Console/Commands/ExcelExportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use OpenSpout\Writer\Common\Creator\Style\StyleBuilder;
use Spatie\SimpleExcel\SimpleExcelWriter;
use Str;
use Symfony\Component\Console\Helper\ProgressBar;

class ExcelExportCommand extends Command
{
Expand Down Expand Up @@ -54,14 +55,19 @@ public function handle()
->setShouldWrapText()
->setBackgroundColor(Color::LIGHT_BLUE)
->build();

$simpleExcelWriter->setHeaderStyle($style);

$interviews = Interview::all();
$interview_last = $interviews->last();

$interviews->each(function (Interview $interview) use ($writer, $simpleExcelWriter, $interview_last) {
// initialize the progress bar
$bar = $this->initializeProgressBar($interviews);

$interviews->each(function (Interview $interview) use ($writer, $simpleExcelWriter, $interview_last, $bar) {
// set the interview name as sheet name
$writer->getCurrentSheet()->setName($interview->id);
$bar->setMessage('Exporting interview ' . $interview->id . '...');

// collect and sort the data
$editors = $interview->editors->unique();
Expand All @@ -78,13 +84,16 @@ public function handle()
$simpleExcelWriter->addRow($rowData);

++$row;
$bar->advance();
} while (true);

if (!$interview->is($interview_last)) {
$writer->addNewSheetAndMakeItCurrent();
}
});

$this->finishProgressBar($bar);

return Command::SUCCESS;
}

Expand Down Expand Up @@ -133,13 +142,15 @@ private function getEditorIterators(SupportCollection $paraphrasesByEditor): Sup
});

return $editorIterators;
}/**
* @param int $row
* @param EloquentCollection $editors
* @param SupportCollection $editorIterators
*
* @return array
*/
}

/**
* @param int $row
* @param EloquentCollection $editors
* @param SupportCollection $editorIterators
*
* @return array
*/
private function getRowData(int $row, EloquentCollection $editors, SupportCollection $editorIterators): array
{
$rowData = [
Expand Down Expand Up @@ -246,4 +257,33 @@ private function getParaphraseCells(

return $rowData;
}

/**
* @param EloquentCollection $interviews
*
* @return ProgressBar
*/
private function initializeProgressBar(EloquentCollection $interviews): ProgressBar
{
$this->info('Exporting paraphrases to Excel...');
$this->newLine();
$paraphrasesCount = Paraphrase::whereIn('interview_id', $interviews->pluck('id'))->count();
$bar = $this->output->createProgressBar($paraphrasesCount);
$bar->start();
$bar->setFormat("<fg=green>%message%</>\n %current%/%max% [%bar%] %percent:3s%%");

return $bar;
}

/**
* @param ProgressBar $bar
*
* @return void
*/
private function finishProgressBar(ProgressBar $bar): void
{
$bar->setMessage('Exporting finished.');
$bar->finish();
$this->newLine(2);
}
}
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "laravel/laravel",
"name": "red-freak/maxqda-paraphrase-matrix_html-to-excel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"description": "Convert MAXQDA-Paraphrase-Matrix-HTML to an Excel-format that makes sense.",
"keywords": ["framework", "laravel", "MAXQDA", "Paraphrase-Matrix", "Excel", "HTML"],
"license": "MIT",
"require": {
"php": "^8.1",
Expand Down

0 comments on commit 4118290

Please sign in to comment.