<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Copy CSV Columns to an Excel Spreadsheet by Using PowerShell</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/09/copy-csv-columns-to-an-excel-spreadsheet-by-using-powershell.aspx</link><description>Summary : Join the Microsoft Scripting Guys as they show you how to copy CSV columns to a Microsoft Excel spreadsheet by using Windows PowerShell. 
 
 
 Hey, Scripting Guy! I love comma-separated value (CSV) files. To me, it seems as if that was the</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Copy CSV Columns to an Excel Spreadsheet by Using PowerShell</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/09/copy-csv-columns-to-an-excel-spreadsheet-by-using-powershell.aspx#3476249</link><pubDate>Thu, 19 Jan 2012 12:24:34 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3476249</guid><dc:creator>JB</dc:creator><description>&lt;p&gt;@jrv: &amp;nbsp; I solved my problem!&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s the code, where I copy the content of &amp;quot;input.csv&amp;quot; in the &amp;quot;specific_tab&amp;quot; of the &amp;quot;output.xlsx&amp;quot; file. &amp;nbsp;In this example, there is only 2 columns in input.csv (if more are present, change the &amp;quot;A1:B1&amp;quot; portion of this code). &amp;nbsp;Note that excel turns the csv filename into the tab name automatically, make sure that this line &amp;quot;$Worksheet = $Workbook.WorkSheets.item(&amp;quot;input&amp;quot;)&amp;quot; is adjusted.&lt;/p&gt;
