Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Good afternoon. I have a CVS file I want to open up within Excel, sort the file (anywhere from 1000 - 6000 lines of data) based on Column 'F' and then delete all rows with specific data in Column 'F'. I am only to the point where I can open the file and that is it. The file will not sort for me. My code is short and simple, and does not work how I want it to work. Suggestions would be greatly appreciated. I will end up adding much more to this file after sorting, but I need to get past this point first. Here is my code;

#!perl use strict; use warnings; use Win32::OLE; use Win32::OLE qw(in with); use Win32::OLE::Variant; use Win32::OLE::Const 'Microsoft Excel'; use File::Copy; $Win32::OLE::Warn = 3; # Die on Errors. #Open the needed file from server location my $excelfile = '\\\\ServerName\\FolderName\\FolderName\\FolderName\\F +ileName.csv'; my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); #Open the file needed and activate the worksheet for manipulation ~ Tr +y to get a input box for entry of Branch name to open correct file... my $Book = $Excel->Workbooks->Open($excelfile); my $Sheet = $Book->Worksheets(1); $Sheet->Activate(); #Sort the file based on "Call Type" Column (F is column number 5, as A + is 0) $Excel->sort_data('WorksheetName',5,'DESC');

I have even attempted to use;

#Find Last Column and Row my $LastRow = $Sheet->UsedRange->Find({What=>"*", SearchDirection=>xlP +revious, SearchOrder=>xlByRows})->{Row}; my $LastCol = $Sheet->UsedRange->Find({What=>"*", SearchDirection=>xlP +revious, SearchOrder=>xlByColumns})->{Column};

to then try a loop type of statement. Yeah, that did not work either. Thank you for any suggestions offered I have a LONG way to go to my end results, and if I am having this many issues with a sort, I am worried about the rest of the requirments.

In reply to Sort CSV file within Excel based on specific column by jaacmmason

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (7)
    As of 2018-06-17 23:14 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (107 votes). Check out past polls.