k10n
Jim Klopfenstein's Radio Weblog

 



Subscribe to "k10n" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.
 
 

Late binding code samples

using System.Reflection;
using Microsoft.VisualBasic.CompilerServices;

private void button1_Click(object sender, EventArgs e) { int intCell; int intRow; Range objRange; Workbook objWorkbook; Worksheet objWorksheet; string strRow = ""; Microsoft.Office.Interop.Excel.Application xlApp;
xlApp = new ApplicationClass(); objWorkbook = xlApp.Workbooks.Open("SOLVSAMP.XLS", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); objWorksheet = (Worksheet) objWorkbook.Worksheets["Quick Tour"]; objRange = objWorksheet.get_Range("A2", "F16");
for (intRow=1; intRow <= 15; intRow++,strRow="") { for (intCell=1; intCell <= 6; intCell++) { strRow = StringType.FromObject ( ObjectType.StrCatObj ( ObjectType.StrCatObj ( strRow, LateBinding.LateGet ( objRange.Cells[intRow, intCell], null, "value", new Object[0], null, null ) ), "\t" ) ); } this.listBox1.Items.Add(strRow); } }


Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Dim xlApp As New Microsoft.Office.Interop.Excel.Application() Dim objWorkbook As Microsoft.Office.Interop.Excel.Workbook Dim objWorksheet As Microsoft.Office.Interop.Excel.Worksheet Dim objRange As Microsoft.Office.Interop.Excel.Range Dim intRow As Integer Dim intCell As Integer Dim strRow As String

objWorkbook = xlApp.Workbooks.Open("SOLVSAMP.XLS")



objWorksheet = objWorkbook.Worksheets.Item("Quick Tour") objRange = objWorksheet.Range("A2", "F16")
For intRow = 1 To 15
For intCell = 1 To 6
strRow = strRow & objRange.Cells(intRow, intCell).value & vbTab
Next intCell
Me.ListBox1.Items.Add(strRow) strRow = ""
Next intRow
End Sub


Click here to visit the Radio UserLand website. © Copyright 2003 Jim Klopfenstein.
Last update: 2/10/2003; 8:43:53 AM.