开发者

How can I add a new row to an existing Excel spreadsheet using Perl?

I have created my Excel sheet a.xls using Perl where I have field as:

date         name    eid     
13/jan/2010   asa    3175

When I will compile next time and if date will be more than previous date then it has to u开发者_开发技巧pdate like wise:

date         name   eid
13/jan/2010  asa    3175
14/jan/2010  stone  3180

If the date will be of previous row date as last row date is 14/jan/2010 and current date is also 14/jan/2010 then it should not insert any row it should update the previous record only.


See example in Spreadsheet::ParseExcel::SaveParser documentation. As I understand, AddCell method can replace existing cell or add new.


With Excel 2007 files, using Excel::Writer::XSLX, you can't do this. As of release 0.47 from June 2012:

This module cannot, as yet, be used to write to an existing Excel XLSX file.

You can only create new files.


    use Win32::OLE::Const 'Microsoft Excel';

    $Excel = Win32::OLE->new('Excel.Application', 'Quit');
    $Excel->{DisplayAlerts}=0;

    my $workbookpath = "D:\\temp.xlsx";
    my $workbook = $Excel->Workbooks->Open($workbookpath);
    # lets think if you created multiple sheets in an workbook, you can refer each workbook by name(Ex: sheet1 here)
    my $sheet = $workbook->WorkSheets("sheet1");
    #Insert row in a particular row value
    $sheet->Cells(8,1)->EntireRow->Insert;
    #save and close workbook, its a best practise when you are doing any excel operation
    $workbook->Save;
    $workbook->Close();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