473,850 Members | 2,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Working with Excel

HI all,

I'm new to C#.
I want to open an excel document and work with it in C#.
I currently have Excel2000, I think it is version9.0. But Clients might have
office XP, XP2003 on
Could someone be so jind as to show me some code or point me in the right
direction.

Thanks
Robert
Jun 27 '06 #1
1 12636
Hi Robert, here you have a bit:

Microsoft.Offic e.Interop.Excel .Application app = new
Microsoft.Offic e.Interop.Excel .Application();

Microsoft.Offic e.Interop.Excel .Workbook book = null; //to access to book
Microsoft.Offic e.Interop.Excel .Worksheet sheet = null; //to access to sheet
Microsoft.Offic e.Interop.Excel .Range range = null; //to access to a range of
data "A1:B2"
book = app.Workbooks.O pen("c:\\test.x ls", Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value);

sheet = (Microsoft.Offi ce.Interop.Exce l.Worksheet)boo k.Worksheets.ge t_Item[1];

range = sheet.get_Range ("A1","B5");

Only take care about release resources from excel. Use ReleaseComObjec t
foreach com object that you use.

System.Runtime. InteropServices .Marshal.Releas eComObject(rang e);
System.Runtime. InteropServices .Marshal.Releas eComObject(shee t);
System.Runtime. InteropServices .Marshal.Releas eComObject(book );
System.Runtime. InteropServices .Marshal.Releas eComObject(app) ;

Hope this helps.
Regards.
Josema
"Robert Bravery" wrote:
HI all,

I'm new to C#.
I want to open an excel document and work with it in C#.
I currently have Excel2000, I think it is version9.0. But Clients might have
office XP, XP2003 on
Could someone be so jind as to show me some code or point me in the right
direction.

Thanks
Robert

Jun 27 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
20299
by: Otie | last post by:
I found the following under the GetObject help notes and in the example for GetObject: "This example uses the GetObject function to get a reference to a specific Microsoft Excel worksheet (MyXL). It uses the worksheet's Application property to make Microsoft Excel visible, to close it, and so on. Using two API calls, the DetectExcel Sub procedure looks for Microsoft Excel, and if it is running, enters it in the Running Object Table. The...
6
11696
by: Brent | last post by:
Having used every combonation of excel 9/10/11 and office 10/11 possible as references i still can not create an excel object! Any ideas? Just using this simple bit below i get "Excel.appication not defined" dim xlApp as Excel.Application, xlWs as Excel.WorkSheet set xlApp = new Excel.Application
2
1494
by: saeed rezaei | last post by:
hi i am saeed rezaei srezaii2000@yahoo.com who is knowh how i can changing the excel cells backcolor. now i can working whit excel but still i cant change the backcolor of cells.
3
1982
by: Michael Kellogg | last post by:
My application works with Excel to put together spreadsheets for reporting purposes. It runs just fine on my box, but when I put it on another one, it bombs. Here is the relevant code: Public Function ImportSis(ByVal strSisFile As String) As Boolean If m_Excel Is Nothing Then m_Excel = New Excel.Application End If
3
1464
by: jeremy.bird | last post by:
I am looking for a possible solution or bump in the right direction when working with excel on the web. Currently I am using and developing in visual studio 2005. Here is the situation I have a lot of spreadsheets with macros that I would like to deliver to people via a web application(read only for now maye not in the future).... Some problems that I am running into are: 1) macros do not work when embedding the excel sheet in the...
6
6687
by: AleydisGP | last post by:
I have a .plt file (which is a tab delimited ASCII file) and I want to format it to get a .dbf with data in rows and columns, detele some rows/columns and substitute decimal '.' with ','. All this using Python (I'm using Pythonwin). The .plt file looks like this: * ISCST3 (02035): Tersa * MODELING OPTIONS USED: * CONC URBAN ELEV DFAULT
0
7285
by: shantanu | last post by:
I am trying to convert a macro code to c# that will copy the values of a column and paste to anather through paste special. Everything is working fine but the transpose meathod to paste the column value as row value is not working. Can someone kindly look into the code, if i am missing something. C# Code ------------ private void ManipulateXLS() {
0
1574
by: mustaqueahmad | last post by:
Hi All, I am getting export to excel problem when I am giving IPAddress in URL, but it is working correct when am giving localhost and page name. eg : when I am writing My machine IP address and aspx pagename like 192.xxx.xxx.xx/exporttoexcell.aspx then popup page is not working. the popup page is being closed automatically , and export to excel option is not comming. for some reason when it opens within a scripted popup (js:...
2
3303
by: deepadevid | last post by:
Hi, when I tried to copy a worksheet programmatically in Excel 2007 the chartObjects are not getting copied. I am getting empty charts inside my new worksheet. This is working in Excel 2003. Excel.Application.Worksheets("Sheet1").ChartObjects.Count //I am getting 2 here. Excel.Application.worksheets("Sheet1").Copy After:= Excel.Application.Worksheets("Sheet2") Excel.Application.Worksheets("Sheet1 (2)").ChartObjects.Count // I am...
4
2579
by: stephen | last post by:
Hi all, I am working with Excel. I read an excel document using ExcelReader and lets say it has 10 columns. I have to read each record and based on a specified column peform some activites and then write the result at the end of the record (so will have 11 columns in total) At the same time, I am performing other calculations which has to be written at the end of the file (for eg. Total records, ..., ...). Currently, I am using...
0
9895
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9744
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10670
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9503
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7900
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5735
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5931
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4142
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3178
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.