We help IT Professionals succeed at work.

vb.net Create excel sheet without Excel

Medium Priority
724 Views
Last Modified: 2012-06-27
Hey,

I am looking for a way to reading and writing to excel sheets without the requirement of a specific Excel version being installed on the client PC.  Even though the PC will most likely have some version Excel installed, my company isn't locked down to one particular version.  That has caused me problems in the past.

To read excel sheets i have been using ODBC and that works fine, but i would like to come up with some standard way of being able to create excel sheets and not have to depend on the PC's installed version.

I have seen a few 3rd part components that would seem to be what i am looking for.  Does anyone have any experience with these components or another method?  To give a little scope, i don't need to be doing anything too complex with the sheets.  Just reading, writting, and some basic formatting..

Any suggestions on components (you have actual experience with) or alternative methods of accomplishing my goal are appreciated.
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
MRS

Author

Commented:
Thank you both for the suggestions...

Code,

I have looked at the Apose Suite before, but they are out of my price range.  at $6000 per developer license it would be cheaper to but everyone in the company office..

Mrugesh1,
Have you had any experience with the GemBox component.  The price seems a little more reasonable if it works as well as it says it does.
I like using the Excel COM object.  It's free with the application and has been around for several versions.  The syntax may change a bit from version to version, but if you're truly working on basic functionality, that shouldn't impact you.  I'll include a basic VBScript version of interacting with the object.  There is a TON of documentation on it, and you can include a reference to it from Visual Studio as well.  The intellisense there should help you figure out the specifics for your application.

The object model is here.
http://msdn.microsoft.com/en-us/library/wss56bz7%28v=vs.80%29.aspx

 
'Set output file name
Dim xls
xls = xlFilePath & "\" & xlFileName

'Create the excel application object
Dim Excel
Set Excel = CreateObject("Excel.Application")
Excel.DisplayAlerts = False

'Open the xls file if it exists, or create a new file if it does not exist
Dim wb
On Error Resume Next
err.Clear
Set wb = Excel.Workbooks.Open(xls)
If err.Number = 1004 Then
	err.Clear
	Set wb = Excel.Workbooks.Add()
End If
If err.Number <> 0 Then
	Exit Sub
End If
On Error GoTo 0

'Create excel worksheet and cell objects
Dim ws, c, pg
Set ws = wb.Sheets(1)
Set c = ws.Cells

'Add values to the spreadsheet
c(1,1).value = "TESTING1"
c(1,2).value = "TESTING2"
c(1,3).value = "TESTING3"
c(1,4).value = "TESTING4"
c(1,5).value = "TESTING5"

'Save the xls file
On Error Resume Next
err.Clear
'Save the xls file
wb.SaveAs(xls)
If err.Number = 1004 Then
	Set c = Nothing
	Set ws = Nothing
	Set wb = Nothing
	Set Excel = Nothing
	Exit Sub	
End If
On Error GoTo 0

'Close the xls file
wb.Close

Open in new window

MRS

Author

Commented:
stuartmorris,

Your example is what I have done in the past.  I am trying to get away from untyped objects like that.

I have decided to go with the Gembox component.  The price is fair and the component seems do to everything i need.  Thank you all for your input.

MRS

Author

Commented:
I went with the GemBox component that was linked at the bottom of the forum page you linked.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.