Okay so after many hours I finally figured out how to read data from an excel file but now I am running into a problem here is how I read in data

Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();

Workbook excelFile = excelApp.Workbooks.Open(filePath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

    object [,] values = gatherInfo(excelFile, type);
    excelFile.Close(false, Type.Missing, Type.Missing);

    public static object [,] gatherInfo (Workbook excelFile, int type) 
     {
      Worksheet excelSheet = (Worksheet) excelFile.Worksheets [1];

      string startPoint = "";

      if (type == 1)
       {
        startPoint = "A2";
       }
      else if (type == 2)
       {
        startPoint = "F1"; 
       }


      Range range = excelSheet.get_Range(startPoint, Missing.Value); )
      range = range.get_End(XlDirection.xlToRight);
      range = range.get_End(XlDirection.xlDown);
   

      string downAddress = range.get_Address(false, false, XlReferenceStyle.xlA1, Type.Missing, Type.Missing); 
      range = excelSheet.get_Range(startPoint, downAddress);

      object[,] values = (object[,])range.Value2;

      return (values);
     }

Well the problem I am having is that it has to deal with the type value. See I want to real one row for type 2 because these are shiftTypes, but with this code it forces me to read a minimum of 2 row (and columns) or else it throws an error. I know the culpret is these lines

range = range.get_End(XlDirection.xlToRight);
      range = range.get_End(XlDirection.xlDown);

Like I said I want to read just 1 row but can't (when I choose type 2). Any help?

Sorry for the mess hope you can understand my mess. Thanks in advance.

Edited 6 Years Ago by JOSheaIV: n/a

This question has already been answered. Start a new discussion instead.