using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using NPOI.SS.Util;
string tpath = “d:\\123.xlsx”;
FileStream fs = new FileStream(tpath, FileMode.Open, FileAccess.Read);
if (tpath.IndexOf(".xlsx") > 0) // 2007版本
workbook = new XSSFWorkbook(fs);
else if (tpath.IndexOf(".xls") > 0) // 2003版本
workbook = new HSSFWorkbook(fs);
sheet = workbook.GetSheet(sheetName);
IRow row = sheet.GetRow(0);
//獲取單元格的公式值
String temp;
if (row.GetCell(0).CellType == CellType.Formula)
temp = row.GetCell(0).NumericCellValue.ToString();
else
temp = row.GetCell(0).ToString();
//設置單元格格式為0.00,
IDataFormat dataformat = workbook.CreateDataFormat();
ICellStyle style0 = workbook.CreateCellStyle();
style0.DataFormat = dataformat.GetFormat("0.00");
row.CreateCell(0).CellStyle = style0;
row.GetCell(0).SetCellValue(1);