Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using Microsoft.Office.Interop;
- using Excel = Microsoft.Office.Interop.Excel;
- class Program
- {
- static void Main()
- {
- Excel.Application app = new Excel.Application();
- Excel.Workbook workbook = app.Workbooks.Open(@"E:\c#\c#OOPBasic\OOPbasicsExams\ConsoleApp1\kcmdata.xlsx");
- Excel.Worksheet sheet = (Excel.Worksheet)workbook.Sheets["Лист1"];
- Excel.Range range = sheet.UsedRange;
- int columnsCount = range.Columns.Count;
- int rowsCount = range.Rows.Count;
- for (int i = 1; i <= rowsCount; i++)
- {
- for (int j = 1; j <= columnsCount; j++)
- {
- if (range.Cells[i, j] == null || ((Excel.Range)range.Cells[i, j]).Value2 == null)
- {
- goto Break;
- }
- Console.Write(((((Excel.Range)range.Cells[i, j]).Value2.ToString()) + "|"));
- }
- Console.WriteLine();
- }
- Break:
- workbook.Close();
- app.Quit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment