private bool SaveFile(List<Object> list, out string url, string templateName)
{
try
{
var designer = new WorkbookDesigner();
var serverpath = new StringBuilder();
serverpath.Append(AppDomain.CurrentDomain.BaseDirectory);
var path = serverpath + templateName;
designer.Workbook = new Workbook(path);
var worksheet = designer.Workbook.Worksheets[0];
designer.SetDataSource("Export", list);
////Process the markers
designer.Process(false);
worksheet.Cells["A2"].PutValue("Ngày: " + list[0].CreatedDay.ToString("dd/MM/yyyy"));
////Save the Excel file.
var namefile = "XuatFile_" + DateTime.Now.ToString("ddMMyyyyhhmmss") + ".xlsx";
url = serverpath + "/Send_Save/" + namefile;
worksheet.Name = "XuatFile_" + DateTime.Now.ToString("ddMMyyyyhhmmss");
designer.Workbook.Save(url, SaveFormat.xlsx);
_log.Info(DateTime.Now.ToString("dd-MM-yyyy HH mm ss " + namefile));
return true;
}
catch (Exception e)
{
url = "";
_log.Info("luu file that bai");
_log.Info("InnerException {0} StackTrace {1} Message {2}", e.InnerException, e.StackTrace,
e.Message);
return false;
throw;
}
}
FILE TEMPLATE EXAMPLE
Wednesday, May 31, 2017
Export Excel with Aspose
Subscribe to:
Post Comments (Atom)
No comments:
Write comments