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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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>