Solved

Manage Excel files with C#

Posted on 2014-10-31
5
148 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 33

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 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