473,394 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 36535
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',...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.