Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Re: Import .csv file

Reply
 
Old 08-05-2008   #1 (permalink)
Shay Levy [MVP]


 
 

Re: Import .csv file


You need to make the other sheet active before you save:


$xl= new-object -com Excel.Application
$xl.visible = $true
$xl.displayalerts=$false
$wb = $xl.workbooks.open("C:\Book1.xls")
$sheet1 = $wb.worksheets | where {$_.name -eq "s1"}
$wb.saveAs("c:\sheet1.csv", 6)

$sheet2 = $wb.worksheets | where {$_.name -eq "s2"}
$sheet2.select()
$wb.saveAs("c:\sheet2.csv", 6)

$xl.quit()



To save all worksheets to csv files:

$wb.worksheets | foreach {
$_.select()
$wb.saveAs("c:\"+$_.name+".csv", 6)
}



---
Shay Levy
Windows PowerShell
http://blogs.microsoft.co.il/blogs/ScriptFanatic
Quote:

> Right. I get that, but what I'm trying to do is to have one existing
> file, and then end up with two different files because I have two
> different csv files. But I don't know how to get the second sheet to
> SaveAs so I can import it in PowerShell. I can get the first sheet to
> SaveAs but the second sheet seems to ignore the code. I've been using
> this code but it seems to not work. Should I be using a different
> code?
>
> $optionSheet.SaveAs("C:\Users\options.csv", 6)
>
> ronni
>


My System SpecsSystem Spec
Old 08-05-2008   #2 (permalink)
roroleee


 
 

Re: Import .csv file

I used the code, but it still won't activate the second sheet.
Everything else works just like it should but the second sheet won't
saveas and won't import in PowerShell. Is there something that I'm not
doing correctly?



ronni
My System SpecsSystem Spec
Old 08-05-2008   #3 (permalink)
Shay Levy [MVP]


 
 

Re: Import .csv file


I used excel 2007 to test the code, what's youre version?

What happens if you try the second part where you can save all sheets?


---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic


Quote:

> I used the code, but it still won't activate the second sheet.
> Everything else works just like it should but the second sheet won't
> saveas and won't import in PowerShell. Is there something that I'm not
> doing correctly?
>
> ronni
>

My System SpecsSystem Spec
Old 08-05-2008   #4 (permalink)
roroleee


 
 

Re: Import .csv file

I'm usng excel 2007 as well.

When I use the second part of the code, I get an error saying that I
cannot access read-only documents. I didn't see this before because I
put it in a function that I'm creating. How do I make it so that the
documents aren't in read-only?


ronni
My System SpecsSystem Spec
Old 08-06-2008   #5 (permalink)
Shay Levy [MVP]


 
 

Re: Import .csv file

Can you create a sample excel file with two or three sheets, save it locally
on your hard drive and try the code again.
BTW, doe's your regional settings set to en-US?


---
Shay Levy
Windows PowerShell
http://blogs.microsoft.co.il/blogs/ScriptFanatic
Quote:

> I'm usng excel 2007 as well.
>
> When I use the second part of the code, I get an error saying that I
> cannot access read-only documents. I didn't see this before because I
> put it in a function that I'm creating. How do I make it so that the
> documents aren't in read-only?
>
> ronni
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
How to import pst file into Windows mail Vista mail
Import from OE6 via CSV File...Is it possible??? Vista mail
My new Vista PC IE will not import my bookmark.htm file from XP PC Vista General
can't import ics file Vista mail
Can't Import .pst file into Windows Mail Vista mail


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46