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.
 
 
 
 
 

64 lines
1.6 KiB

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NPOI.HSSF.UserModel;
namespace CK.SCP.Common
{
public class MyExcel
{
public HSSFWorkbook hssfworkbook = null;
public string filename = null;
public HSSFSheet sheet = null;
public void NewExcel(string _filename)
{
this.filename = _filename;
this.hssfworkbook = new HSSFWorkbook();
}
public void OpenExcel(string _filename)
{
this.filename = _filename;
FileStream file = new FileStream(this.filename, FileMode.Open, FileAccess.Read);
this.hssfworkbook = new HSSFWorkbook(file);
}
public void NewSheet(string sheetname)
{
this.sheet = (HSSFSheet)this.hssfworkbook.CreateSheet(sheetname);
}
public void OpenSheet(string sheetname)
{
this.sheet = (HSSFSheet)this.hssfworkbook.GetSheet(sheetname);
}
public void CreateRow(int rowindex)
{
this.sheet.CreateRow(rowindex);
}
public void CreateCell(int rowindex, int colindex)
{
this.sheet.GetRow(rowindex).CreateCell(colindex);
}
public void SetCellValue(int rowindex, int colindex, string value)
{
this.sheet.GetRow(rowindex).GetCell(colindex).SetCellValue(value);
}
public void Save()
{
FileStream file = new FileStream(this.filename, FileMode.Create);
this.hssfworkbook.Write(file);
file.Close();
}
}
}