Solved

Manage Excel files with C#

Posted on 2014-10-31
5
153 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 34

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 26

Accepted Solution

by:
ProfessorJimJam earned 500 total points
ID: 40417719
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

632 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