For example if a user types a word in the console that matches a specific cell I want it to connect to, can I have info sent back to them from a different cell with WriteLine?
You’re describing a key value look up. It is possible to use Excel for this, but that would not be a good choice for this problem. Using a SQLite file would be best. If you want novice users to edit the file, CSV might be better.
I don’t want anyone to edit it. But I want certain words typed by the user to be recognized as a cell and then another cell will be displayed back to the user as a result.
Could you tell us why you want to use excel files for this task? There are other formats and techniques available that are a lot easier to implement and have better behavior.
If you just want Excel to be able to show your file, you can simply create comma-separated values (CSV) in a file with extension .csv
This. Do CSV to dictionary. Super fast and efficient lookups from the dictionary to return the values.
Yes – this is possible using Microsoft.Office.Interop.Excel.
You can get the excel object, get a particular workbook, and then a particular sheet. Once you have the sheet you can reference cell values and perform logic like you listed above. For example if cell A1 text matches the console input text and you want to return the content of cell A2 and write that to the console line that is all within the scope of the Excel objects available in that namespace.
I would recommend looking into EPPlus. It is also a library for interacting with Excel files but I found it much more intuitive and much faster to code than Office.Interop.Excel.
I’ve used both in an app I wrote for my company and EPPlus is more performant if you’re doing lots of requests. I started with OIE and moved to EPPlus.
OIE is reliant on the user running the program having Excel installed. My work was further complicated by different users having different versions and languages installed, though this might not be relevant to you it won’t hurt to keep in mind.
Thanks!
To avoid the XY problem you should always explain why you are doing something. It sucks to get your answer and then have the wrong solution.
I suspect the excel file in question is input for another process, or is sent to a person the insists on excel files. The thing us excel isn’t always the best tool for the job but excel might be the only tool people have/are abel/willing to use tef the covid track snd trace programs in several countries including the UK
This is like a classic stackoverflow response – convince you that you don’t want to do what you asked. Yeah you can use xls easily, there are multiple libraries on nuget that will do this without difficult interop problems. Check nuget! It will be equally difficult as csv or sqlite.
What part of their post makes you think they want to do that?
C# devs
null reference exceptions