简体   繁体   中英

How to merge two csv files as worksheets in Excel file using perl

All,

I have 2 .csv files which has some data in it (test1.csv, test2.csv)

I have to create a new Excel (test.xls) with 2 worksheets test1 and test2

test1 is nothing but contents of test1.csv and test2 is nothing but test2.csv

I am using the below code. but it only creates only empty worksheets.

Can you please let me know how do i load these csv files into worksheets of xls file.

#!/opt/perl-5.8.0/bin/perl

use strict;
use Spreadsheet::WriteExcel;

my $workbook = Spreadsheet::WriteExcel->new("Test.xls");

$workbook->addworksheet("test1.csv");
$workbook->addworksheet("test2.csv");
$workbook->close();

exit;

You need to convert your CSV to XLS format before writing to the workbook.

You could install Text::CSV_XS and use the csv2xls utility that comes with it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM