Created
January 27, 2022 09:55
-
-
Save sironekotoro/b8fb6d4cd45974b4d374d8f3748fd127 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Win32::OLE; | |
# https://perldoc.jp/docs/modules/libwin32-0.26/Win32/OLE.pod | |
# use existing instance if Excel is already running | |
my $excel; | |
eval { $excel = Win32::OLE->GetActiveObject('Excel.Application') }; | |
die "Excel not installed" if $@; | |
unless ( defined $excel ) { | |
$excel = Win32::OLE->new( 'Excel.Application', sub { $_[0]->Quit; } ) | |
or die "Oops, cannot start Excel"; | |
} | |
# get a new workbook | |
my $book = $excel->Workbooks->Add; | |
# write to a particular cell | |
my $sheet = $book->Worksheets(1); | |
$sheet->Cells( 1, 1 )->{Value} = "foo"; | |
# save and exit | |
# USERNAME は変更してね | |
$book->SaveAs('C:\Users\USERNAME\Desktop\test.xlsx') or die("$!"); | |
undef $book; | |
undef $excel; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment