如何使用perl将两个csv文件合并为Excel文件中的工作表

时间:2023-01-15 12:36:29

All,

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

我有2个.csv文件,里面有一些数据(test1.csv,test2.csv)

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

我必须使用2个工作表test1和test2创建一个新的Excel(test.xls)

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

test1只是test1.csv和test2的内容,只不过是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.

你能告诉我如何将这些csv文件加载到xls文件的工作表中。

#!/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;

1 个解决方案

#1


0  

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

在写入工作簿之前,您需要将CSV转换为XLS格式。

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

您可以安装Text :: CSV_XS并使用随附的csv2xls实用程序。

#1


0  

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

在写入工作簿之前,您需要将CSV转换为XLS格式。

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

您可以安装Text :: CSV_XS并使用随附的csv2xls实用程序。