using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
namespace Чтение_и_запись_в_xlsx_без_Excela__1_
{
public partial class Form1 : Form
{
FileStream xlsxFile;
XSSFWorkbook xssfwb;
ISheet sheet1;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
using (xlsxFile = new FileStream("Книга1.xlsx", FileMode.Open, FileAccess.Read))
{
xssfwb = new XSSFWorkbook(xlsxFile);
}
sheet1 = xssfwb.GetSheet("Лист1");
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(sheet1.GetRow(int.Parse(textBox1.Text)).GetCell(int.Parse(textBox2.Text)).StringCellValue);
}
private void button2_Click(object sender, EventArgs e)
{
sheet1.GetRow(int.Parse(textBox1.Text)).GetCell(int.Parse(textBox2.Text)).SetCellValue("Ура!");
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
using (xlsxFile = new FileStream("Книга1.xlsx", FileMode.Open, FileAccess.Write))
{
xssfwb.Write(xlsxFile);
}
}
}
}