Aliendreamer

excel shit

Jun 23rd, 2018
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System;
  2. using Microsoft.Office.Interop;
  3. using Excel = Microsoft.Office.Interop.Excel;
  4.  
  5. class Program
  6.     {
  7.         static void Main()
  8.         {
  9.            
  10.             Excel.Application app = new Excel.Application();
  11.             Excel.Workbook workbook = app.Workbooks.Open(@"E:\c#\c#OOPBasic\OOPbasicsExams\ConsoleApp1\kcmdata.xlsx");
  12.             Excel.Worksheet sheet = (Excel.Worksheet)workbook.Sheets["Лист1"];
  13.             Excel.Range range = sheet.UsedRange;
  14.             int columnsCount = range.Columns.Count;
  15.             int rowsCount = range.Rows.Count;
  16.             for (int i = 1; i <= rowsCount; i++)
  17.             {
  18.                 for (int j = 1; j <= columnsCount; j++)
  19.                 {
  20.                     if (range.Cells[i, j] == null || ((Excel.Range)range.Cells[i, j]).Value2 == null)
  21.                     {
  22.                         goto Break;
  23.                     }
  24.                     Console.Write(((((Excel.Range)range.Cells[i, j]).Value2.ToString()) + "|"));
  25.                 }
  26.                 Console.WriteLine();
  27.             }
  28.             Break:
  29.             workbook.Close();
  30.             app.Quit();
  31.         }
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment