如何使用"Excel :: Writer :: XLSX"复制.xlsx单元格的格式使用"Spreadsheet :: WriteExcel"将阅读器读取到复制的单元格作家? [英] How to copy the format of the .xlsx cell using "Excel::Writer::XLSX" reader to the copied cell using "Spreadsheet::WriteExcel" writer?

查看:76
本文介绍了如何使用"Excel :: Writer :: XLSX"复制.xlsx单元格的格式使用"Spreadsheet :: WriteExcel"将阅读器读取到复制的单元格作家?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Perl的新手,如果它非常基础,请多多包涵.下面的代码可以将excel值很好地复制到另一个代码中.我在复制格式时遇到问题.我需要从读取文件中复制格式值,然后将其分配给写入单元格,这是需要更改的变量.

I am new to the Perl, Please bear up with me if it's very basic. The below code works fine copying in excel value to another. 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.

代码:-

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


            }

        }
    }

}

推荐答案

我不记得电子表格:: XLSX具有复制单元格格式的能力".这是一个非常基本的cpan软件包,用于获取单元格内容.

I don't recall spreadsheet::XLSX have the "power" to copy formating of cells. It's a very basic cpan package for getting cell contents.

您看到这个了吗? https://metacpan.org/pod/Spreadsheet::ParseXLSX

这篇关于如何使用"Excel :: Writer :: XLSX"复制.xlsx单元格的格式使用"Spreadsheet :: WriteExcel"将阅读器读取到复制的单元格作家?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