Click here to Skip to main content
15,563,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to remove any word from excel file in c?

What I have tried:

I know how to delete that file but unfortunately didn't know how to delete any specific word or character from a file.
Posted
Updated 20-Apr-22 9:58am
Comments
jeron1 20-Apr-22 12:20pm    
Read the contents of the file into memory, remove the word (or character) from memory, then write the modified memory to the file.
Dave Kreskowiak 20-Apr-22 12:39pm    
That's not an "Excel" file. What you're dealing with is a CSV (Comma Separated Values) file, which is just a text file.
xguybluehat 20-Apr-22 13:25pm    
I mean , i'm using the format .xlsx, that's an excel file extension.
Dave Kreskowiak 20-Apr-22 14:11pm    
The extension doesn't change the content of the file in any way.

A .csv file is just a text file with comma separated values. Any application that can read CSV or text files can open these.

A .xlsx file is an Excel file format, which is really a bunch of .xml files compressed into a .zip file and given the .xlsx extension. Opening these is anything other than Excel, or some other application that specifies it can read these, results in a bunch of garbage being displayed.

The reason a .csv file opens in Excel when you double-click it is because Excel is registered as the default application that opens any filename with a .csv extension. You don't have to use Excel to open the file. You can just drag and drop the file on Notepad and it'll open it since .csv is just a formatted text file.
xguybluehat 20-Apr-22 15:13pm    
hm , thanks for this explanation , i see some loopholes in my knowledge.

It'll depend on the actual excel version - there are two file types: .XLS and .XLSX.

The former is a binary format which is proprietary to Microsoft and will not be at all easy to process in C.

The latter is a Zipped set of XML files and is a lot simpler to process - but even then you're going to need to put a lot of effort in. Starting by finding a C library that can read ZIP files - but even then you're probably going to have to check carefully as there are different version of ZIP files as well, and early libraries may not be able to open XLSX zips.
Inside the zip will be OpenXML files so you'll either have to find a library that can read and write them - good luck with that for C - or write your own XML processor. But once you have that the job itself is relatively trivial.

Would I do it? No chance. I'd use a modern language, with a modern framework which gives support for reading an writing Excel files directly ... C is just too old a language to make it anything but a nasty job!
 
Share this answer
 
Comments
xguybluehat 20-Apr-22 15:25pm    
Thanks for your advice man! , but i'm currently working on a project that analyze company's stocks for u, so I've to complete it anyhow within this month. No chance to learn any other lang. like python rn.

Btw , I learnt c cuz I just wanted to understand the low level working of hardware , so that cs make more sense for me.
OriginalGriff 21-Apr-22 4:51am    
C is great for low level hardware interaction (though Assembler is better) but for less hardware oriented stuff it's a PITA these days. Remember, C was invented in 1972 - fifty years ago - and it was designed for the tiny memory and processor systems we had then. Modern memory, CPU, and OS are much, much more powerful, and you need a more advanced framework to interact with them properly. C# is a good choice for that, C isn't!
KarstenK 21-Apr-22 4:13am    
C isnt the best tool for that job, but works fine with hardware. I recommend c# for such tasks.
I do not know of any way to do it from C. Excel files are in a proprietary format, they are not simple text files. If you use one of the .NET languages then you can access its content via the Microsoft.Office.Interop.Excel Namespace | Microsoft Docs[^].
 
Share this answer
 
Comments
KarstenK 21-Apr-22 4:16am    
I know a way, but I wont go it. ;-)
COM interop like: https://www.codeproject.com/Articles/13601/COM-in-plain-C
Richard MacCutchan 21-Apr-22 4:28am    
Yes, I read that article a few years ago. But it will not be of any use to someone who is just learning.
The right language for working with MS Excel is C#. It is a hugh field and so you better start with How to access Office interop objects (C# Programming Guide) if you are serious about it.

Looks like there is some example code.

PS: C is a low level language to control hardware, but not for COM interop with Excel. Someday you may understand the truth of my words.
 
Share this answer
 
Comments
xguybluehat 20-Apr-22 15:12pm    
i can't learn c# rn , cuz i'm working on a project that i've to finish this month anyhow.
KarstenK 21-Apr-22 4:18am    
Try your luck with: https://www.codeproject.com/Articles/13601/COM-in-plain-C

but I would dive into the easier C# language. Discuss my advice with somebody who has the skills and you trust. Good luck.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900