freeze panes in excel without using a module

Discussion in 'Perl Misc' started by mrbluelamp@yahoo.com, Oct 31, 2005.

  1. Guest

    I'm trying to freeze panes in excel without using a module, because I
    already know that Spreadsheet::WriteExcel will do it for me, so if that
    is your answer, no need to respond.

    What I have tried and found not to work:

    $generalSheet->Range("A2")->Select;
    ActiveWindow->{FreezePanes} = True;
    , Oct 31, 2005
    #1
    1. Advertising

  2. wrote in news:1130787698.326521.209170
    @g44g2000cwa.googlegroups.com:

    > I'm trying to freeze panes in excel without using a module,


    Can you show how you deal with Excel documents without using any module?

    Sinan

    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Oct 31, 2005
    #2
    1. Advertising

  3. Guest

    This is a short example of how I do it

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

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

    $Excel->{Visible} = 1;

    $Book = $Excel->Workbooks->Add;
    $generalSheet = $Book->Worksheets(1);
    $generalSheet->Cells(1, 3)->{Value} = 'Data';
    $LastRow =
    ($generalSheet->Cells->SpecialCells(xlCellTypeLastCell)->{Row});

    foreach $value (@valueArray)
    {
    $generalSheet->Cells($LastRow, 3)->{Value} = $value;
    }

    $generalSheet->Columns->AutoFit;
    $Book->Save;
    $Book->Close;
    $Excel->Quit;
    , Oct 31, 2005
    #3
  4. Joe Smith Guest

    wrote:
    > I'm trying to freeze panes in excel without using a module, because I
    > already know that Spreadsheet::WriteExcel will do it


    Hold it. Spreadsheet::WriteExcel _is_ a module.
    How can you ask for a solution that does not use a module when
    you are already using a module?
    -Joe
    Joe Smith, Oct 31, 2005
    #4
  5. wrote in news:1130790911.350135.262050
    @z14g2000cwz.googlegroups.com:

    [ When compsing a follow-up, please make sure to quote context. ]

    > "A. Sinan Unur" <> wrote in

    news:Xns97009C0EBFCCBasu1cornelledu@127.0.0.1:
    >
    >> wrote in news:1130787698.326521.209170
    >> @g44g2000cwa.googlegroups.com:
    >>
    >>> I'm trying to freeze panes in excel without using a module,

    >>
    >> Can you show how you deal with Excel documents without using any
    >> module?

    >
    > This is a short example of how I do it
    >
    > use Win32::OLE::Const 'Microsoft Excel';


    You are using modules.

    I don't think you are using them correctly.

    The code you posted is missing:

    use strict;
    use warnings;

    use Win32::OLE;
    $Win32::OLE::Warn = 3;

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


    See the Win32::OLE documentation for a way of doing this correctly.

    > foreach $value (@valueArray)


    There is no other mention of @valueArray in your code.

    You'll need to post sample code that can be compiled and run.

    Sinan
    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Oct 31, 2005
    #5
  6. Guest

    Ok, well if "use Win32::OLE::Const 'Microsoft Excel'" means I'm using a
    module, then I am then, and would like a solution using that, I am not
    using Spreadsheet::WriteExcel, but I am aware that it can be done with
    this module real easy like, is what I was trying to say.
    , Oct 31, 2005
    #6
  7. Guest

    I don't actually need to strict and get warnings to make this short
    example to work, but added it anyways, this runs on my computer just
    fine:

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

    $Win32::OLE::Warn = 3;

    my $Excel = Win32::OLE->new('Excel.Application', 'Quit');

    $Excel->{Visible} = 1;

    my $Book = $Excel->Workbooks->Add;
    my $generalSheet = $Book->Worksheets(1);
    $generalSheet->Cells(1, 3)->{Value} = 'Data';
    my $LastRow =
    ($generalSheet->Cells->SpecialCells(xlCellTypeLastCell)->{Row});

    my @valueArray = ();

    push(@valueArray,"Value1");
    push(@valueArray,"Value2");
    push(@valueArray,"Value3");
    push(@valueArray,"Value4");

    foreach my $value (@valueArray)
    {
    $LastRow++;
    $generalSheet->Cells($LastRow, 3)->{Value} = $value;
    }

    $generalSheet->Columns->AutoFit;
    $Book->Close;
    $Excel->Quit;
    , Oct 31, 2005
    #7
  8. wrote in news:1130792650.627763.66980
    @g49g2000cwa.googlegroups.com:

    [ Please quote an appropriate amount of context when you reply. ]

    > I don't actually need to strict and get warnings


    You may think so. However, originally, you posted:

    > $generalSheet->Range("A2")->Select;
    > ActiveWindow->{FreezePanes} = True;


    Here is what perl has to say about these lines with strictures and
    warnings enabled:

    D:\Home\asu1\UseNet\clpmisc> bug
    Can't use bareword ("ActiveWindow") as a HASH ref while "strict refs" in
    use at D:\Home\asu1\UseNet\clpmisc\bug.pl line 38.

    D:\Home\asu1\UseNet\clpmisc> bug
    Bareword "True" not allowed while "strict subs" in use at D:\Home\asu1
    \UseNet\clpmisc\bug.pl line 38.
    Execution of D:\Home\asu1\UseNet\clpmisc\bug.pl aborted due to
    compilation errors.

    #!/usr/bin/perl

    use strict;
    use warnings;

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

    $Win32::OLE::Warn = 3;

    my $Excel;
    eval {
    $Excel = Win32::OLE->GetActiveObject('Excel.Application')
    };
    die "Excel not installed" if $@;

    unless (defined $Excel) {
    $Excel = Win32::OLE->new('Excel.Application', sub { $_[0]->Quit })
    or die "Cannot start Excel";
    }

    $Excel->{Visible} = 1;

    my $Book = $Excel->Workbooks->Add;
    my $Sheet = $Book->Worksheets(1);
    $Sheet->Cells(1, 3)->{Value} = 'Data';
    my $LastRow = $Sheet->Cells->SpecialCells(xlCellTypeLastCell)->{Row};

    my @valueArray = qw( value1 value2 value3 value4 );

    for my $value (@valueArray) {
    $LastRow++;
    $Sheet->Cells($LastRow, 3)->{Value} = $value;
    }

    $Sheet->Columns->AutoFit;
    $Sheet->Range("A2")->Select;
    $Excel->ActiveWindow->{FreezePanes} = 1;




    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Oct 31, 2005
    #8
  9. Guest

    Sweet, thanks Sinan. I never actually knew what the warnings did either
    because I guess I never got any warnings with the other script that I
    have that actually has that at the top. Also, I like that little
    tidbit you showed about seeing if excel was even installed, thanks
    again.
    , Oct 31, 2005
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Phani
    Replies:
    3
    Views:
    336
  2. Luqman
    Replies:
    0
    Views:
    658
    Luqman
    Sep 25, 2007
  3. Replies:
    5
    Views:
    245
    Olivier Renaud
    Mar 15, 2007
  4. Matt Kruse
    Replies:
    10
    Views:
    337
    Richard Cornford
    Sep 16, 2005
  5. srinivas
    Replies:
    7
    Views:
    252
    Thomas 'PointedEars' Lahn
    Nov 18, 2005
Loading...

Share This Page