473,471 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to fill values in an Excel spreadsheet from c# ?

Hi all,
I'm just beginning with C#.
I have an Excel spreadsheet which I use to print invoices for my
company.
I'd like to fill some Excel's rows from my Visual C# project.
Which is the easiest way to do it ?
Thanks a lot
Francesco

Nov 16 '05 #1
5 10238
There are several approaches determined by the environemnt your code is
running in and the level of flexibility you need.

If you're writing a c# windows app you could use COM to open an excel
session and dump the data in.

If you're writing a c# web app without excel on the server the simplest
approach is to strip the page of all formatting, change the mime type to
excel and stream the results. There are numerous excellent articles on
the web - do a search for datagrid and excel in google.

Regards,

Chris

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2
Hello Chris,
thanks for your answer.
What I need is to write a c# widnwos app. Have you (or has anybody) got
a minimalist sample how to communicate with excel using COM ?
Thanks a lot
Francesco

Nov 16 '05 #3


I don't have anything readily to hand but there are numerous examples on
the microsoft site. I'm not sure how complex the excel spreadsheet is
you're trying to create. If its really simple you could save your
dataset as XML / csv and just open that up in Excel depending on which
version of Excel you're using.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4
Francesco -

I've recently completed a very simple Windows form application to
automate data loading with C# and Excel {open XLS, change date, update
XLS, save, load data into SQL Server, repeat}.

Here are the important Excel related statements assuming you've got the
PIA off of MSDN, installed and registered it (all part of the
directions).

object optional = Missing.Value;
object updateLinks = 0;
Microsoft.Office.Interop.Excel._Workbook wkb = app.Workbooks.Open
(fullname, updateLinks, optional, optional, optional, optional,
optional, optional, optional, optional, optional, optional, optional,
optional, optional);
Microsoft.Office.Interop.Excel._Worksheet wks =
(_Worksheet)wkb.Worksheets.get_Item(MySheet.Text);
wks.Activate();
wks.Visible = XlSheetVisibility.xlSheetVisible;
Range wksRange;
wksRange = wks.get_Range("H7", "H7");
wksRange.set_Value(Missing.Value, workingDate);
app.Calculate();
wkb.Save();
wkb.Close(false,Missing.Value,false);
app.Quit();
If this is too cryptic, drop me an email and I'll provide more detail.
Terry

Nov 16 '05 #5
jokabs_aquino
1 New Member
Hi all,
I'm just beginning with C#.
I have an Excel spreadsheet which I use to print invoices for my
company.
I'd like to fill some Excel's rows from my Visual C# project.
Which is the easiest way to do it ?
Thanks a lot
Francesco
If you're comfortable using ADO.NET architecture, you might want to check out www.connectionstrings.com. Look for the corresponding connection string for Excel. And from there, you'll get the idea. :)
Jun 14 '06 #6

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

Similar topics

0
by: Jeff | last post by:
I will start off by giving you a background of the process I am taking. The nature of my DTS package is that I recieve an Excel Spreadsheet, run it through the DTS Package applying validation to...
1
by: garry.oxnard | last post by:
Can anyone help me to solve a problem which involves switching from Access to Excel (then back to Access) programatically please? I have an Excel template which, on open, also opens an Access...
5
by: Paul H | last post by:
In my tblOrderDetails table I have the following fields: OrderID, OrderItemID and DeliveryDate. I need to loop trough each row in an excel spreadsheet and find OrderID and OrderItemID...
3
by: toffee | last post by:
Hi all, I got a pre-formatted spreadsheet. would it be possible using js to copy the data from a table on the current webpage, open the spreadsheet and paste the content ? if so, anyone got any...
4
by: NormAmst | last post by:
I have a list of CPU processing times and job durations for an entire department at work. There are 3 classifications I am maintaining. CPU time during peak hours , CPU time during non peak hours...
0
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I have a gridview. I calculated some values in the gridview for the footer of the gridview so basically I am adding all the values that are displayed in the gridview for each...
1
by: Sport Girl | last post by:
Hi everybody , i have the task of developing in Perl a script that retrieves data from 3 tables ( bugs, profiles, products) from a MySQL database called bugs and display them in an excel sheet...
0
by: dprjessie | last post by:
Hello, I am a Web programmer and I'm working on my first desktop application as a favor for a friend. I'm sure I have a stupid error here, but there is no error being thrown so I can't figure out...
6
by: JFKJr | last post by:
Hello everyone, the following is the Access VBA code which opens an excel spreadsheet and creates combo boxes dynamically. And whenever a user selects a value in a combo box, I am trying to pass...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.