Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I want help in transferring data from a list<int> to an xls which has just one column. Can anyone please help me? Thank You.
Posted
Comments
Nelek 25-Nov-12 16:41pm    
Yes, there are people here capable to help you but...
Please don't think we can read minds or do astral projections to see your monitor. If you need help, the least you could do is to add some relevant code to your question or to explain your problem in such a way, that the users of CP can understand it. Otherwise, nobody will be able to help you.
what have you tried?[^]

hello;

hope that will help :

<pre lang="c#">Microsoft.Office.Interop.Excel.Application xla = new Microsoft.Office.Interop.Excel.Application();

xla.Visible = true;

Microsoft.Office.Interop.Excel.Workbook wb = xla.Workbooks.Add(Microsoft.Office.Interop.Excel.XlSheetType.xlWorksheet);

Microsoft.Office.Interop.Excel.Worksheet ws = (Microsoft.Office.Interop.Excel.Worksheet)xla.ActiveSheet;

int i = 1;

int j = 1;

foreach (ListViewItem comp in listView1.Items)

{

ws.Cells[i, j] = comp.Text.ToString();

//MessageBox.Show(comp.Text.ToString());

foreach (ListViewItem.ListViewSubItem drv in comp.SubItems)

{

ws.Cells[i, j] = drv.Text.ToString();

j++;

}

j = 1;

i++;

}


regards...
 
Share this answer
 
You can treat an xls file as a database table (the workbook is the database and the worksheet is the table)
and write to it using the classes in System.Data.Oledb. The database connectionstring to use can be found at http://www.connectionstrings.com/excel[^]

In your case, the simplest solution might be just to write your data as text, one item per line, and give the output file a .csv extension. Opening the text file in excel will automatically convert it , then you can "save as" xls or xlsx.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900