Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6884773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:33:04+00:00 2026-05-27T05:33:04+00:00

I have a ListView which after populating it, will look like this: I already

  • 0

I have a ListView which after populating it, will look like this:

enter image description here

I already can export it to a CSV formatted file using the following code:

StringBuilder sb = new StringBuilder();

//Making columns!
foreach (ColumnHeader ch in lvCnt.Columns)
{
    sb.Append(ch.Text + ",");
}

sb.AppendLine();

//Looping through items and subitems
foreach (ListViewItem lvi in lvCnt.Items)
{
    foreach (ListViewItem.ListViewSubItem lvs in lvi.SubItems)
    {
        if (lvs.Text.Trim() == string.Empty)
            sb.Append(" ,");
        else
            sb.Append(lvs.Text + ",");
    }
    sb.AppendLine();
}

But the problem is, in CSV, I can not export the back color of the ListView items and subitems, which in my case are very important. Would be nice if you can help me with this or at least point me to the right direction!

UPDATE

I managed to find a way to export directly to Excel, but I still can not export the background color of ListView items into Excel.

private void ToExcel()
{
    Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
            app.Visible = true;
    Microsoft.Office.Interop.Excel.Workbook wb = app.Workbooks.Add(1);
    Microsoft.Office.Interop.Excel.Worksheet ws = (Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets[1];
        int i = 1;
        int i2 = 1;
        foreach (ListViewItem lvi in myList.Items)
        {
            i = 1;
            foreach (ListViewItem.ListViewSubItem lvs in lvi.SubItems)
            {                   
                ws.Cells[i2, i] = lvs.Text;
                i++;
            }
            i2++;
        }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:33:05+00:00Added an answer on May 27, 2026 at 5:33 am

    Seems like this is a pretty easy project to export your data with:

    • http://epplus.codeplex.com/wikipage?title=WebapplicationExample

    It has examples showing how to set background colours and other formatting items.

    You already have your code to loop through the headers and rows so you should be able to work with it!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listview which has its datasource changed after update of a search
This is a very common scenario: displaying images in a ListView which have to
I have seen some ListView dynamic growing implementations which use OnScrollListener. I would like
I have found this example Lazy load of images in ListView from Fedor which
I have a listView displaying a bunch of graphs. I can sort this listview
I have a ListView which sometimes I need to put around 10000 items in.
I have a ListView which is using a GridView to display a DataTable and
I have a WPF ListView which repeats the data vertically. I cannot figure out
I have the following ListView in which I am using the JQuery UI sortable
I have an app with a large ListView which is terribly slow so I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.