这是一种npoi的 看见这个的时候发现不错,就留了下来
FileStream file = new FileStream(Server.MapPath("template/") + "a.xls", FileMode.Open, FileAccess.Read);
HSSFWorkbook hssfworkbook = new HSSFWorkbook(file);
file.Close();
ISheet sheet1 = hssfworkbook.GetSheet("Sheet1");
if (sheet1.GetRow(23) == null)
{
sheet1.CreateRow(23);
}
if (sheet1.GetRow(23).GetCell(6) == null)
{
sheet1.GetRow(23).CreateCell(6);
}
sheet1.GetRow(23).GetCell(6).SetCellValue(300);
sheet1.ForceFormulaRecalculation = true;
FileStream file2 = new FileStream(Server.MapPath("template/") + "ccc.xls", FileMode.Create, FileAccess.Write);
hssfworkbook.Write(file2);
file2.Close();
下面这一种是本人自己写的一个epplus关于模板的,不说废话直接上代码
string str = Application.StartupPath + "\readiness form_0427.xlsx";
FileStream fs = new FileStream(str, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
ExcelPackage ep = new ExcelPackage(fs);
ExcelWorksheet sheet = ep.Workbook.Worksheets[1];
sheet.Cells[1, 11].Value = "纬度";
sheet.Cells[10, 11].Value = "纬度";
fs.Close();
string sr=AppDomain.CurrentDomain.BaseDirectory + @"output
eadiness";
if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + @"output"))
{
Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + @"output");
}
fs = new FileStream(str, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
ep.SaveAs(fs);//存档
fs.Close();
ep.Dispose();
ep = null;