From 7edaba25d943bf4967e59a65195e4bfc386f886d Mon Sep 17 00:00:00 2001 From: Olivia Reynolds Date: Fri, 12 Jun 2026 14:45:57 +0000 Subject: [PATCH] Bug 12757: Set float type on OpenDocument cells Test plan: 1. Navigate to Reports > Create from SQL. 2. Create a new report with a name and the following SQL query: SELECT 'test', 1, '2' 3. Run the report. 4. Under the Download dropdown, select "Open Document Spreadsheet". 5. Verify a ".ods" file is downloaded. 6. Open the downloaded spreadsheet. 7. Verify the two number-like columns are handled as such. This depends on your choice of spreadsheet software: - In Excel, the numbers should not have a leading single quote in the edit-bar when selected. - In Google Sheets, the numbers should be right-aligned, and selecting both of them should display their sum in the bottom toolbar. 8. Run `prove t/Koha/Util/OpenDocument.t` and verify all tests were successful. Sponsored-by: Open Fifth Signed-off-by: David Nind Signed-off-by: Lucas Gass --- Koha/Util/OpenDocument.pm | 2 ++ t/Koha/Util/OpenDocument.t | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Koha/Util/OpenDocument.pm b/Koha/Util/OpenDocument.pm index ac9cbc60e9..1269fe2c0d 100644 --- a/Koha/Util/OpenDocument.pm +++ b/Koha/Util/OpenDocument.pm @@ -21,6 +21,7 @@ use Modern::Perl; use File::Basename qw( dirname ); use OpenOffice::OODoc qw( odfDocument odfWorkingDirectory ); +use Scalar::Util qw(looks_like_number); use parent qw( Exporter ); @@ -70,6 +71,7 @@ sub generate_ods { for ( my $i = 0 ; $i < $nb_rows ; $i++ ) { for ( my $j = 0 ; $j < $nb_cols ; $j++ ) { my $cellval = $input_rows[$i][$j]; + $odf_doc->cellValueType( $odf_rows[$i], $j, 'float' ) if looks_like_number($cellval); $odf_doc->cellValue( $odf_rows[$i], $j, $cellval ); } } diff --git a/t/Koha/Util/OpenDocument.t b/t/Koha/Util/OpenDocument.t index 0d41325ff1..4ccc919a12 100755 --- a/t/Koha/Util/OpenDocument.t +++ b/t/Koha/Util/OpenDocument.t @@ -19,7 +19,7 @@ use Modern::Perl; use File::Temp qw/tempfile/; use Test::NoWarnings; -use Test::More tests => 5; +use Test::More tests => 7; BEGIN { use_ok('Koha::Util::OpenDocument'); } @@ -40,4 +40,6 @@ $filepath = $fh2->filename; my $content2 = [ [ 'A', 'B' ], [ '1', '2' ] ]; $ret = generate_ods( $filepath, $content2 ); ok( defined $ret, 'Call generate_ods with 2x2 content' ); +is( $ret->cellValueType( 0, 0, 0 ), 'string', 'Text cells have string type' ); +is( $ret->cellValueType( 0, 1, 0 ), 'float', 'Number cells have float type' ); close $fh2;