Quick Tip: How to work with Excel files in VB.Net (Update)

יום שני, פברואר 23, 2009

This is an update for previous post. Added new function to read entire content of Excel File:       ''' <summary>      ''' Reads the data from excel file.      ''' </summary>      ''' <param name="strFilePath">The file path.</param>      ''' <returns>DataSet</returns>      Public Shared Function ReadDataFromExcelFile(ByVal strFilePath As String) As DataSet            If strFilePath Is Nothing Then Throw New NullReferenceException("strFilePath")            If Not File.Exists(strFilePath) Then Throw New FileNotFoundException(strFilePath)              ' copy source excel file to temp. folder (because the original file can be locked by other process)            Dim tmpFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)            If Not Directory.Exists(tmpFolder) Then tmpFolder = Environment.CurrentDirectory              Dim tmpPath As String = _           ...

Quick Tip: How to work with Excel files in VB.Net

יום שלישי, יולי 8, 2008

Recently I've being asked by friend to show him a simple way to read/write data from/to MS Excel files. I found my old project with very simple method of working with excel files by using Microsoft.Jet.OLEDB.4.0 Provider (similar to MS Access). This is one of many methods to work with excel files. Read data from Excel Sheet:     ''' <summary>     ''' Reads the data from excel file.     ''' </summary>     ''' <param name="strFilePath">The file path.</param>     ''' <param name="strSheetName">Name of the sheet.</param>     ''' <returns></returns>     Public Function ReadDataFromExcelFile(ByVal...