Home > Backend Development > C++ > How Can I Create Excel Files in C# Without Using Microsoft Office?

How Can I Create Excel Files in C# Without Using Microsoft Office?

Linda Hamilton
Release: 2025-02-02 23:26:10
Original
164 people have browsed it

How Can I Create Excel Files in C# Without Using Microsoft Office?

In C#, no Microsoft Office is required to create an excel file

Many developers need to create an excel table in the application without relying on Microsoft Office. In C#, some libraries can help programmers realize this.

A commonly used option is

Excellibrary

, an open source library that can be obtained on Google Code. Although it mainly supports the older .xls format, it provides a simple and easy -to -use interface. In addition, Excellibrary contains a DataSethelper, which is convenient for seamless integration with DataSet and DataTable. Another feasible alternative is

Epplus

, which is compatible with the newer .xlsx format used in Excel 2007 and higher versions. It has active development and comprehensive documents.

NPOI

is another option to support XLS and XLSX formats. However, due to its continuous update and functional enhancement, Epplus is widely considered the most powerful choice.

For example, Epplus supports data perspective tables, and other libraries may not support.

The following is an example of using

Excellibrary

Export the database data to the Excel workbook:

These libraries provide a convenient and efficient solution for the creation of the Excel file in C#, enabling developers to expand their applications' functions without Microsoft Office. Please note that in the above code example,

is replaced with a more standardized
DataSet ds = new DataSet("New_DataSet");
DataTable dt = new DataTable("New_DataTable");
OleDbConnection con = new OleDbConnection(dbConnectionString);
string sql = "SELECT Whatever FROM MyDBTable;";
OleDbDataAdapter adptr = new OleDbDataAdapter(sql, con); // 修正:将cmd替换为sql和con
adptr.Fill(dt);
ds.Tables.Add(dt);
ExcelLibrary.DataSetHelper.CreateWorkbook("MyExcelFile.xls", ds);
Copy after login
and

to ensure the correctness of the code. cmd

The above is the detailed content of How Can I Create Excel Files in C# Without Using Microsoft Office?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template