简体   繁体   English

使用C#作为字符串导入Excel(.xlsx)数据

[英]Import Excel (.xlsx) data using C# as strings

I am trying to import data from an .xlsx document. 我正在尝试从.xlsx文档导入数据。 It keeps reading the data types incorrectly. 它会继续错误地读取数据类型。 I need every column to come in as a string. 我需要每一列都以字符串形式出现。

My connection string looks like this: 我的连接字符串如下所示:

"Provider=Microsoft.ACE.OLEDB.12.0; Data Source = " + FileName + "; Extended Properties = 'Excel 12.0 Xml; HDR = Yes; IMEX = 1';"

You may want to try something like linqtoexcel this turns excel worksheets into objects which can be queried using linq queries. 您可能要尝试使用linqtoexcel之类的东西,这会将excel工作表转换为可以使用linq查询查询的对象。 Then you can turn columns into string if you want to by quering the linq objects. 然后,您可以通过查询linq对象将列转换为字符串。

you will find some documentation about how to read an excel file here (interop) 您将在此处找到一些有关如何读取Excel文件的文档(互操作)

If you need information about connection string I think this website could be helpful : http://connectionstrings.com/ 如果您需要有关连接字符串的信息,我认为该网站可能会有所帮助: http : //connectionstrings.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM