• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1196
  • Last Modified:

How to manipulate Excel file from C# app. ?

Hi experts!

Im  using C# 2008 WinForm, NET2. I need to print data from my C# application into file of MS Excel 2003/2007. I need

1.      To open Excel file
2.      To fill it with data. I need to do some mark in some sheet of Excel which show me from where to start to insert my data.
3.      To create new page of this Excel file
4.      To Save this documents.

 Can somebody show me  with example witch object and which method to use ? Of course I have installed Office2007 in my computer.

0
dvplayltd
Asked:
dvplayltd
  • 3
  • 2
1 Solution
 
DhaestCommented:
Some articles, codesnippets:

How to automate Microsoft Excel from Microsoft Visual C# .NET
http://support.microsoft.com/kb/302084

Building an Excel sheet in C# the easy way
http://codebetter.com/blogs/peter.van.ooijen/archive/2005/10/20/133409.aspx

Opening and Navigating Excel with C#
http://www.codeproject.com/KB/office/csharp_excel.aspx
0
 
dvplayltdAuthor Commented:
More information.

Hi experts!

Im  using C# 2008 WinForm, NET2. I need to print data from my C# application into file of Excel. I need

1.      To open Excel file
2.      To fill it with data. I need to do some mark in the sheet of Excel which show me from which cell  to start to insert my data. Probably with give name of start cell.
3.      To create new page of this Excel file, new page to copy all properties of one which is already exiting page in this Excel file. I mean  graphic
4.      To Save this documents.
Can somebody show me  with example witch object and which method to use ? Of course I have installed Office2007 in my computer.
0
 
DhaestCommented:
Take a look at the links I've posted ...
0
 
dvplayltdAuthor Commented:
Yes - and I get Old format or INvlid type  labrary. I get this with refrence of Office 2003 and with Office 2007 (file which I try to open is with MS Excel 2003.  Here is code

And other question. I need to work both with Office 2003 and 2007 (depend what office is install on user computer). How to to this ? In COM there some called early and late bound - how is here ?

                Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
                excelApp.Visible = true;

                string workbookPath = @"c:\Template_Rule.xls";
                Microsoft.Office.Interop.Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath,
                    0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "",
                    true, false, 0, true, false, false);

                Microsoft.Office.Interop.Excel.Sheets excelSheets = excelWorkbook.Worksheets;


                string currentSheet = "Sheet1";
                Microsoft.Office.Interop.Excel.Worksheet excelWorksheet =
                    (Microsoft.Office.Interop.Excel.Worksheet)excelSheets.get_Item(currentSheet);

                Microsoft.Office.Interop.Excel.Range excelCell =
            (Microsoft.Office.Interop.Excel.Range)excelWorksheet.get_Range("A3", "A3");
                excelCell.Value2 = "Tryrrrrrrrr!";

                excelApp.Save(@"C:\NewName.xls");
                excelApp = null;
0
 
dvplayltdAuthor Commented:
Probably because this sample is fo Excel 10 (XP), I'm want sample for 11 (2003) or 12 (2007).
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now