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

  • SEARCH
  • Home
  • 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 8026641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:33:28+00:00 2026-06-04T23:33:28+00:00

I want to add to my application an ability to save data to XLS

  • 0

I want to add to my application an ability to save data to XLS (old excel files).

I’ve seen an example on how to do this in ASP.NET here, but I don’t know how this translates into c# code for desktop applications.

I also had a look at excel automation, which looks like this:

private void button1_Click(object sender, EventArgs e)
{
    Excel.Application xlApp ;
    Excel.Workbook xlWorkBook ;
    Excel.Worksheet xlWorkSheet ;
    object misValue = System.Reflection.Missing.Value;

    xlApp = new Excel.ApplicationClass();
    xlWorkBook = xlApp.Workbooks.Add(misValue);

    xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
    xlWorkSheet.Cells[1, 1] = "http://csharp.net-informations.com";

    xlWorkBook.SaveAs("csharp-Excel.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
    xlWorkBook.Close(true, misValue, misValue);
    xlApp.Quit();

    releaseObject(xlWorkSheet);
    releaseObject(xlWorkBook);
    releaseObject(xlApp);

    MessageBox.Show("Excel file created , you can find the file c:\\csharp-Excel.xls");
}

private void releaseObject(object obj)
{
    try
    {
        System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
        obj = null;
    }
    catch (Exception ex)
    {
        obj = null;
        MessageBox.Show("Exception Occured while releasing object " + ex.ToString());
    }
    finally
    {
        GC.Collect();
    }
}

And I don’t want to use it because:

  1. It will be ueberslow if I export large amounts of data

  2. I want this to work on PCs without Microsoft Excel installed if possible

I’ve also tried CarlosAg.Excel.Xml, and it seems to work, except that when I’m opening the file, I’m getting warning from excel, that the file is not in XLS format, but some other one.

Can anyone recommend to me a free c# library which would do this, or show me how to use conventional .Net libraries to save the data to XLS?

  • 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-06-04T23:33:29+00:00Added an answer on June 4, 2026 at 11:33 pm

    Use NOPI, which available on codeplex.com

    This project is the .NET version of POI Java project at
    http://poi.apache.org/. POI is an open source project which can help
    you read/write xls, doc, ppt files. It has a wide application.

    Here’s an example on how to use NOPI:

            using (FileStream fileOut = new FileStream("poi-test.xls", FileMode.OpenOrCreate))
            {
                HSSFWorkbook workbook = new HSSFWorkbook();
                var worksheet = workbook.CreateSheet("POI Worksheet");
    
                // index from 0,0... cell A1 is cell(0,0)
                var row1 = worksheet.CreateRow((short)0);
    
                var cellA1 = row1.CreateCell((short)0);
                cellA1.SetCellValue("Hello");
                ICellStyle cellStyle = workbook.CreateCellStyle();
                cellStyle.FillForegroundColor = HSSFColor.GOLD.index;
                cellStyle.FillPattern = FillPatternType.SOLID_FOREGROUND;//.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
                cellA1.CellStyle = cellStyle;
    
                ICell cellB1 = row1.CreateCell((short)1);
                cellB1.SetCellValue("Goodbye");
                cellStyle = workbook.CreateCellStyle();
                cellStyle.FillForegroundColor = HSSFColor.LIGHT_CORNFLOWER_BLUE.index;
                cellStyle.FillPattern = FillPatternType.SOLID_FOREGROUND;
                cellB1.CellStyle = cellStyle;
    
                var cellC1 = row1.CreateCell((short)2);
                cellC1.SetCellValue(true);
    
                var cellD1 = row1.CreateCell((short)3);
                cellD1.SetCellValue(new DateTime());
                cellStyle = workbook.CreateCellStyle();
                cellStyle.DataFormat = HSSFDataFormat
                        .GetBuiltinFormat("m/d/yy h:mm");
                cellD1.CellStyle = cellStyle;
    
                workbook.Write(fileOut);
            }
    

    Ref:
    Creating Excel spreadsheets .XLS and .XLSX in C# by Leniel Macaferi .

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

Sidebar

Related Questions

I want to add the ability in my application which is using Spring framework
Im writing WPF application and want to add ability to call jump list and
In my WPF 4.0 desktop-based application, I want to add an ability to traverse
Basically I want to add my application to the application chooser list for files
I want to add in my application functionality to decompress (and optionally compress) files
I have the following HTML code in my ASP.NET application and I want to
I have an application to which I want to add the ability to import
In my application i want to add more than two markers in a Google
In my application I want to add a simple animation to buttons and other
I want to add a feature to our application that let's a user know

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.