0

This is for self education really. But, is there an easier way to read from an excel sheet, without using the COM/INTEROP DLLs? Any other way Microsoft makes it easier to read values from an excel sheet cell by cell(And word by word in Word)?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Aniket Inge
  • 25,375
  • 5
  • 50
  • 78
  • 1
    You could use Oledbconnection to read line by line witha DataReader object. – Derek Dec 11 '12 at 14:41
  • 1
    Same sort of question with some suggested answer http://stackoverflow.com/questions/7711851/create-excel-without-interop-and-template-with-or-without-row-and-columnspan – Kamran Shahid Dec 11 '12 at 14:49

5 Answers5

2

I know the question asks if there are alternatives to the Excel and Word interop API - but as I read it, this is asked because the OP wants a more simple way to, e.g., read the cells from an Excel sheet or read the words in a Word document.

I just want to add that for Word, reading each word in a document can be done with very few lines:

foreach (var word in myDocument.Words)
{
    Console.WriteLine(word);
}

... I don't believe this can be done more simple, so I was wondering if it really is alternative API's the OP wants or maybe a couple of Word interop samples instead? (at least in case of using the Word interop API)

Lasse Christiansen
  • 10,205
  • 7
  • 50
  • 79
1

If you are about new format (xlmx, docx) i think you can use OpenXML.

Hamlet Hakobyan
  • 32,965
  • 6
  • 52
  • 68
1

For Word & Excel a good 3rd party library is Aspose http://www.aspose.com/.net/total-component.aspx Aspose provides a very easy to use API with a plethora of options to manipulate word and excel documents. The documentation is also good. That said the licensing fees might be prohibitive.

If you want open-source alternatives for Word there is DocX http://docx.codeplex.com/ DocX provides a nice API over OpenXML.

We have made some major extensions to DocX in an unofficial branch that you may find useful: https://github.com/organizations/Word-DocX

The list of extensions include support for single and multilevel lists, support for reading font-formatting, section/section-breaks etc.

fjxx
  • 945
  • 10
  • 20
1

If you want to use ODBC and read for a WorkSheet for example follow this simple example this is just one of many different ways to read from Excel

    OleDbCommand myCommand = new OleDbCommand("Select * from [Sheet1$];");
    OleDbConnection myConnection = new OleDbConnection(connectionString);
    myConnection.Open();
    myCommand.Connection = myConnection;
    OleDbDataReader myReader = myCommand.ExecuteReader();

    while (myReader.Read())
    {
    // it can read upto 5 columns means A to E. In your case if the requirement is different then change the loop limits a/c to it.
      //Change the Response.Write blow to Console.WriteLine() if you are wanting to test this in a Console application vs a web app.
      for (int i = 0; i < 5; i++)
      {
        Response.Write(myReaderIdea.ToString() + " ");
      }
      Response.Write("<br>");
    }
    myConnection.Close();

    //make sure to Dispose of the Reader object as well 
   ((IDisposable)myReaderIdea).Dispose();
MethodMan
  • 18,625
  • 6
  • 34
  • 52
0

There is an excel driver for ODBC data sources. It is accessible via the control panel. If you configure there, or use a connection string with the excel driver you could access it via the ADO APIs.

RayB64
  • 149
  • 1
  • 4