2007년 4월 4일 수요일

html의 확장자를 xls로 만들어 내릴 경우

mso format 에 대해서
date: 2007.4.4 15:16 - jk.

확장자를 xls로 만들어서 html로 data를 내릴 경우


<html xmlns:x="urn:schemas-microsoft-com:office:excel">
<head>
<xml>
<x:ExcelWorkbook>
  <x:ExcelWorksheets>
  <x:ExcelWorksheet>
   <x:Name>Sheet1</x:Name>
   <x:WorksheetOptions>
    <x:Selected/>
   </x:WorksheetOptions>
  </x:ExcelWorksheet>
  </x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml>
</head>
<body>

## Misc
# Add a formula to a cell : <td x:num x:fmla="=B2+1"></td>
# Define a cell as Text   : <td style='mso-number-format:"\@"'>00123</td>
# Indent a row 2 columns  : <td colspan=2 style='mso-ignore:colspan'></td>

# perl sample
#!/usr/bin/perl
use strict;
use warnings;

sub add_xl_header    {
   return<<EOT;
<html xmlns:x="urn:schemas-microsoft-com:office:excel">
<head>
<xml>
<x:ExcelWorkbook>
  <x:ExcelWorksheets>
  <x:ExcelWorksheet>
   <x:Name>Sheet1</x:Name>
   <x:WorksheetOptions>
    <x:Selected/>
   </x:WorksheetOptions>
  </x:ExcelWorksheet>
  </x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml>
</head>
<body>
EOT
}

sub add_xl_table    {
   defined(my $array_ref = shift) || return;
   my ($use_row_headers, $use_col_headers) = @_;
   my $table;
   my $max_width = 0;
   if ($use_row_headers)    {
       my $row = shift @$array_ref;
       $table .= "<tr>\n";
       $table .= "<th>$_</th>\n" for @$row;
       $table .= "</tr>\n";
   }
   for my $row (@$array_ref)    {
       $max_width = @$row if @$row > $max_width;
       $table .= "<tr>\n";
       $$row[0] = '<b>' . $$row[0] if $use_col_headers;
       $table .= "<td>$_</td>\n" for @$row;
       $table .= "</tr>\n";
   }
   $table = "<table>\n<col span=$max_width style='width:48pt'>\n$tabl
+e</table>\n";
   $table;
}

sub add_xl_separator    {
   my $sep_rows = shift || 1;
   return "<table><tr style='mso-xlrowspan:$sep_rows'></tr></table>\n
+";
}

sub add_xl_trailer    {
   return "</body>\n</html>\n";
}

## Misc
# Add a formula to a cell : <td x:num x:fmla="=B2+1"></td>
# Define a cell as Text   : <td style='mso-number-format:"\@"'>00123</
+td>
# Indent a row 2 columns  : <td colspan=2 style='mso-ignore:colspan'><
+/td>

my @test_array1 = ( [2, 3, 5] , [7, 11, 13] , [17, 19, 23] );
my @test_array2 = ( ['', 'Height', 'Siblings'], ['Joe', 77, 1], ['Fran
+k', 70, 4] );

print add_xl_header;
print add_xl_table \@test_array1;
print add_xl_separator 3;
print add_xl_table (\@test_array2, 1, 1);
print add_xl_trailer;

댓글 없음:

댓글 쓰기