【问题标题】:How to format the string with in the cell of a Excel sheet using perl language如何使用 perl 语言在 Excel 工作表的单元格中格式化字符串
【发布时间】:2013-11-27 00:08:01
【问题描述】:

我正在使用 win32::Ole 模块,我正在尝试使用 colorindex 将字符串格式化为粗体,它位于 Excel 工作表的单元格中,您能否建议我使用哪种方法..

Formatprgm.pl

use strict;
use warnings;
use Win32::OLE;
my prgm=fn_prgm();
sub fn_prgm
{
  $inputfile="C:\Users\u304079\Desktop\Santu123\CurrentData.xlsx";
  my $Excel = Win32::OLE->new('Excel.Application');
  my $Workbook = $Excel->Workbooks->Open($inputfile);
  my $sheet = $Workbook->Worksheets(1);
  my $cell1val=$sheet->Cells(1,1)->{value};
   #here i want to format the text in $cell1val

}

【问题讨论】:

    标签: perl


    【解决方案1】:

    您也可以为此使用Spreadsheet::WriteExcel

           use Spreadsheet::WriteExcel;
    
           # Create a new Excel workbook
           my $workbook = Spreadsheet::WriteExcel->new('perl.xls');
    
           # Add a worksheet
           $worksheet = $workbook->add_worksheet();
    
           #  Add and define a format
           $format = $workbook->add_format(); # Add a format
           $format->set_bold();
           $format->set_color('red');
           $format->set_align('center');
    
           # Write a formatted and unformatted string, row and column notation.
           $col = $row = 0;
           $worksheet->write($row, $col, 'Hi Excel!', $format);
           $worksheet->write(1,    $col, 'Hi Excel!');
    

    UPD

    为了重写现有的 Excel 文件,您应该使用 Spreadsheet::ParseExcel::SaveParser

    描述

       The "Spreadsheet::ParseExcel::SaveParser" module rewrite an existing Excel 
       file by reading it with "Spreadsheet::ParseExcel"
       and rewriting it with "Spreadsheet::WriteExcel".
    

    【讨论】:

    • 它正在工作,但我想使用 win32::OLE 模块,你能建议我在单元格中格式化文本的方法
    • WriteExcel 模块仅用于新创建的 excel 工作表,但我想格式化现有 excel 文件中的文本,请您给我建议....
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多