1 package Koha
::Util
::OpenDocument
;
3 # Copyright 2019 Biblibre
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use Encode
qw( decode );
24 use File
::Basename
qw( dirname );
25 use OpenOffice
::OODoc
;
27 use parent
qw( Exporter );
35 Koha::Util::OpenDocument - utility class to manage filed in Open Document Format aka OpenDocument
41 Generate an Open Document Sheet
43 Arguments are file path and content as an arrayref of lines containing arrayrefs of cells.
49 my ( $filepath, $content ) = @_;
51 unless ( $filepath && $content ) {
54 my @input_rows = @
$content;
55 my $nb_rows = scalar @input_rows;
58 $nb_cols= scalar @
{ $input_rows[0] };
62 my $wdir = dirname
($filepath);
63 odfWorkingDirectory
($wdir);
64 my $odf_doc = odfDocument
( file
=> $filepath, create
=> 'spreadsheet' );
68 my $odf_sheet = $odf_doc->expandTable( 0, $nb_rows + 1, $nb_cols );
69 my @odf_rows = $odf_doc->getTableRows($odf_sheet);
72 for ( my $i = 0 ; $i < $nb_rows ; $i++ ) {
73 for ( my $j = 0 ; $j < $nb_cols ; $j++ ) {
74 my $cellval = $input_rows[$i][$j];
75 $odf_doc->cellValue( $odf_rows[$i], $j, $cellval );
91 Koha Development Team <http://koha-community.org/>
93 Fridolin Somers <fridolin.somers@biblibre.com>