Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert CSV to Excel in C #

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to convert CSV to Excel in C#. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

A CSV (Comma Separated Values) file is a plain text file that contains data separated by commas and is often used to import or export data from one application to another. By converting CSV files to EXCEL, you can perform more operations about data editing, formatting, and so on.

I. Program environment

The Excel library can be installed in the following ways:

1. Install Spire.XLS through NuGet

two。 Officially download the package, extract and install it to the local specified path. Open solution Explorer in Visual Studio and add a reference to the program from the dll under the Bin folder under the local installation path.

Second, convert CSV to Excel

C#

Using Spire.Xls;namespace CSVtoExcel_XLS {class Program {static void Main (string [] args) {/ / load the CSV file Workbook workbook = new Workbook (); workbook.LoadFromFile ("test.csv", 1,1); / / get the first worksheet Worksheet sheet = workbook.Worksheets [0] / / access the range used in the worksheet CellRange usedRange = sheet.AllocatedRange; / / ignore the error usedRange.IgnoreErrorOptions = IgnoreErrorType.NumberAsText; / / Adaptive row height and column width usedRange.AutoFitColumns (); usedRange.AutoFitRows () when saving the numbers in the range as text / / Save document workbook.SaveToFile ("result.xlsx", ExcelVersion.Version2013); System.Diagnostics.Process.Start ("result.xlsx");}

VB.NET

Imports Spire.XlsNamespace CSVtoExcel_XLS Class Program Private Shared Sub Main (args As String ()) 'loads the CSV file Dim workbook As New Workbook () workbook.LoadFromFile ("test.csv", 1 1) 'get the first worksheet Dim sheet As Worksheet = workbook.Worksheets (0)' access the range Dim usedRange As CellRange = sheet.AllocatedRange used in the worksheet when saving the numbers in the range as text Ignore the error usedRange.IgnoreErrorOptions = IgnoreErrorType.NumberAsText 'Adaptive row height and column width usedRange.AutoFitColumns () usedRange.AutoFitRows ()' Save document workbook.SaveToFile ("result.xlsx", ExcelVersion.Version2013) System.Diagnostics.Process.Start ("result.xlsx") End Sub End ClassEnd Namespace

This is the end of the article on "how to convert CSV into Excel in C#". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report