private static void ReadLine(Excel.Worksheet sheet, Vector <double> values, XlPosition position, int rowShift, int columnShift)
 {
     for (int i = 0; i < values.Count; i++)
     {
         values[i] = GetDouble(sheet, new XlPosition(position.Row + i * rowShift, position.Column + i * columnShift));
     }
 }
 private static void SetValue(Excel.Worksheet sheet, string value, XlPosition position)
 {
     sheet.Cells[
         position.Row,
         position.Column]
         = value;
 }
        /*
         * This code consist of methods that read data
         * from cell, column, row or table
         * from excel sheet in specified position
         */

        private static void ReadRow(Excel.Worksheet sheet, string[] values, XlPosition position)
        {
            for (int i = 0; i < values.Length; i++)
            {
                values[i] = GetString(sheet, new XlPosition(position.Row, position.Column + i));
            }
        }
 private static void SetLineValues(Excel.Worksheet sheet, string[] values, XlPosition position, int rowShift, int columnShift)
 {
     for (int i = 0; i < values.Length; i++)
     {
         sheet.Cells[
             position.Row + i * rowShift,
             position.Column + i * columnShift]
             = values[i];
     }
 }
 private static void ReadTable(Excel.Worksheet sheet, Matrix <double> matrix, XlPosition position)
 {
     for (int i = 0; i < matrix.RowCount; i++)
     {
         for (int j = 0; j < matrix.ColumnCount; j++)
         {
             matrix[i, j] = GetDouble(sheet, new XlPosition(position.Row + i, position.Column + j));
         }
     }
 }
 private static void SetColumnValues(Excel.Worksheet sheet, Vector <double> values, XlPosition position)
 {
     SetLineValues(sheet, values, position, 1, 0);
 }
 private static void SetTableValues(Excel.Worksheet sheet, Matrix <double> dataXVals, XlPosition dataXValsSp)
 {
     for (int i = 0; i < dataXVals.ColumnCount; i++)
     {
         SetColumnValues(sheet, dataXVals.Column(i), new XlPosition(dataXValsSp.Row, dataXValsSp.Column + i));
     }
 }
 private static void SetValue(Excel.Worksheet sheet, double value, XlPosition position)
 {
     SetValue(sheet, value.ToString("N7"), position);
 }
 private static void SetRowValues(Excel.Worksheet sheet, string[] values, XlPosition position)
 {
     SetLineValues(sheet, values, position, 0, 1);
 }
 /*
  * Pre-condition:
  *      Gets sheets and position on it
  *
  * Post-condition:
  *      Returns value of cell in specified in sheet
  */
 private static string GetString(Excel.Worksheet sheet, XlPosition position)
 {
     return(sheet.Cells[position.Row, position.Column].Value2.ToString());
 }
 private static int GetInt(Excel.Worksheet sheet, XlPosition position)
 {
     return(Convert.ToInt32(GetString(sheet, position)));
 }
 private static double GetDouble(Excel.Worksheet sheet, XlPosition position)
 {
     return(Convert.ToDouble(GetString(sheet, position)));
 }
 private static void ReadRow(Excel.Worksheet sheet, Vector <double> values, XlPosition position)
 {
     ReadLine(sheet, values, position, 0, 1);
 }
 private static void ReadColumn(Excel.Worksheet sheet, Vector <double> values, XlPosition position)
 {
     ReadLine(sheet, values, position, 1, 0);
 }
 private static void SetRowValues(Excel.Worksheet sheet, Vector <double> values, XlPosition position)
 {
     SetLineValues(sheet, values, position, 0, 1);
 }
        private static void SetLineValues(Excel.Worksheet sheet, Vector <double> values, XlPosition position, int rowShift, int columnShift)
        {
            bool failed;

            for (int i = 0; i < values.Count; i++)
            {
                failed = false;
                do
                {
                    try
                    {
                        sheet.Cells[
                            position.Row + i * rowShift,
                            position.Column + i * columnShift]
                            = values[i].ToString("N7");

                        failed = false;
                    }
                    catch (System.Runtime.InteropServices.COMException)
                    {
                        failed = true;
                        Thread.Sleep(10);
                    }
                } while (failed);
            }
        }
        /*
         * This code consist of methods that write (set) data
         * to cell, column, row or table
         * in excel sheet in specified position
         */

        private static void SetColumnValues(Excel.Worksheet sheet, string[] values, XlPosition position)
        {
            SetLineValues(sheet, values, position, 1, 0);
        }