#!/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 => '@'); $default_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;Database=database;Trusted_Connection=Yes") or die("\n\nCONNECT ERROR:\n\n$DBI::errstr"); my $sth = $dbh->prepare(<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;