Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

excel format problem

by mark4444az (Sexton)
on Sep 03, 2014 at 16:58 UTC ( [id://1099433]=perlquestion: print w/replies, xml ) Need Help??

mark4444az has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I have an issue where I am writing a hex value to an Excel spreadsheet and it looks like when there's an "e" in the number the Excel is changing it to Scientific Notation. So this number:83834e82 gets changed in Excel to:8.3834E+82. As I understand it Excel should default to General format, even still I added some code:
my $right = $workbook->add_format(align => 'right'); my $num_format = $workbook->add_format(); $num_format->set_num_format('general');
And when I do the actual write:
$worksheet1->write($row_num, $col_num, $hex_data, $right, $num_format) +; <
Has anyone else encountered this?

Replies are listed 'Best First'.
Re: excel format problem
by choroba (Cardinal) on Sep 03, 2014 at 17:13 UTC
    How should Excel know the value is a hex number? Use hex:
    $worksheet1->write($row_num, $col_num, hex $hex_data, $right, $num_for +mat);
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: excel format problem
by AppleFritter (Vicar) on Sep 03, 2014 at 17:14 UTC
    Can't say I've ever worked with Excel, so this is just a random stab in the dark, but - have you tried formatting your number as 0x83834e82 or 83834e82h? Maybe that'll help.
      I don't think this will work, but, on the other hand, Excel has a HEXDEC conversion function which might work. But I really think that converting the hex number into decimal notation in Perl prior to loading it to Excel, as suggested by choroba will be much easier.

        Excel's hex converter certainly used to be limited to numbers less then 512. I also believe that the OP is using Spreadsheet::WriteExcel or something from that stable rather than Win32::OLE, otherwise I would rush my BigInt xla out & suggest he used that, but I understand that it's a problem importing modules into Excel files using S:WE or its derivatives.

        Regards,

        John Davies

Re: excel format problem
by bulrush (Scribe) on Sep 04, 2014 at 19:23 UTC
    Spreadsheet::WriteExcel write() function makes a guess as to what kind of data you are writing. For the hex data, do not use write(), and instead write it as a string with: write_string($row, $column, $string, $format).

    Perl 5.8.8 on Redhat Linux RHEL 5.5.56 (64-bit)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1099433]
Approved by AppleFritter
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-23 18:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found