-1

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?

Mafii
  • 7,227
  • 1
  • 35
  • 55
Kyle Dama
  • 49
  • 5
  • 2
    Define "best". Fastest? Cheapest? Easiest to code? Have you done any research already? What methods have you found, and what reasons do you have for not using one of them? – D Stanley Mar 24 '16 at 14:18
  • 2
    Excel isn't a _database_ – Mafii Mar 24 '16 at 14:20
  • I have yet to find any good methods, just looking for one that is efficient, but not overly difficult. – Kyle Dama Mar 24 '16 at 14:24
  • 1
    @KyleD maybe this answer will help you http://stackoverflow.com/questions/7244971/how-do-i-import-from-excel-to-a-dataset-using-microsoft-office-interop-excel – alexlz Mar 24 '16 at 14:26
  • 1
    Easiest might be to save it as .csv file and read that. – Nyerguds Mar 24 '16 at 15:12

2 Answers2

1

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(....)

Jacek Cz
  • 1,872
  • 1
  • 15
  • 22
1

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();
}
synapse
  • 130
  • 4