Ram
Ram

Reputation: 921

How to read data from one xls file and write it into another xls file

I have dev.xls file with sheet name as "Electricity". In my vb.net winform application, I want to read all this data and write it into another xls file (Test.xls) with sheet name as "Electricity_Processed".

Looking for a way to do this without using other dll's or Interop

Any suggestions please?

Upvotes: 0

Views: 440

Answers (3)

SSS
SSS

Reputation: 5403

A more serious answer is to use late binding. Late binding however requires that MS Excel is installed on the system running the program.:

Option Strict Off

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim xl As Object = CreateObject("Excel.Application")
    xl.visible = True
    xl.Workbooks.Open("C:\junk\junk.xls")
    Dim sht1 As Object = xl.Sheets(1) '1-based
    Dim rng As Object = sht1.Range("A2", "A2") 'get the cell
    MsgBox(rng.Value) 'show the value
    Dim rng2 As Object = sht1.Range("B3", "B3") 'get the cell
    rng2.Value = "Hello" 'set the value
  End Sub
End Class

Upvotes: 0

Heinzi
Heinzi

Reputation: 172448

You can use OleDb, which supports reading and writing of Excel files. Google with the keywords OleDb and Excel has tons of results, and there's also a Microsoft KB article on exactly this subject:

Basically, you can use simple SELECT statements to read data, and INSERT statements to write data. Excel sheets are represented as tables, so you can use CREATE TABLE to create your Electricity_Processed sheet.

Upvotes: 1

SSS
SSS

Reputation: 5403

No DLLs or Interop? You can write your own XLS parser, I suppose :-) The XLS format is described here: http://www.wotsit.org/list.asp?fc=6

Upvotes: 0

Related Questions