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 realize the conversion between txt and Excel with ADO.NET

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

Share

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

This article shows you how to use ADO.NET to achieve the conversion between txt and Excel, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

I have read a lot of articles in the garden, about design patterns, about architecture, and so on. Here I talk about some software functions and why they are needed.

Some time ago, I wrote a function about why TXT and EXCEL should be converted to each other. Some people may ask, what is the use of such a function? Yes, this small feature plays a great role in software development. There is no format for txt text, but excel documents are formatted. Converting things without format into things with format can be convenient for others to read. In addition, what the server of a lot of software sends to the client is something without format, that is, a string. The client receives this string and how to format it becomes something we need, such as excel documents. Conversely, if you have an excel document, you have to change it into a string before it can be sent to the server or to the caller. Of course, some people may say that the way of passing strings is very backward, there is now a standardized thing like webservice, webservice is formatted, and it is easy to transfer and parse, but if you write in C language in the background, or if you write in a lower-level language, and there is nothing similar to webservice, then you can only transfer character streams. In fact, webservice also transmits wsdl text, which itself is just a bunch of characters, but becomes something we need through some components, such as classes. Webservice is only a general standard, and it can also develop its own standard.

EXECL conversion TXT:

First of all, you need to read the EXCEL document, and the excel document can be read through ADO.NET 's Connection.

/ get excel / privateOleDbConnection getCon (stringexcelPath) {try {stringstrConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + excelPath + ";" + "Extended Properties=Excel 8.0;"; OleDbConnection conn = newOleDbConnection (strConn); conn.Open (); returnconn;} catch (Exception ex) {thrownewArgumentException ("Open excel failed", ex.Message);}}

Then, you need to read every page of the excel document, and read the contents of the excel

/ get excel page / publicstring [] getSheets (stringexcelPath) {OleDbConnection conn = getCon (excelPath); try {DataTable dtSheetName = conn.GetOleDbSchemaTable (OleDbSchemaGuid.Tables, newobject [] {null, "Table"}); string [] strTableNames = newstring [dtSheetName.Rows.Count]; inti = 0 for (intk = 0; k)

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