Advertisement
Just_Support

Excel.cs

Jan 30th, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.Office.Interop.Excel;
  7. using _Excel = Microsoft.Office.Interop.Excel;
  8.  
  9.  
  10. namespace Fakturace
  11. {
  12.     class Excel
  13.     {
  14.         string path ="";
  15.         _Application excel = new _Excel.Application();
  16.         Workbook wb;
  17.         Worksheet ws;
  18.        
  19.         public Excel(string path, int Sheet)
  20.             {
  21.             this.path = path;
  22.             wb = excel.Workbooks.Open(path);
  23.             ws = wb.Worksheets[Sheet];
  24.             }
  25.  
  26.      public string ReadCell (int i, int j)
  27.           {
  28.         i++;
  29.         j++;
  30.         if (ws.Cells[i, j].Value2 != null)
  31.             return ws.Cells[i, j].Value2;
  32.         else
  33.             return "";
  34.           }
  35.  
  36.         public void WriteToCell(int i, int j, string s)
  37.         {
  38.             i++;
  39.             j++;
  40.             ws.Cells[i, j].Value2 = s;
  41.         }
  42.  
  43.         public void Save()
  44.         {
  45.             wb.Save();
  46.         }
  47.  
  48.         public void SaveAs(string path)
  49.         {
  50.             wb.SaveAs(path);
  51.         }
  52.  
  53.         public void Close()
  54.         {
  55.             wb.Close();
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement