如何读取和写入excel并从excel中删除不需要的字符 [英] How to Read and write to excel and remove unwanted characters from the excel
问题描述
嗨伙计,
我想构建一个appplication,它读取excel,写入对新excel的更改:
一些请求是:
我有一个Excel(.csv),里面包含很多不需要的字符,比如
单引号,双引号,逗号。所以我想删除excel(.csv)的所有这些不需要的字符。并更新excel(.csv)并存储新的excel(.csv)。
我有很多带有不需要的字符的.csv文件所以我想让它自动使用C#代码
任何人都可以帮助我。
PIEBALDconsult写道:
你可以很容易地做到这一点,但它可能不再是一个CSV。
这是真的。
我建议您使用ADO.NET来读写* .csv文件: 从.NET应用程序访问Microsoft Office数据 [ ^ ]
如何使用ADO.NET使用Visual Basic .NET在Excel工作簿中检索和修改记录 [ ^ ] - 我知道它是VB.NET,但VB.NET与C#非常相似。
如果您仍想更改某些值,请查看此处: Range.Replace方法 [ ^ ]
您可以使用功能强大的命令行工具Microsoft Log Parser 2.2 [ ^ ],将CSV和其他文件转换为所需文件。
您也可以尝试 gwebcmd [ ^ ]命令行工具。
它允许您将不同的csv格式转换为多种统一格式,以便进一步导入数据库。
例如,要更改分隔符,请运行:
gwebcmd texttocsv src.csv dest.csv / separator =;
此外,您可以在导入之前将多个csv文件合并为一个大文件以减少导入时间。
>
你必须使用LinqToExcel dll。从nuget下载你将能够在工作簿上进行所有类型的操作。 http://www.codeproject.com/Articles/659643/Csharp-Query-Excel-and-CSV-Files-Using-LinqToExcel
Hi Folks,
I would to build an appplication which reads excel, writes changes to the new excel:
some requests are:
I have an Excel(.csv) which contains lot of unwanted characters like
single quotes, double quotes, comma. So I want to remove all these unawanted charaters for the excel(.csv). And update the excel(.csv) and store new excel(.csv).
I have many .csv files with unwanted characters so i want to make it automated using C# code
Can any one please help me on this.
PIEBALDconsult wrote:
You can do that very easily, but then it might no longer be a CSV.
It's true.
I'd suggest you to use ADO.NET to read and write *.csv files: Accessing Microsoft Office Data from .NET Applications[^]
How To Use ADO.NET to Retrieve and Modify Records in an Excel Workbook With Visual Basic .NET[^] - i know it's VB.NET, but VB.NET is quite similar to C#.
In case you'll still want to change some values, have a look here: Range.Replace method[^]
You may use a powerful command line tool, Microsoft Log Parser 2.2[^], to transform CSV and other files to a desired file.
Also you may try the gwebcmd[^] command line tool.
It allows you to transform different csv formats into several unified formats for futher import into databases.
For example, to change the separator, run:
gwebcmd texttocsv src.csv dest.csv /separator=;
In addition, you may combine multiple csv files into a one big file before importing to reduce import time.
you have to use LinqToExcel dll. download from nuget u wil be able to do all sort of operation on workbook. http://www.codeproject.com/Articles/659643/Csharp-Query-Excel-and-CSV-Files-Using-LinqToExcel
这篇关于如何读取和写入excel并从excel中删除不需要的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!