python - 更改电子表格中每个单元格中首字母的大小写

标签 python perl bash csv openoffice-calc

我有很多单元格需要转换,以便每个单元格中的第一个字母都大写。例如。 cook, chef, fireman 变为 Cook, Chef, Fireman

  • 我在 OpenOffice.org 中有电子表格,但它似乎只有“全部大写”或“全部小写”的选项。
  • 如果 OpenOffice.org 无法执行此操作,我可以在 OpenOffice.org 中对其进行编辑或导出为 CSV 并使用 BASH 脚本编辑 CSV。

如何将电子表格中每个单元格的首字母更改为大写?

最佳答案

我正好做这个任务。您必须安装 Spreadsheet::ParseExcelSpreadsheet::WriteExcel模块。

use strict;
use warnings;

use Spreadsheet::ParseExcel::SaveParser;

my $parser   = Spreadsheet::ParseExcel::SaveParser->new();
my $workbook = $parser->Parse('Book1.xls');

if ( !defined $workbook ) {
    die $parser->error(), ".\n";
}

for my $worksheet ( $workbook->worksheets() ) {

    my ( $row_min, $row_max ) = $worksheet->row_range();
    my ( $col_min, $col_max ) = $worksheet->col_range();

    for my $row ( $row_min .. $row_max ) {
        for my $col ( $col_min .. $col_max ) {

            my $cell = $worksheet->get_cell( $row, $col );
            next unless $cell;

            # "ucfirst lc" make sure that only the first letter is capitalized
            # if you dont like that just remove lc
            $worksheet->AddCell( $row, $col, ucfirst lc $cell->value() );

        }
    }
}

# ofcouse save your work
$workbook->SaveAs('Book2.xls');

关于python - 更改电子表格中每个单元格中首字母的大小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8720589/

相关文章:

python - 调用元类基础时出错

xml - 在 Perl 中对 XML 数据进行 XPath 查询的最简单方法是什么?

arrays - 如何在 bash 中连接数组?

bash - 从 zsh 恢复到 bash 后 Vim/Vundle 坏了

c# - 在 Unity Cloud Build 中执行 bash 脚本

python - 为多次迭代重置 csv.reader 的正确方法?

python - 使用 scipy.signal 查找局部最大值

python - Pytest E DeprecationWarning : defusedxml. lxml 不再受支持,将在未来版本中删除

sql - 通过 Perl 连接到 Teradata

Perl:子程序输出;输入到 foreach 语句