472,988 Members | 2,643 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,988 software developers and data experts.

Simple C# to Excel Export

Hi everyone
I've got a very basic program that lists drivespace stats of important network computers. I want to export the variable data to excel so i can do a trend analysis over a given time to help predict when our servers will run out of space.
No fancy formatting is needed.

Any help will be much appreciated

Thanks
Gustav
May 22 '07 #1
5 36489
to answer my own question...:)
i figured it out, much simpler than i thought
so if anyone has a similar question, hope this helps:
it pulls data out of a listview and pumps it into Excel 2007.
Make sure you have the correct references.
Expand|Select|Wrap|Line Numbers
  1. Microsoft.Office.Interop.Excel.Application xla = new Microsoft.Office.Interop.Excel.Application();
  2.  
  3.             xla.Visible = true;
  4.             Workbook wb = xla.Workbooks.Add(XlSheetType.xlWorksheet);
  5.             Worksheet ws = (Worksheet)xla.ActiveSheet;
  6.             int i = 1;
  7.             int j = 1;
  8.             foreach (ListViewItem comp in lvwResults.Items)
  9.             {
  10.                 ws.Cells[i, j] = comp.Text.ToString();
  11.                 //MessageBox.Show(comp.Text.ToString());
  12.                 foreach (ListViewItem.ListViewSubItem drv in comp.SubItems)
  13.                 {
  14.                     ws.Cells[i, j] = drv.Text.ToString();
  15.                     j++;
  16.                 }
  17.                 j = 1;
  18.                 i++;
May 22 '07 #2
kenobewan
4,871 Expert 4TB
Well done! Thanks for sharing the solution.
May 22 '07 #3
I have three list views in my code. How I can export each one to a specific sheet in the excel file? How I can also give each sheet name.
Apr 14 '09 #4
How do i test this code? Do i just copy this code and paste it in Visual studio? Im new to this. Need guidance. Thanks.
Dec 23 '09 #5
Her77
1
Hi, I'm Hernán from Argentina. I found the post very useful! Thanks a lot! Congratulations!
Jul 27 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Eric Johannsen | last post by:
Hi, Is there any open source / demo code that shows how to create a simple Excel 97 or later file without resorting to Interop? My application currently creates a simple CSV file, but I would...
0
by: Max Mayer | last post by:
Hello everybody, I have implemented a windows form in C# .NET to export data from a listbox to Excel. I work on a Windows XP machine with Office 97 and .NET framework 1.1 SDK installed. I use...
0
by: Max Mayer | last post by:
Hello everybody, I have implemented a windows form in C# .NET to export data from a listbox to Excel. I work on a Windows XP machine with Office 97 and .NET framework 1.1 SDK installed. I use...
0
by: arnab | last post by:
Dear All, I have a code which does Excel Export using ASP.NET Content disposition. The whole code works fine and opens up a dialog box to open,save when i click on the export button. If i save the...
8
by: Taffman | last post by:
I've searched this goup for an answer to this, there are many discussions that come close but non that I can find that actually addresses this particular problem. I'm exporting queries to Excel....
8
by: lostdog | last post by:
Hi all, I hope someone can help me. Running access 03 on win xp. I have a single table database which contains name, address and last contact date as its fields. The number of records is...
2
by: gokulin | last post by:
Hi All, I am writing an ASP.NET application in C# (an Application integrated and communicates with MS CRM) with Excel Export and Import options. The user of the system exports data from the...
6
by: Sergio E. | last post by:
Hi, I'm looking for information about gridview's cell properties... I've the following case: one gridview with alternatirg row style and normalrowstyle, 3 o 4 custom styles that are applied to...
1
by: RobinAG | last post by:
Hello, I'm trying to create a new Excel document from a template I've created (Export.xls). I'm having trouble getting it to work, sometimes it works, sometimes it gives me a run-time error '70',...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.