Use strict;
Use CWD;
Use strict 'subs ';
Use Win32: Ole QW (in );
Use Win32: Ole: variant;
$ Win32: Ole: Warn = 3; # Die on errors...
My @ files = ("1.xls"," 2.xls", "3.xls"," 4.xls", "5.xls"," 6.xls ");
Foreach my $ file (@ files)
{
& Editexcel ($ file );
Alarm (1500 );
}
Sub editexcel
{
My $ dir = getcwd;
My $ fullpath = "$ DIR/$ _ [0]";
Print $ fullpath. "/N ";
############################ Initialize ########## #####################
My $ Excel;
# Use existing instance if Excel is already running
Eval
{
Win32: Ole-> getactiveobject ('excel. application ');
};
If ($ @)
{
Print "excel not installed $ @";
}
Unless (defined $ Excel)
{
$ Excel = Win32: Ole-> New ('excel. application', sub {$ _ [0]-> quit;}) or print "cannot start excel .";
}
Alarm (500 );
############################ Current date ######### ######################
My $ sec, my $ min, my $ hour, my $ mday, my $ month, my $ year, my $ wday, my $ yday, my $ isdst;
($ Sec, $ min, $ hour, $ mday, $ month, $ year, $ wday, $ yday, $ isdst) = localtime (Time ());
$ Year + = 1900;
$ Month + = 1;
# Print "$ year-$ month-$ mday ";
# $ Excel-> {visible} = 0; # Show Excel
######################### Workbook ############## ###################
# Open a workbook
My $ book = $ Excel-> workbooks-> open ($ fullpath );
############################ Sheets ########### #######################
My $ sheets = $ book-> worksheets;
############################# Sheet ######### ###########################
# My $ sheet = $ book-> worksheets (1 );
My $ curr_mon = sprintf ("%-02.2d month", $ month );
My $ curr_day = sprintf ("%-02.2d", $ mday );
My $ sheet = $ sheets-> item ($ curr_mon );
# Activate the appointed page
$ Sheet-> activate ();
############################## Set value ######## ############################
# Set yrp
$ Sheet-> cells (2, 1)-> {value} = "yrp ";
$ Sheet-> cells (3, 2)-> {value} = "bug Parsing ";
# Row counts and column counts of cells used
My $ row_counts = $ sheet-> {usedrange}-> {rows}-> {count };
My $ column_counts = $ sheet-> {usedrange}-> {columns}-> {count };
For (my $ Col = 1; $ Col <= $ column_counts; $ Col ++)
{
If ($ sheet-> cells (1, $ col)-> {value} = ~ /^ $ Curr_day $/I)
{
$ Sheet-> cells (3, $ col)-> {value} = 8;
$ Sheet-> cells (4, $ col)-> {value }= 100;
Print "-- Set Value OK !! --/N ";
Last;
}
}
########################## Save ############# ##########################
# Save and exit
$ Book-> Save ();
$ Book-> close ();
UNDEF $ book;
UNDEF $ Excel;
}