Source Code for Me (s-c.me)

Allows you to paste souce code to blogs! Adapted for Twitter! Here is Search Form in case you missed your code.
Tags: CSharp,Application, Created At: 1/18/2018 8:19:58 AMViews:

HTML view:
Copy Source | Copy HTML
  1. Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
  2. Workbook workbook = app.Workbooks.Open(filename);
  3. Worksheet worksheet = workbook.Sheets[1];
  4. //получаем полный квадрат всех используемых ячеек
  5. Range range = worksheet.UsedRange;
  6. int cCount = range.Columns.Count; //кол-во столбцов
  7. int rCount = range.Rows.Count; //кол-во строк
  8. // заполним модель данными по новым контактам это может быть List<T>
  9. for (int i = 1; i <= rCount; i++)
  10. {
  11.     r1 = worksheet.Cells[i, 4].Text;
  12.     r2 = worksheet.Cells[i, 1].Text + " " + worksheet.Cells[i, 2].Text + " " + worksheet.Cells[i, 3].Text;
  13.     r3 = worksheet.Cells[i, 5].Text;
  14.     r4 = worksheet.Cells[i, 6].Text;
  15. }

Based on Manoli.Net's CodeFormatter. Made by Topbot (c) 2008-2018