How to create a new Excel document in c#

G

Guest

I would like to create a new blank excel and set some header columns for the
user.

I try this code. It's work with Excel 2003 English but a got a error line 2
with all other version. (Excel 2003 french, Excel 2000, etc.)
---
Dim oExcel As New Microsoft.Office.Interop.Excel.Application
Dim oBook As Microsoft.Office.Interop.Excel.Workbook

Dim IsNewBook As Boolean = False
If File.Exists(FileName) Then
oBook = oExcel.Workbooks.Open(FileName)
Else
IsNewBook = True
oBook = CType(oExcel.Workbooks.Add(),
Microsoft.Office.Interop.Excel.Workbook)
End If

If oBook Is Nothing Then
Return False
End If

Dim oCell As Microsoft.Office.Interop.Excel.Range
oCell = oExcel.Range("A1")
oCell.Value2 = "LOCATION"
-----------

I use the reference:
Name: Microsoft.Office.Interop.Excel
Description: Microsoft Excel 11.0 Object Library

can someone can help me?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top