using Aspose.Cells;
using Aspose.Cells.Tables;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
namespace gAMS_Sacombank.Web.ExportReport.CodeExport
{
///
/// Dùng để xuất template excel(thường dùng cho xuất báo cáo)
/// htangiau12th01@gmail.com
///
public class ExcelTemplateExportBase
{
#region "Properties"
public Dictionary SmartmarkersObjData{get;set;}
///
/// Lưu trữ thông tin đường dẫn teplate
///
///
/// The template path.
///
public String TemplatePath { get; set; }
public String ErrorMessage { get; set; }
#endregion
#region Method
///
/// Xuất báo cáo theo Smartmarkers
///
///
public MemoryStream ExprortSmartmarkers()
{
MemoryStream dstStream = new MemoryStream();
WorkbookDesigner designer = new WorkbookDesigner()
{
Workbook = new Workbook(this.TemplatePath)
};
#region [Smart markers]
foreach (var smark in this.SmartmarkersObjData)
{
designer.SetDataSource(smark.Key, smark.Value);
}
designer.Process();
#endregion [Smart markers]
designer.Workbook.CalculateFormula();
designer.Workbook.Save(dstStream, SaveFormat.Xlsx);
return dstStream;
}
public MemoryStream ExprortSmartmarkersPDF()
{
MemoryStream dstStream = new MemoryStream();
WorkbookDesigner designer = new WorkbookDesigner()
{
Workbook = new Workbook(this.TemplatePath)
};
#region [Smart markers]
foreach (var smark in this.SmartmarkersObjData)
{
designer.SetDataSource(smark.Key, smark.Value);
}
designer.Process();
#endregion [Smart markers]
designer.Workbook.CalculateFormula();
// Wraptext
for (int i = 0; i < designer.Workbook.Worksheets.Count; i++)
{
designer.Workbook.Worksheets[i].AutoFitRows();
}
designer.Workbook.Save(dstStream, SaveFormat.Pdf);
return dstStream;
}
#endregion
}
}