using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
namespace Чтение_и_запись_в_xls_без_Excelа__с_помощью_NPOI_
{
public partial class Form1 : Form
{
FileStream xlsFile;
HSSFWorkbook hssfwb;
ISheet sheet1;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
using (xlsFile = new FileStream("Книга1.xls", FileMode.Open, FileAccess.Read))
{
hssfwb = new HSSFWorkbook(xlsFile);
}
sheet1 = hssfwb.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 (xlsFile = new FileStream("Книга1.xls", FileMode.Open, FileAccess.Write))
{
hssfwb.Write(xlsFile);
}
}
}
}