I recently used Perl (using Win32: Ole) to operate Excel. I didn't find similar content on the Internet, so I had to find some beginner knowledge in a book, and I had a great deal with myself, finally, I am a little confused. Here I will make a backup for your reference. ^_^
#! Usr/bin/perl
Use strict;
Use warnings;
Use Win32: Ole; # import a Win32 Ole package
My $ dir = 'd: // myperl // win32ole // '; # create two new Excel files in this directory
My $ src_name = $ dir. "test1". "/. xls ";
My $ dst_name = $ dir. "Test2". "/. xls"; my $ nowstr; # create an Excel application object, and then we can operate on Excel.
My $ app_xls = Win32: Ole-> New ('excel. application', sub {$ _ [0]-> quit })
Or die "can't install excel01! "; # Open an Excel file. 'true' indicates read-only my $ src_book = $ app_xls-> workbooks-> open ($ src_name, 0, 'true ');
My $ src_sheet = $ src_book-> worksheets (1); # select a worksheet
$ Nowstr = $ src_sheet-> cells (1, 'A')-> {value}; # retrieve data in a cell
Print ($ nowstr );
$ Src_sheet-> cells (1, 'A')-> {value} = "change"; # modify data in a cell
My $ dst_book = $ app_xls-> workbooks-> open ($ dst_name );
My $ dst_sheet = $ dst_book-> worksheets (1 );
$ App_xls-> {displayalerts} = 'false'; # Turn off the Excel prompt, such as whether to save the modification.
# $ Dst_book-> worksheets (1)-> Delete; # delete a worksheet
# Copy a worksheet from an Excel worksheet to another Excel worksheet
$ Src_book-> worksheets (1)-> copy ($ dst_book-> worksheets ('sheet3 '));
$ Dst_book-> Save; # Save the changes
$ App_xls-> {displayalerts} = 'true'; # restore prompt
UNDEF $ src_book;
UNDEF $ dst_book; UNDEF $ app_xls; # disable the opened Excel application
References: 1. perl5 programming core technology-du jingnong (Beijing hope electronics Publishing House) 2000.11 first version 2. Microsoft Excel developers refer to and use OLE to describe Excel operations, for ole-related support, you can find it on Microsoft's msdn. There is also an introduction to Ole in my blog technical discussion directory. Author: smilelance from: http://blog.csdn.net/smilelanceTime:2006.05.23