[英]How to copy the format of the .xlsx cell using "Excel::Writer::XLSX" reader to the copied cell using "Spreadsheet::WriteExcel" writer?
I am new to the Perl, Please bear up with me if it's very basic.我是 Perl 的新手,如果它是非常基本的,请耐心等待。 The below code works fine copying in excel value to another.下面的代码可以很好地将 excel 值复制到另一个值。 I am having trouble copying the format.我在复制格式时遇到问题。 I need to copy the format value from the reading file and then assign it to writing cell- self is the variable need to change.我需要从读取文件中复制格式值,然后将其分配给写入单元格-self 是需要更改的变量。
Code:-代码:-
#!/home/utils/perl-5.24/5.24.2-058/bin/perl -w
use warnings;
use Spreadsheet::XLSX;
use Excel::Writer::XLSX;
#reading the sheet using below perl parser
my $excel = Spreadsheet::XLSX -> new ('abcd.xlsx');
#writing the sheet using below parser
my $excel_2 = Excel::Writer::XLSX -> new ('abcd_N.xlsx');
my $format = $excel_2->add_format();
#loop to read the hseet and write
foreach my $sheet (@{$excel -> {Worksheet}})
{
printf("Sheet: %s\n", $sheet->{Name});
my $sheet_write = $excel_2->add_worksheet($sheet->{Name});
$sheet -> {MaxRow} ||= $sheet -> {MinRow};
foreach my $row ($sheet -> {MinRow} .. $sheet -> {MaxRow})
{
$sheet -> {MaxCol} ||= $sheet -> {MinCol};
foreach my $col ($sheet -> {MinCol} .. $sheet -> {MaxCol})
{
my $cell = $sheet -> {Cells} [$row] [$col];
if ($cell)
{
printf("( %s , %s ) => %s\n", $row, $col, $cell -> {Val});
$sheet_write->write($row, $col,$cell -> {Val},$self);
}
}
}
}
I don't recall spreadsheet::XLSX have the "power" to copy formating of cells.我不记得电子表格:: XLSX 具有复制单元格格式的“能力”。 It's a very basic cpan package for getting cell contents.这是一个非常基本的 cpan 包,用于获取单元格内容。
Did you look at this?你看这个了吗? https://metacpan.org/pod/Spreadsheet::ParseXLSX https://metacpan.org/pod/Spreadsheet::ParseXLSX
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.