Kirish Asosoiy qisim


Download 0.76 Mb.
bet3/14
Sana28.12.2022
Hajmi0.76 Mb.
#1014407
1   2   3   4   5   6   7   8   9   ...   14
Bog'liq
8888 (Автосохраненный)

Excel.Worbook - Excel ilovasidagi bitta ish kitobini ifodalaydi
Excel.Worksheet - Ishchi kitob ob'ektidagi Ishchi varaqlar to'plamining a'zosi
Keling, ushbu o'zgaruvchilarni keyingi foydalanish uchun e'lon qilaylik.
C#
Private static Excel.Workbook MyBook = null;
Private static Excel.Application MyApp = null;
Private static Excel.Worksheet MySheet = null;
Excel dasturini ishga tushiring
C#
MyApp = new Excel.Application();
MyApp.Visible = false;
MyBook =
MyApp.Workbooks.Open(DB_PATH);
MySheet =
(Excel.Worksheet)MyBook.Sheets[1];
// Explicit cast is not required here
lastRow =
MySheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row;

Esda tutingki, Workbooks.open(string) usuli bu usulga parametr sifatida fayl yoʻlini oʻtkazish orqali Excel ish kitobini ochish uchun ishlatiladi. Odatiy bo'lib, yaratilgan har bir ish kitobida uchta ish varag'i mavjud. Ushbu misolda biz


MyBook.Sheets[1]
yordamida birinchi ishchi varaqni ochdik.
Excelda oxirgi ishlatilgan qatorni xlCellTypeLastCell parametri bilan SpecialCells usuli yordamida hisoblash mumkin.
Excel dan o'qish
Quyidagi kod qismi Excel varaqlari hujayralarini o'qish va har bir qatorni Employee ob'ektida saqlashni ko'rsatadi.
C#
BindingList EmpList =
new BindingList();
for (int indeks = 2; indeks <= lastRow; indeks++)
{ System.Array MyValues ​​= (System.Array)MySheet.get_Range("A" +
index.ToString(), "D" + index.ToString()).Cells.Value;
EmpList.Add (nev Employee
{
Name=
MyValues.GetValue(1,1).ToString(),
Employee_ID =
MyValues.GetValue(1,2).ToString(),

Download 0.76 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   ...   14




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling