简体   繁体   中英

How to update data in excel File using C#?

This Question might be repeated, But I couldn't get solution regarding my problem so far. I'm new to Interop. I'm using excel file (as a database). Here is data presentation in excel file

在此处输入图片说明

in my data If Card ID repeated then I need to increment '1' in Counter in the same row, similarly I need to fetch IP address of same row..

I'm using Interop Excel approach to insert data in excel file.. Kindly tell me how can I perform that update operation to that excel file through C# (WPF)

Sorry for bad English..

Thanks

I recommend using Closed XML

You write to the file directly and don't need Excel. It will need to be the latest version of an Excel file to work (The open xml standard).

Epplus.dll或npoi.dll还将读取/写入不带excel的excel文件。

将数据保存在XML或JSON文件中,然后当您要可视化它们时,您可以根据这些数据创建excel文件,因此您将拥有一个非常轻便的文件,并且可以根据需要轻松读取和更新。

I haven't done this specifically through wpf, but you can access powershell cmdlets through .net and powershell has commands for retrieving and writing Excel data.

That said, my experience has been it's very tedious and inconsistent with bugs. I would tell your client that using an Excel file as a database is impossible and certainly prone to failure in practice.

For one thing you will run into read/write restrictions if it is used by anything else.

If you don't mind to use comercial libraries, you can try to use Aspose.Cells . It has rich cells API and able to work without Excel interop API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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