using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using NPOI.SS.Util;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System.Drawing;
namespace Stone.WinModule.Standard
{
public class MyExcelX
{
public XSSFWorkbook hssfworkbook = null;
public string filename = null;
public XSSFSheet sheet = null;
public MyExcelX()
{
}
///
/// 新建一个Excel文件
///
/// 要新建的Excel文件路径
public void NewExcel(string _filename)
{
filename = _filename;
hssfworkbook = new XSSFWorkbook();
}
///
/// 打开一个Excel文件
///
/// 要打开的Excel文件路径
public void OpenExcel(string _filename)
{
filename = _filename;
FileStream file = new FileStream(filename, FileMode.Open, FileAccess.Read);
hssfworkbook = new XSSFWorkbook(file);
}
///
/// 新建一个工作表
///
///
public void NewSheet(string sheetname)
{
sheet = (XSSFSheet)hssfworkbook.CreateSheet(sheetname);
}
///
/// 打开一个工作表
///
///
public void OpenSheet(string sheetname)
{
sheet = (XSSFSheet)hssfworkbook.GetSheet(sheetname);
}
///
/// 创建一行
///
///
public void CreateRow(int rowindex)
{
sheet.CreateRow(rowindex);
}
///
/// 创建一行
///
///
public void CreateRow(int rowindex, short rowheight)
{
sheet.CreateRow(rowindex);
sheet.GetRow(rowindex).Height = rowheight;
}
///
/// 创建一单元格
///
///
///
public void CreateCell(int rowindex, int colindex)
{
sheet.GetRow(rowindex).CreateCell(colindex);
}
///
/// 设置单元格的值
///
///
///
///
public void SetCellValue(int rowindex, int colindex, string value)
{
sheet.GetRow(rowindex).GetCell(colindex).SetCellValue(value);
}
public void SetCellValue(int rowindex, int colindex, double value)
{
sheet.GetRow(rowindex).GetCell(colindex).SetCellValue(value);
}
public ICell GetCellValue(int rowindex, int colindex)
{
return sheet.GetRow(rowindex).GetCell(colindex);
}
///
/// 保存Excel文件
///
public void Save()
{
FileStream file = new FileStream(filename, FileMode.Create);
hssfworkbook.Write(file);
file.Close();
}
}
}