Import Data From Excel to C# [closed] - c#

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I'm looking for the best method to import co-ordinates from excel into a C# program. The goal is to retrieve data from the X Pos Column and Y Pos Column and compare them to X position and Y position of the user clicks. What is the best way to get the data from the excel database?

One of the simplest is to use clipboard.
Probably Ctr-C from Excel give few formats of windows clipboard (more or less powerful)
Simple way is to use basic (main, natural) clipboard format, cells are delimited with tabulator \t and lines with \n
Such multiline strong You can split or parse in other way, up to You.
Read MSDN about System.Windows.Forms.Clipboard.GetText(....)

If the goal is to import data from an XLS(X) document, you can use http://spreadsheetlight.com/
(It does not require Office installed on the workstation)
You can open the document, select a sheet and read data row by row for instance.
You should store the coordinates in a proper data structure and compare them with the cursor coordinates when mouse events are triggered.
Quick sample to get cell value ;
using(SLDocument document = new SLDocument("TheFile.xlsx", "TheSheet"))
{
string cellContent = document .GetCellValueAsString("A1");
document.CloseWithoutSaving();
}

Related

C# - What is the best way to export the content of a list in an external file? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I'm developing a program to manage my coin collection. I'd like to export my list of coins in an external file in order to save what I've stored inside the list. As the title says, I'd like to know what is the best way to do that. Should I export the content in a text file, in a Excel file or in a XML file?
I don't know if it is useful to know this, but I'm using LINQ to manage the queries.
At the moment, everything is working as intended. The only thing that I need to finish the project is to save all the data inside the list. I'm not asking for some code to paste, I just want some opinions.
Thanks in advance for the help.
Wow, so many options!
I think these days I prefer JSON. It is lightweight simple, human readable and portable.
With a library such as Newtonsoft then it is also easy. I know you didn't ask for a code example, but below shows how easy it is.
string output = JsonConvert.SerializeObject(myObject, Newtonsoft.Json.Formatting.Indented);
File.WriteAllText("c:\path\outputfile.json", output);
And to read it in again
string json = File.ReadAllText("c:\path\inputfile.json");
MyObject myObject = JsonConvert.DeserializeObject<MyObject >(json);
And if you did want XML, you can use the sample library to then convert your obejct to XML for output
System.Xml.XmlDocument doc = JsonConvert.DeserializeXmlNode(json, "RootElementName");
doc.Save("c:\path\outputfile.xml");

How can I extract written number in a answer sheet(image) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I tried tesseract but it only works on pure text document, can anyone suggest me what to do?
Here is my code for vb.net
Dim pic = New Bitmap(OpenFileDialog1.FileName)
Dim ocr = New TesseractEngine("./dataset", "eng", EngineMode.TesseractAndCube)
Dim page = ocr.Process(pic)
TextBox1.Text = page.GetText
It looks like your answer sheet is well structured. I would focus on extracting a sub-image for each answer, and then running Tesseract in single character mode on that image.
I'm not sure how you get single character mode in whatever Tesseract wrapper you're using, but via command line it's the parameter: --psm 10.
To extract each image, I would use OpenCV (try Emgu for .NET). You may need to first apply a perspective wrap in order to get the image square. You can then use a simple sliding window to get each sub image.
I'm not sure how this will perform in cases where an answer has been crossed out.

Optimized parse text file, to then upload to Excel [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
My project is to take large amounts of logs, output inside text files and parse some of the data to be made into Excel format.
There is a lot of garbage data in between not needed
This is how one portion of it is like:
2018-05-17 07:16:57.105>>>>>>
{"status":"success", "statusCode":"0", "statusDesc":"Message Processed Sucessfully", "messageNumber":"451", "payload":{"messageCode":"SORTRESPONSE","Id":"5L","Id":"28032","messageTimestamp":"2018-05-16 23:16:55"}}
I will first need to take the time stamp befor the "{}"
as it differs from the messageTimestamp
When generating the excel workbook
This is how it will look like in Excel:
------A-----------------------------------B--------------C
1. Overall time stamp ---------- status------- statusCode
2. 2018-05-17 07:16:57.105 - success --- -0
And so on...
payload has its own section of logs within its "{}"
so its section in excel will look like this:
F
1. payload
2. {"messageCode":"SORTRESPONSE","Id":"5L","Id":"28032","messageTimestamp":"2018-05-16 23:16:55"}
its content can be in one section that's not an issue.
A friend of mine have done something similar but it can take a few minutes to even generate even one relatively small excel document
My Question:
What is the most optimal way can I parse the data needed to then store it in an array or multidimensional array
to then push it into an excel document.
I would try to split the input text on newline characters, then parse the JSON part with Newtonsoft.Json.
I would highly advise to not try to parse the JSON yourself. The bottleneck here will be disk IO not in-memory processing, so make it easy to write correct code and use 3rd party libraries.
Once you have structured data representing the input, you can write each entry to an output file with only the fields you need.
For an Excel file, is CSV okay or do you need XLSX files? For CSV you can just write to a file directly, for XLSX I would recommend the EPPlus library.
https://www.newtonsoft.com/json
https://archive.codeplex.com/?p=epplus

Generate sequential number based on selected sequence [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a website dropdown that is populated from a SQL query. The values in the dropdown are from a table column and are like:
ABC-0123
ABC-0124
ABC-0125
ABC-0126.01
ABC-0126.02
ABC-0127
DEF-0123
DEF-0124
DEF-0125.1.01
DEF-0125.1.02
DEF-0125.2
I have a button to generate a new number based on what is selected in the dropdown. For example, if ABC-0125 is selected, ABC-0128 would need to be created since it's the next number in sequence. If ABC-0126.01 is selected, ABC-0126.03 would need to be created.
I'm looking for ideas on how to perform this. I considered just using the dropdown or querying the database directly.
I've split the selected value as a start:
String strDocFamily = drpDocFamily.SelectedValue;
string[] strDocTiers = strDocFamily.Split('.');
This may be open ended, but I'm looking for some suggestions on how to proceed. Thank you.
A solution might be to split the storage of the data into two or more columns, one for the alphabetic part ('ABC') another for the 'family' (0128 - the first set of digits) and others for the other tiers. You could then directly look up the maximum value of the 'family' column based on alphabetic. For example:
SELECT MAX(family-number)
FROM table-name
WHERE alpha-part='ABC';
Here is a UniqueID generator that can be easily adapted to generate a similar sequence to the one you need.
https://stackoverflow.com/a/39312025/2495728

How I can read after EOF? C# [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I`m using C# and I need to read something after EOF. Is it possible by using C#? How?
Thanks.
You cant. EOF means end of file, there's nothing actually in the file after that.
You may as well ask how you can get ten gallons of oil from a four-gallon drum. Once it's empty, there's no more to be had.
Since you're talking C# hence Windows (and based on your comment and data located behind the end of file pointer), it's possible that they may be referring to "DOS mode" text files, which are (or used to be, I haven't investigated recently) terminated by the CTRL-Z character.
From the earliest days of the PC revolution, where CP/M used integral numbers of disk blocks to store a file and only stored the number of disk blocks rather than the number of bytes, CTRL-Z was used to indicate end of file if the file wasn't an exact multiple of the disk block size.
If that's the case, it's probably best just to open the file as a binary file, then read up to the first CTRL-Z character (code point 26) - everything beyond that could be considered data beyond EOF if it's truly a text file of that format.

Categories