Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Modifying files.

Status
Not open for further replies.

umneydurak

Programmer
Jun 28, 2005
9
0
0
US
Hello.
I'm trying to write something that will modify comma seperated files. I'm using the Excel OLE to do it. Program works fine, except it has this wiered bug. After I modify the file first few lines are missing commas after the last entry.
So for example if orginal file looks like this:

,,,,,stuff,,,,,
,,,,,stuff,,,,,
,,,,,stuff,,,,,
,,,,,stuff,,,,,
,,,,,stuff,,,,,

After modification:

,,,,,stuff
,,,,,stuff
,,,,,stuff,,,,,
,,,,,modified,,,,,
,,,,,stuff,,,,,

I have no idea what causes it, since I do not touch first lines. Any ideas? I would really hate to try to modify those files with perl commands.

Thanks.
 
try using Text::CSV, I've had good luck with it in the past.
 
Is it a standard perl package, or something that has to be installed seperatly?
If it has to be installed seperately I rather try to get OLE working first.
 
Looks like a "split" problem to me.
If you split a record into fields and don't specify a number of items to split into, split will truncate empty fields from the list.


Trojan.
 
But it only does it for the first few lines, it ignores the empty fields in the rest of the file.
Here is how I get the row:
my $startC="A";
my $endC="AZ";
my $range=$startC.$row.":".$endC.$row;
my $row_array=$Sheet->Range($range)->{value};

Even if I modify just one line in the middle of the text it still removes commas in the first few lines. Like in my example.
 
Err, just a question.....
Why ole on a simple csv ?

Why not stay with VB if you reaaaally want to use ole ?

Gimme me a shout if you want to know how to do this in perl...

[ponder]KrK
 
Because when I was researching on how to parse CSV files thats pretty much then only thing I found. I didn't even know about Text::CSV untill it was mentioned here.
On a side note. Not a particular fan of VB, just a personal thing.
Anyway I got everything working with Text::CSV. Required very minimal changes from when I was using OLE.

I would still like to know why using an OLE would cause a problem I described above. Also the same thing happened when I just opened a CSV file with Excell, edited and saved it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top