In that snippet, 12 will come before 2 because it's doing an ASCII sort. Not very appealing, and all too familiar. By overriding the default cell value type to floating point numbers, we can get the cells to sort properly.use strict; use warnings; use OpenOffice::OODoc; my $ods_doc = odfDocument(file => 'somefile.ods', create => 'spreadsheet',); # Set table to desired size my $sheet = 0; # First sheet in the file. my $num_rows = 3; my $num_cols = 1; # <- really small spreadsheet. $ods_doc->expandTable($sheet, $num_rows, $num_cols); # If you only need the cell to contain a text string, than # all you have to do is write to it, that's the default. $ods_doc->updateCell($sheet, 0, 0, "The title of the column"); # Even though we're writing a number, it will be escaped # as a string because we haven't change the format of # the cell. $ods_doc->updateCell($sheet, 1, 0, 2); $ods_doc->updateCell($sheet, 2, 0, 12); $ods_doc->save;
I hope you have found this witty and informative.# &c as above. my $cell = $ods_doc->getCell($sheet, 1, 0); $ods_doc->cellValueType($cell, 'float'); $ods_doc->updateCell($sheet, 1, 0, 2); $cell = $ods_doc->getCell($sheet, 2, 0); $ods_doc->cellValueType($cell, 'float'); $ods_doc->updateCell($sheet, 2, 0, 12); $ods_doc->save;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Changing the cell value to a numeric type using OpenOffice::OODoc
by alexander_lunev (Pilgrim) on Jun 17, 2022 at 06:31 UTC |