Nuget read write file excel top 2023 free năm 2024

I created new app using .NET 7 preview VS 2022, while I also created WPF App with .NET 6 stable. Just because of you to affirm.

Actually, my old applications works fine and the new one work fine too. However, see the below codes and steps:

using Microsoft.Office.Interop; using ExcelAdaptorLib = Microsoft.Office.Interop.Excel; using Excel = Microsoft.Office.Interop.Excel; using ExcelAdaptorLib;

namespace WpfAppExcel { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); }

    private void Button_Click(object sender, RoutedEventArgs e)  
    {  
        Excel.Application objExcel = new Excel.Application();  
        objExcel.Visible = true;  
    }  
}  

}

Now, before the above code add your reference in COM

Notice new version 16.0, also, check your package for alert, if there is any on security warning perhaps you add testing for excelTools, remove it for now.

The Excel spreadsheet is one of the best ways to present or store data. Automating the creation of Excel files can save us a lot of time and energy. In this article, I am going to introduce how to programmatically create an Excel file in Java and how to write strings, arrays, and DataTable into the specified cell or cell range by using Free Spire.XLS for .NET.

  • Write Strings to Specific Cells
  • Write Arrays to a Worksheet
  • Write a DataTable to a Worksheet

Add References

Method

1: Download Free Spire.XLS and unzip the package somewhere on your disk to find the “BIN” folder. Free Spire.XLS has the DLLs compiled for multiple versions of .NET Framework as well as for .NET Core and other platforms. Choose the DLLs from the folder that you exactly need and add them all as dependencies in your project.

Method

2: Create a .NET application in you Visual Studio, and install Free Spire.XLS directly through NuGet. NuGet package manager will automatically install the correct version that fits in with your application.

Write Strings to Specific Cells

Spire.XLS provides the Workbook class and the Worksheet class to represent an Excel document and a worksheet, respectively. Users are able to access a specific cell through the Worksheet.Range[int row, int column] property. Then, assign a text value or a number value to the cell through the Value or NunberValue property. The following are the detailed steps:

  • Create a Workbook object.
  • Clear the default worksheets using Workbook.Worksheets.Clear() method.
  • Add a worksheet using Workbook.Worksheets.Add() method.
  • Write values to cells through the Worksheet.Range[].Value property and the Worksheet.Range[].NumberValue property.
  • Save the workbook to an Excel file using Workbook.SaveToFile() method.

using Spire.Xls;namespace WriteDataToCellsOneByOne {

class Program  
{  
    static void Main(string[] args)  
    {  
        //Create a Workbook object  
        Workbook workbook = new Workbook();            //Remove default worksheets  
        workbook.Worksheets.Clear();            //Add a worksheet and name it  
        Worksheet worksheet = workbook.Worksheets.Add("WriteToCell");            //Write data to specific cells  
        worksheet.Range[1, 1].Value = "Student Name";  
        worksheet.Range[1, 2].Value = "Math";  
        worksheet.Range[1, 3].Value = "English";  
        worksheet.Range[1, 4].Value = "Total Marks";  
        worksheet.Range[2, 1].Value = "Hazel";  
        worksheet.Range[2, 2].NumberValue = 80;  
        worksheet.Range[2, 3].NumberValue = 78;  
        worksheet.Range[2, 4].NumberValue = 158;  
        worksheet.Range[3, 1].Value = "Tina";  
        worksheet.Range[3, 2].NumberValue = 98;  
        worksheet.Range[3, 3].NumberValue = 72;  
        worksheet.Range[3, 4].NumberValue = 170;            //Auto fit column width  
        worksheet.AllocatedRange.AutoFitColumns();            //Save to an Excel file  
        workbook.SaveToFile("WriteToCells.xlsx", ExcelVersion.Version2016);  
    }  
}  
}

Write Arrays to a Worksheet

