Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Manage Excel files with C#

Posted on 2014-10-31
5
Medium Priority
?
157 Views
Last Modified: 2014-11-03
HI

I am converting a VB.NET application to C# that uses Excel files. I have tried to search for how to use Excel files in C#, but I just can’t get any of it to work. I’m not experienced in C# so I don’t see the issues so easily.

Can someone help me with some simple example code that …
Opens an existing Excel file
Creates a new Excel file
Reads values from a Worksheet
Write values to a worksheet
Closes the Excel file

I’m using Visual Studio 2008 and Excel 2003.
0
Comment
Question by:daghoff
5 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 40417133
you already have VB code? check this converter: http://converter.telerik.com/
0
 
LVL 25

Expert Comment

by:apeter
ID: 40417330
You want to duplicate the file ?
0
 
LVL 35

Expert Comment

by:it_saige
ID: 40417335
I was going to suggest using a converter.  However, first, is this truly a VB.NET application or VB6?

-saige-
0
 

Author Comment

by:daghoff
ID: 40417565
Hi

Thanks for your answerers, but you have misunderstood. I am not looking for converters. I already have tested many of them for the conversion, but the problem is that converters don’t do a really good job. And they do not successfully convert my Excel code that works well in my VB applications.

So I have decided to rebuild that code from scratch. I have tried most of what I find on webs, but there is always something that does not work. Probably because I use an old version of Visual Studio and Excel. I’m also inexperienced with C#.

My most successful attempt comes from this link:
 http://csharp.net-informations.com/excel/csharp-open-excel.htm.

It should work since it is a fully working example, but I get the error
 “Object reference not set to an instance of an object.”
 In this line:
MessageBox.Show(xlWorkSheet.get_Range("A1", "A1").Value2.ToString());

And I don’t see what the problem can be since the Excel Workbook apparently opens. Or does it not?

This is what I need your help with. I’ll deal with all the other C# problems later.

Regards.
0
 
LVL 27

Accepted Solution

by:
ProfessorJimJam earned 2000 total points
ID: 40417719
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question