&lt;p&gt;$sourcefile = &amp;quot;C:\input.csv&amp;quot; &lt;/p&gt;
&lt;p&gt;$updatedfile = &amp;quot;C:\output.xlsx&amp;quot; &lt;/p&gt;
&lt;p&gt;$Excel = New-Object -ComObject excel.application &lt;/p&gt;
&lt;p&gt;$Excel.visible = $false &lt;/p&gt;
&lt;p&gt;$Workbook = $excel.Workbooks.open($sourcefile) &lt;/p&gt;
&lt;p&gt;$Worksheet = $Workbook.WorkSheets.item(&amp;quot;input&amp;quot;) &lt;/p&gt;
&lt;p&gt;$worksheet.activate() &amp;nbsp;&lt;/p&gt;
&lt;p&gt;$range = $WorkSheet.Range(&amp;quot;A1:B1&amp;quot;).EntireColumn &lt;/p&gt;
&lt;p&gt;$range.Copy() | out-null &lt;/p&gt;
&lt;p&gt;$Workbook = $excel.Workbooks.open($updatedfile) &lt;/p&gt;
&lt;p&gt;$Worksheet = $Workbook.WorkSheets.item(&amp;quot;specific_tab&amp;quot;) &lt;/p&gt;
&lt;p&gt;$worksheet.activate() &amp;nbsp;&lt;/p&gt;
&lt;p&gt;$Range = $Worksheet.Range(&amp;quot;A1&amp;quot;) &lt;/p&gt;
&lt;p&gt;$Worksheet.Paste($range) &amp;nbsp;&lt;/p&gt;
&lt;p&gt;$workbook.Save() &amp;nbsp;&lt;/p&gt;
&lt;p&gt;$Excel.Quit() &lt;/p&gt;
&lt;p&gt;Remove-Variable -Name excel &lt;/p&gt;
&lt;p&gt;[gc]::collect() &lt;/p&gt;
&lt;p&gt;[gc]::WaitForPendingFinalizers() &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3476249" width="1" height="1"&gt;</description></item><item><title>re: Copy CSV Columns to an Excel Spreadsheet by Using PowerShell</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/09/copy-csv-columns-to-an-excel-spreadsheet-by-using-powershell.aspx#3475941</link><pubDate>Tue, 17 Jan 2012 22:48:42 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3475941</guid><dc:creator>jrv</dc:creator><description>&lt;p&gt;@JB&lt;/p&gt;
&lt;p&gt;You need to use Excel directly. &amp;nbsp;It is not necessary to import. &amp;nbsp;YOur master sheet can read data directly from a CSV file.&lt;/p&gt;
&lt;p&gt;There are a number of places where you can get more help on this.&lt;/p&gt;
&lt;p&gt;You can post in an Excel forum at Microsoft:&lt;a rel="nofollow" target="_new" href="http://social.technet.microsoft.com/Forums/en/excel/threads"&gt;social.technet.microsoft.com/.../threads&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You can post at The Scripting Guys Forum at Microsoft: &lt;a rel="nofollow" target="_new" href="http://social.technet.microsoft.com/Forums/en-US/ITC"&gt;social.technet.microsoft.com/.../ITC&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You can post at: &lt;a rel="nofollow" target="_new" href="http://www.scriptinganswers.com"&gt;www.scriptinganswers.com&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Each forum has its own particular strengths and weaknesses.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3475941" width="1" height="1"&gt;</description></item><item><title>re: Copy CSV Columns to an Excel Spreadsheet by Using PowerShell</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/09/copy-csv-columns-to-an-excel-spreadsheet-by-using-powershell.aspx#3475932</link><pubDate>Tue, 17 Jan 2012 21:56:31 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3475932</guid><dc:creator>JB</dc:creator><description>&lt;p&gt;@jrv: &amp;nbsp;the CSV data need to be pushed into a XLSX file where many graphs and pivot tables depend on this data. &amp;nbsp;Note that this process will be automated (unsupervised) and will either do daily, weekly, or monthly data concatenation/handling. &amp;nbsp;I&amp;#39;ve found another method here: &lt;a rel="nofollow" target="_new" href="http://gallery.technet.microsoft.com/scriptcenter/d41565f1-37ef-43cb-9462-a08cd5a610e2"&gt;gallery.technet.microsoft.com/.../d41565f1-37ef-43cb-9462-a08cd5a610e2&lt;/a&gt; but my powershell skills are way to low to make it work... when i pipe the csv file it only loads the filename lenght or each line byte count... i&amp;#39;m desperate now... help!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3475932" width="1" height="1"&gt;</description></item><item><title>re: Copy CSV Columns to an Excel Spreadsheet by Using PowerShell</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/09/copy-csv-columns-to-an-excel-spreadsheet-by-using-powershell.aspx#3475911</link><pubDate>Tue, 17 Jan 2012 19:19:55 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3475911</guid><dc:creator>jrv</dc:creator><description>&lt;p&gt;What is not made clear here is that there is no need to import a CSV into an Excel spreadsheet. &amp;nbsp;a CSV file will open directly in Excel and can be easily saved in many formats. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;This is very fast.&lt;/p&gt;
&lt;p&gt;The only reason to do an import is if you want to edit the values or filter the import. &amp;nbsp;This too may be easier after just opening the CSV in Excel directly.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3475911" width="1" height="1"&gt;</description></item><item><title>re: Copy CSV Columns to an Excel Spreadsheet by Using PowerShell</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/09/copy-csv-columns-to-an-excel-spreadsheet-by-using-powershell.aspx#3475891</link><pubDate>Tue, 17 Jan 2012 18:28:32 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3475891</guid><dc:creator>JB</dc:creator><description>&lt;p&gt;This works for me, but can end up being pretty long. &amp;nbsp;On my server, it takes approx 0.04 seconds per imported cell. &amp;nbsp;Do the math, but with a 10,000 rows spreadsheet with 86 columns, it takes over 9 hours to complete! &amp;nbsp;Any suggestions to make it faster? Maybe something else than a &amp;quot;foreach&amp;quot; loop... ?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3475891" width="1" height="1"&gt;</description></item><item><title>re: Copy CSV Columns to an Excel Spreadsheet by Using PowerShell</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/09/copy-csv-columns-to-an-excel-spreadsheet-by-using-powershell.aspx#3356670</link><pubDate>Mon, 20 Sep 2010 20:28:22 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3356670</guid><dc:creator>ScriptingGuy1</dc:creator><description>&lt;p&gt;@Matt B. you can use ADO to write to Access, or to SQL. See the ADO tag on this blog, or the Scripting for databases on the Learn to script page.&lt;/p&gt;
&lt;p&gt;@WF probably a good thing to do.&lt;/p&gt;
&lt;p&gt;@Steven White MSDN is the comprenhensive source of information about everything you can do with Microsoft Excel. See the hyperlinks in the article for guidance.&lt;/p&gt;
&lt;p&gt;@WhoEver abstraction is always a good thing, but generally makes the script more complex to understand. Feel free to modify the script and post it to the Repository.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3356670" width="1" height="1"&gt;</description></item><item><title>re: Copy CSV Columns to an Excel Spreadsheet by Using PowerShell</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/09/copy-csv-columns-to-an-excel-spreadsheet-by-using-powershell.aspx#3356280</link><pubDate>Sat, 18 Sep 2010 01:34:51 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3356280</guid><dc:creator>Whoever</dc:creator><description>&lt;p&gt;This post would have been considerably more useful if it was generalized. Everything is hard-coded. Can we not get and print the column names dynamically; deal with an arbitrary number of columns; pass the paths to the script, etc?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3356280" width="1" height="1"&gt;</description></item><item><title>re: Copy CSV Columns to an Excel Spreadsheet by Using PowerShell</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/09/copy-csv-columns-to-an-excel-spreadsheet-by-using-powershell.aspx#3354508</link><pubDate>Thu, 09 Sep 2010 16:29:52 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3354508</guid><dc:creator>Steven </dc:creator><description>&lt;p&gt;Pardon my premature question. &amp;nbsp;The script error was my own fault (no dollar sign before excel.workbooks.add) but the question seems reasonable, namely, is there documentation on all these methods. &amp;nbsp;I do see the examples in the script repository, but that is not the same as a comprehensive list of all the things one can do with/to an excel spreadsheet.&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3354508" width="1" height="1"&gt;</description></item><item><title>re: Copy CSV Columns to an Excel Spreadsheet by Using PowerShell</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/09/copy-csv-columns-to-an-excel-spreadsheet-by-using-powershell.aspx#3354498</link><pubDate>Thu, 09 Sep 2010 16:07:45 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3354498</guid><dc:creator>Steven White</dc:creator><description>&lt;p&gt;I tried a variation of this, and on the &lt;/p&gt;
&lt;p&gt;$workbook = excel.workbooks.add()&lt;/p&gt;
&lt;p&gt;line I got an error about an expression expected after the left parenthesis. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Where is the documentation on these various methods for excel?&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3354498" width="1" height="1"&gt;</description></item><item><title>re: Copy CSV Columns to an Excel Spreadsheet by Using PowerShell</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/09/copy-csv-columns-to-an-excel-spreadsheet-by-using-powershell.aspx#3354462</link><pubDate>Thu, 09 Sep 2010 14:20:43 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3354462</guid><dc:creator>WF</dc:creator><description>&lt;p&gt;Just wondered &amp;nbsp;what would be the best way to get rid of the Excel COM object. The Windows PowerShell Tip of the Week &amp;nbsp;&amp;quot;Getting Rid of a COM Object (Once and For All)&amp;quot; at &lt;a rel="nofollow" target="_new" href="http://technet.microsoft.com/en-us/library/ff730962.aspx"&gt;technet.microsoft.com/.../ff730962.aspx&lt;/a&gt; recommends: [System.Runtime.Interopservices.Marshal]::ReleaseComObject($Excel)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3354462" width="1" height="1"&gt;</description></item></channel></rss>