Repository navigation
Gradebook: Export list view scores as numeric percentage, score and max columns in Excel - #9279
Merged
ywarnier merged 1 commit intoOct 20, 2026
Conversation
…ax columns in Excel - Fixes chamilo#1642
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #9279 +/- ##
============================================
+ Coverage 17.13% 17.20% +0.06%
- Complexity 62160 62176 +16
============================================
Files 2522 2522
Lines 233279 233319 +40
============================================
+ Hits 39981 40133 +152
+ Misses 193298 193186 -112 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Gradebook: Export list view scores as numeric percentage, score and max columns in Excel
Fixes #1642
Problem
The Excel export of the Gradebook list view (Assessments → List view → "Export Excel",
/api/gradebook/export/flat.xls) writes each evaluation result, and the total, as one text cell,e.g.
6.00 / 10.00 (60.00%). Excel cannot sum, average or chart these values. #1642 asked to split theminto separate numbers, e.g.
0.90;18;20. Current master still exports one text cell.In 2017 the request was postponed to 2.0 because the 1.11 sheet had one column per student. The 3.x
list-view export has one row per learner, so the split is now simple.
Cause
GradebookExportServicebuilds a single table of strings (buildFlatTable()), shared by the CSV, DOCX,PDF and XLS exports.
createXlsResponse()then writes every cell withDataType::TYPE_STRING.Fix
Only the XLS export changes, in
src/CoreBundle/Service/Gradebook/GradebookExportService.php. CSV,DOCX and PDF keep their current layout.
buildFlatTable().<title> (Percentage): a fraction with the0.00%number format, so Excel shows 90.00% andcomputes with 0.9;
<title> (Score);<title> (Max score).sanitizeSpreadsheetValue(), the formula-injection guard.createXlsResponse()was only used by this export, so it is removed.Percentage,Score,Max score,TotalandRankingalready exist.How it was tested
The branch is rebased on master 26b01e9. All runs below are from Oct 20.
PHPUnit, new test
tests/CoreBundle/Service/Gradebook/GradebookExportServiceTest.php(
php bin/phpunit tests/CoreBundle/Service/Gradebook/GradebookExportServiceTest.php). It generates theXLS, reads it back with PhpSpreadsheet and checks:
TYPE_NUMERIC, with the right values and the percent format;With the fix:
OK (1 test, 22 assertions). With the service reverted to master: 1 failure(
Failed asserting that two arrays are identical, because the headers are stillQuiz 1,Total).PHPUnit, related existing tests:
tests/CoreBundle/Repository/GradebookCertificateExpiryTest.php: OK (7 tests).tests/CoreBundle/Api/GradebookLinkSecurityTest.php: 10 errors, allAccess denied for user 'root'@'localhost'. That comes from the local test-DB setup, not from thischange.
Playwright, new feature
tests/playwright/features/gradebookExcelExport.feature, plus 3 newgeneric steps in
common.steps.ts: open a path with a resolved course id, download from an icon link,and search the downloaded file.
GBXLS, subscribes and gradesnorizales, clicks "Export Excel"in the list view, checks that the downloaded file has the split headers, then deletes the course.
npx playwright test --config=tests/playwright/playwright.config.ts <spec> --retries=0 --workers=1"xlsexam (Percentage)" in the downloaded file), 2 passed.Playwright, existing Gradebook suite
toolAssessments.feature, run with the fix: 10/10 passed.It covers the PDF exports, among other things. With the new feature: 13/13 passed.
Static checks:
php -l: OK.vendor/bin/ecs checkon both PHP files: no findings.vendor/bin/phpstan analyse: no findings.vendor/bin/psalm --no-cacheon the service: clean.on master.
Security review
sanitizeSpreadsheetValue().is_numeric(), and are cast to float.Notes for reviewers
milestone 3.1.
single-column layout would need to be adapted.
are checked by the PHPUnit test.
common.steps.ts. Whichever ismerged second needs a trivial rebase.