Free Library Recommendation for Excel Operations in C#

fatih uyanık 225 Reputation points
2025-03-19T10:12:22.9766667+00:00

Hello,

I am developing a project in C# where I need to export data to an Excel file and import it back into my application. I initially considered using the EPPlus library, but since it requires a license for commercial use, I am concerned that it might cause issues in the future.

Could you recommend a comprehensive free library that allows me to read and write data, add comments to cells if necessary, and adjust column widths, even when Microsoft Office is not installed?

Thank you in advance!

Developer technologies | C#
0 comments No comments
{count} vote

Accepted answer
  1. Anonymous
    2025-03-19T12:15:53.9733333+00:00

    Hi @fatih uyanık , Welcome to Microsoft Q&A,

    ClosedXML has an MIT license, suitable for commercial use. (This forum does not recommend the use of third-party products, nor does it provide subsequent support for them. Use with caution.)

    using ClosedXML.Excel;
    using System;
    
    namespace xxx
    {
        internal class Program
        {
            static void Main(string[] args)
            {
                using (var workbook = new XLWorkbook())
                {
                    var worksheet = workbook.Worksheets.Add("data");
    
                    worksheet.Cell(1, 1).Value = "ID";
                    worksheet.Cell(1, 2).Value = "Name";
                    worksheet.Cell(1, 3).Value = "Age";
    
                    worksheet.Cell(2, 1).Value = 1;
                    worksheet.Cell(2, 2).Value = "Zhang San";
                    worksheet.Cell(2, 3).Value = 30;
    
                    int currentRow = 1;
                    int currentCol = 1;
                    string myComment = "This is a comment"; worksheet.Cell(currentRow, currentCol).GetComment().AddText(myComment);
    
                    worksheet.Columns().AdjustToContents(); // Automatically adjust column width
    
                    workbook.SaveAs("Sample.xlsx");
                }
    
                Console.WriteLine("Excel file created!");
            }
        }
    }
    

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    2 people found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Castorix31 90,686 Reputation points
    2025-03-19T13:04:56.4033333+00:00
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.