Solved

Manage Excel files with C#

Posted on 2014-10-31
5
142 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 69

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 32

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 25

Accepted Solution

by:
ProfessorJimJam earned 500 total points
ID: 40417719
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now