Excel worksheet

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello all,

Am not sure if this is the right newgroup.

I want to open and excel worksheet from VB.Net, populate data and save it.

Any idea how it can be done?

Thanks in advance
Regards
Ishan
 
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim xlWS As Excel.Worksheet

Dim inVal As Object

'Create Report Name for this month
Dim sRept As String = "fullpath to sheet..XLS"

'Open the report template
inVal = New System.Runtime.InteropServices.DispatchWrapper(Nothing)
xlApp = CType(CreateObject("Excel.Application"), Excel.Application)
xlApp.Visible = False 'True if you want to see it on the screen
xlWB = xlApp.Workbooks.Open(sRept )
xlWS = CType(xlWB.Sheets(1), Excel.Worksheet)
xlWS.PageSetup.RightHeader = "Last Updated: " & Format(Today, "dd-MMM-yy")

Dim nCol, nRow as Integer
'To save word Data in cell B3
nRow = 3
nCol = 2

xlWS.Cells(nRow, nCol) = "Data"

'Save & Close the Excel Sheet
xlWB.Close(SaveChanges:=True)
xlApp.Visible = True
xlApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
 
Back
Top