Spire.XLS provides the Worksheet.InsertArrary() method, allowing programmers to write one-dimensional array or two-dimensional array into the specified cell range of a worksheet. The steps to write arrays to a worksheet are as follows:

  • Create a Workbook object.
  • Clear the default worksheets using Workbook.Worksheets.Clear() method.
  • Add a worksheet using Workbook.Worksheets.Add() method.
  • Create a one-dimensional array and a two-dimensional array.
  • Insert the arrays to worksheet using Worksheet.InsertArray() method.

using Spire.Xls;namespace WriteArraysToWorksheet {

class Program  
{  
    static void Main(string[] args)  
    {            //Create a Workbook instance  
        Workbook workbook = new Workbook();            //Remove default worksheets  
        workbook.Worksheets.Clear();            //Add a worksheet and name it  
        Worksheet worksheet = workbook.Worksheets.Add("InsertArrays");            //Create a one-dimensional array  
        string[] oneDimensionalArray = new string[] { "January", "February", "March", "April", "May", "June" };            //Write the array to the first row of the worksheet  
        worksheet.InsertArray(oneDimensionalArray, 1, 1, false);            //Create a two-dimensional array  
        string[,] twoDimensionalArray = new string[,]{{"Name", "Age", "Sex", "Dept.", "Tel."},  
            {"John", "25", "Male", "Development","654214"},  
            {"Albert", "24", "Male", "Support","624847"},  
            {"Amy", "26", "Female", "Sales","624758"}  
        };            //Write the array to the worksheet starting from the cell A3  
        worksheet.InsertArray(twoDimensionalArray, 3, 1);            //Auto fit column width in the located range  
        worksheet.AllocatedRange.AutoFitColumns();            //Save to an Excel file  
        workbook.SaveToFile("InsertArrays.xlsx", ExcelVersion.Version2016);  
    }  
}  
}

Write a DataTable to a Worksheet

To write data from a DataTable to a worksheet, use Worksheet.InsertDataTable() method. The following are the steps to write a DataTable to a worksheet using Free Spire.XLS.

How to read Excel files using ironxl?

Below is a summary of the overal workflow for reading Excel files using IronXL: Install the IronXL Excel Library. We can do this using our NuGet package or by downloading the .Net Excel DLL. Use the WorkBook.Load method to read any XLS, XLSX or CSV document. Get Cell values using intuitive syntax: sheet ["A11"].DecimalValue

Can epplus read Excel 2007/2010 files?

I would suggest giving it a try. Dont forget on the condition that: "EPPlus is a .net library that reads and writes Excel 2007/2010 files using the Open Office Xml format (xlsx)." So .xls file will not work. The link no longer works.

Why does exceldatareader throw a 'no data is available for encoding 1252'?

By default, ExcelDataReader throws a NotSupportedException "No data is available for encoding 1252." on .NET Core and .NET 5.0 or later. To fix, add a dependency to the package System.Text.Encoding.CodePages and then add code to register the code page provider during application initialization (f.ex in Startup.cs): System. Text.

Does exceldatareader support formatting?

ExcelDataReader does not support formatting directly. Users may retreive the number format string for a cell through IExcelDataReader.GetNumberFormatString (i) and use the third party ExcelNumberFormat library for formatting purposes.

Is Spire XLS free?

Category: Free Spire.XLSIt is totally free without any warning message for your commercial and personal use. Free version is limited to 5 sheets per workbook and 200 rows per sheet. This limitation is enforced during reading or writing XLS or PDF files.

Is GemBox spreadsheet free?

GemBox. Spreadsheet works in four different modes: Free mode - free of charge, limited to 5 worksheets and 150 rows per worksheet. Trial mode - free of charge, randomly selected cells will have their value replaced with string TRIAL.

What is the best library to read Excel C#?

IronXL is the leading C# Excel library for generating and editing Excel documents in . NET. Its user friendly API allows developers to add Excel functionality to . NET projects in minutes.

How can I read Excel files for free?

6 Ways to Open XLS and XLSX Files for Free.

Office Editing for Docs, Sheets & Slides..

Google Sheets..

LibreOffice Calc..

Apache OpenOffice..

Aspose Excel Viewer..

Zoho Sheet..