<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Sarunbe's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 17 May 2008 21:35:48 GMT</pubDate>
    <description>DZone Snippets: Sarunbe's Code Snippets</description>
    <item>
      <title>Excel object</title>
      <link>http://snippets.dzone.com/posts/show/4317</link>
      <description>// Excel object&lt;br /&gt;&lt;code&gt;&lt;br /&gt;// 'create object&lt;br /&gt;Set excelobj = CreateObject( "Excel.Application")&lt;br /&gt;Set exp_data_workbook=excelobj.workbooks.open("c:\debug_expected.xls")&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;'get the sheet count&lt;br /&gt;exp_sheetcnt=exp_data_workbook.Sheets.Count&lt;br /&gt;	&lt;br /&gt;&lt;br /&gt;'select a sheet&lt;br /&gt;For i = 1 to exp_sheetcnt&lt;br /&gt;	sheet_tblname=exp_data_workbook.Sheets(i).Name&lt;br /&gt;	If  UCASE(Trim(sheet_tblname)) = "Sheet_name" Then&lt;br /&gt;		exp_data_workbook.Sheets(i).select&lt;br /&gt;&lt;br /&gt;		'once selected set the range object	&lt;br /&gt;		set exp_rangeobj=exp_data_workbook.Sheets(i).UsedRange&lt;br /&gt;	end if&lt;br /&gt;next&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;'Get the column count for the &lt;br /&gt;&lt;br /&gt;columncnt=exp_rangeobj.columns.count&lt;br /&gt;&lt;br /&gt;'find  the column index of  the column column_name&lt;br /&gt;		For i=1 to columncnt&lt;br /&gt;			colname=exp_rangeobj.cells(1,i).value&lt;br /&gt;			If UCASE(Trim(colname)) = "column_name" Then&lt;br /&gt;				pos_id_idx = i&lt;br /&gt;				Exit For&lt;br /&gt;			End If&lt;br /&gt;		Next		&lt;br /&gt;&lt;br /&gt;'proceess the value from that column&lt;br /&gt;&lt;br /&gt;rowcnt=exp_rangeobj.rows.count&lt;br /&gt;&lt;br /&gt;		'Strat reading the values from the 2nd row since the first row contains the column names.&lt;br /&gt;		If rowcnt &gt; 1 Then&lt;br /&gt;			For i=2 to rowcnt				 &lt;br /&gt;				'process the expected file row if it has a value&lt;br /&gt;				If  Len(Trim(exp_rangeobj.cells(i,1).value))&gt;0 Then &lt;br /&gt;					posIndex = (exp_rangeobj.cells(i,pos_id_idx).value) -1&lt;br /&gt;				end if&lt;br /&gt;			next &lt;br /&gt;		end if&lt;br /&gt;		&lt;/code&gt;</description>
      <pubDate>Wed, 18 Jul 2007 14:14:08 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4317</guid>
      <author>sarunbe (Arun Kumar)</author>
    </item>
  </channel>
</rss>
