#!/usr/bin/perl use strict; use DBI; use Spreadsheet::WriteExcel; my $listId; my $p_filename; $listId = shift; $p_filename = shift; use constant C_HEADING => 0; use constant C_WIDTH => 1; my @columns = ( ['AgentID', 10 ], ['Question1', 20 ], ['Question2', 20 ], ['Question3', 11 ], ['Question4', 11 ], ['Question5', 24 ], ['Question6', 11 ], ['Question7', 22 ], ['Question8', 22 ] ); my $workbook = Spreadsheet::WriteExcel->new($p_filename); my $sheet = $workbook->add_worksheet("Data"); my $default_format = $workbook->add_format(num_format => '@'); $defau +lt_format->set_font('Verdana'); $default_format->set_border(1); my $bold_format = $workbook->add_format(); $bold_format->set_font( +'Verdana'); $bold_format->set_bold(); $bold_format->set_border(1); $sheet->write(0,$_,$columns[$_]->[C_HEADING], $bold_format) for (0..$# +columns); $sheet->set_column($_, $_, $columns[$_]->[C_WIDTH]) for (0..$#columns) +; my $dbh = DBI->connect("DBI:ODBC:Driver={SQL Server};Server=server;Dat +abase=database;Trusted_Connection=Yes") or die("\n\nCONNECT ERROR:\n\ +n$DBI::errstr"); my $sth = $dbh->prepare(<<EOQ SELECT Custom1 AS AgentID, Custom13 AS Question1, Custom14 AS Question +2, Custom15 AS Question3, Custom16 AS Question4, Custom17 AS Question +5, Custom18 AS Question6, Custom19 AS Question7, Custom20 AS Question +8 FROM [purl].[dbo].[MailFiles] WHERE ListId='$listId' AND Completed ='1' EOQ ); $sth->execute(); my $i = 1; my $row; while ( $row = $sth->fetchrow_arrayref ) { $sheet->write_string($i,$_,$row->[$_], $default_format) for (0..$# +$row); $i++; } $sheet->activate(); exit;

I wrote this code to connect to a database and retrieve 9 columns my columns will have this values AgentID = 1234 Question1 = strongly agree Question2 = agree Question3 = strongly disagree Question4 = etc Question5 =etc Question6 =etc Question7 =etc Question8 = etc

I need to change the value of the questions from string to numeric

Strongly Agree – 5 Agree – 4 Neutral – 3 Disagree – 2 Strongly Disagree -1

then write it back to the excel file


In reply to Trying to manipulate data by emadmahou

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.