You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
2.7 KiB

3 years ago
using System;
using System.Collections.Generic;
using System.Text;
using NPOI.HPSF;
using NPOI.HSSF.UserModel;
using NPOI.HSSF.Record;
using System.IO;
using NPOI.SS.Util;
using NPOI.SS.UserModel;
namespace Stone.Common
{
public class MyExcel
{
public HSSFWorkbook hssfworkbook = null;
public string filename = null;
public HSSFSheet sheet = null;
public MyExcel()
{
}
/// <summary>
/// �½�һ��Excel�ļ�
/// </summary>
/// <param name="_filename">Ҫ�½���Excel�ļ�·��</param>
public void NewExcel(string _filename)
{
filename = _filename;
hssfworkbook = new HSSFWorkbook();
}
/// <summary>
/// ����һ��Excel�ļ�
/// </summary>
/// <param name="_filename">Ҫ�򿪵�Excel�ļ�·��</param>
public void OpenExcel(string _filename)
{
filename = _filename;
FileStream file = new FileStream(filename, FileMode.Open, FileAccess.Read);
hssfworkbook = new HSSFWorkbook(file);
}
/// <summary>
/// �½�һ��������
/// </summary>
/// <param name="sheetname"></param>
public void NewSheet(string sheetname)
{
sheet = (HSSFSheet)hssfworkbook.CreateSheet(sheetname);
}
/// <summary>
/// ����һ��������
/// </summary>
/// <param name="sheetname"></param>
public void OpenSheet(string sheetname)
{
sheet = (HSSFSheet)hssfworkbook.GetSheet(sheetname);
}
/// <summary>
/// ����һ��
/// </summary>
/// <param name="rowindex"></param>
public void CreateRow(int rowindex)
{
sheet.CreateRow(rowindex);
}
/// <summary>
/// ����һ��Ԫ��
/// </summary>
/// <param name="rowindex"></param>
/// <param name="colindex"></param>
public void CreateCell(int rowindex, int colindex)
{
sheet.GetRow(rowindex).CreateCell(colindex);
}
/// <summary>
/// ���õ�Ԫ����ֵ
/// </summary>
/// <param name="rowindex"></param>
/// <param name="colindex"></param>
/// <param name="value"></param>
public void SetCellValue(int rowindex, int colindex, string value)
{
sheet.GetRow(rowindex).GetCell(colindex).SetCellValue(value);
}
/// <summary>
/// ����Excel�ļ�
/// </summary>
public void Save()
{
FileStream file = new FileStream(filename, FileMode.Create);
hssfworkbook.Write(file);
file.Close();
}
}
}