根据模板往Excel里写入数据
先写一个大的方法,返回所需路径
public string WriteToExecl()
{
//设置excel的名字
string toFileName = DateTime.Now.ToFileTime().ToString();
string sExportFilePath = PMTConstant.TEMPFOLDER + "/" + toFileName + ".xlsx";
//目标文件
string sFilePath = SysConfig.GetFileServerUpload(sExportFilePath);
//模板文件
string sPath = SysConfig.GetFileServerTemplate("Template.xlsx");
//往模板里写数据
WriteTemplate(sFilePath, sPath);
return sExportFilePath;
}
根据模板文件向目标文件里写入
private string WriteTemplate(string sFilePath, string sTemplatePath)
{
if (sTemplatePath != null)
{
workbook = ReadExecl(sTemplatePath);
if (workbook != null)
{
sheet = workbook.GetSheetAt(0);
//往sheet写入数据
WriteTemplateData();
MemoryStream stream = new MemoryStream();
workbook.Write(stream);