Bug 22220: Fix bib Apache rewrite rule for intranet
[koha.git] / Koha / Util / OpenDocument.pm
blob0fc807236ace3927719ac0dc5ce925979300ca54
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
10 # version.
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.
20 use Modern::Perl;
22 use Encode qw( decode );
23 use File::Temp;
24 use File::Basename qw( dirname );
25 use OpenOffice::OODoc;
27 use parent qw( Exporter );
29 our @EXPORT = qw(
30 generate_ods
33 =head1 NAME
35 Koha::Util::OpenDocument - utility class to manage filed in Open Document Format aka OpenDocument
37 =head1 METHODS
39 =head2 generate_ods
41 Generate an Open Document Sheet
43 Arguments are file path and content as an arrayref of lines containing arrayrefs of cells.
45 =cut
48 sub generate_ods {
49 my ( $filepath, $content ) = @_;
51 unless ( $filepath && $content ) {
52 return;
54 my @input_rows = @$content;
55 my $nb_rows = scalar @input_rows;
56 my $nb_cols;
57 if ($nb_rows) {
58 $nb_cols= scalar @{ $input_rows[0] };
61 # Create document
62 my $wdir = dirname($filepath);
63 odfWorkingDirectory($wdir);
64 my $odf_doc = odfDocument( file => $filepath, create => 'spreadsheet' );
66 if ($nb_rows) {
67 # Prepare sheet
68 my $odf_sheet = $odf_doc->expandTable( 0, $nb_rows + 1, $nb_cols );
69 my @odf_rows = $odf_doc->getTableRows($odf_sheet);
71 # Writing
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 );
80 # Done
81 $odf_doc->save();
83 return $odf_doc;
87 __END__
89 =head1 AUTHOR
91 Koha Development Team <http://koha-community.org/>
93 Fridolin Somers <fridolin.somers@biblibre.com>
95 =cut