1
|
using Aspose.Cells;
|
2
|
using Aspose.Cells.Tables;
|
3
|
using System;
|
4
|
using System.Collections.Generic;
|
5
|
using System.Data;
|
6
|
using System.IO;
|
7
|
using System.Linq;
|
8
|
using System.Web;
|
9
|
|
10
|
namespace gAMS_Sacombank.Web.ExportReport.CodeExport
|
11
|
{
|
12
|
/// <summary>
|
13
|
/// Dùng để xuất template excel(thường dùng cho xuất báo cáo)
|
14
|
/// htangiau12th01@gmail.com
|
15
|
/// </summary>
|
16
|
public class ExcelTemplateExportBase
|
17
|
{
|
18
|
#region "Properties"
|
19
|
|
20
|
public Dictionary<string,object> SmartmarkersObjData{get;set;}
|
21
|
/// <summary>
|
22
|
/// Lưu trữ thông tin đường dẫn teplate
|
23
|
/// </summary>
|
24
|
/// <value>
|
25
|
/// The template path.
|
26
|
/// </value>
|
27
|
public String TemplatePath { get; set; }
|
28
|
public String ErrorMessage { get; set; }
|
29
|
#endregion
|
30
|
#region Method
|
31
|
/// <summary>
|
32
|
/// Xuất báo cáo theo Smartmarkers
|
33
|
/// </summary>
|
34
|
/// <returns></returns>
|
35
|
public MemoryStream ExprortSmartmarkers()
|
36
|
{
|
37
|
MemoryStream dstStream = new MemoryStream();
|
38
|
WorkbookDesigner designer = new WorkbookDesigner()
|
39
|
{
|
40
|
Workbook = new Workbook(this.TemplatePath)
|
41
|
};
|
42
|
#region [Smart markers]
|
43
|
foreach (var smark in this.SmartmarkersObjData)
|
44
|
{
|
45
|
designer.SetDataSource(smark.Key, smark.Value);
|
46
|
}
|
47
|
designer.Process();
|
48
|
#endregion [Smart markers]
|
49
|
designer.Workbook.CalculateFormula();
|
50
|
designer.Workbook.Save(dstStream, SaveFormat.Xlsx);
|
51
|
return dstStream;
|
52
|
}
|
53
|
|
54
|
|
55
|
public MemoryStream ExprortSmartmarkersPDF()
|
56
|
{
|
57
|
MemoryStream dstStream = new MemoryStream();
|
58
|
WorkbookDesigner designer = new WorkbookDesigner()
|
59
|
{
|
60
|
Workbook = new Workbook(this.TemplatePath)
|
61
|
};
|
62
|
#region [Smart markers]
|
63
|
foreach (var smark in this.SmartmarkersObjData)
|
64
|
{
|
65
|
designer.SetDataSource(smark.Key, smark.Value);
|
66
|
}
|
67
|
|
68
|
designer.Process();
|
69
|
#endregion [Smart markers]
|
70
|
designer.Workbook.CalculateFormula();
|
71
|
|
72
|
// Wraptext
|
73
|
for (int i = 0; i < designer.Workbook.Worksheets.Count; i++)
|
74
|
{
|
75
|
designer.Workbook.Worksheets[i].AutoFitRows();
|
76
|
}
|
77
|
|
78
|
designer.Workbook.Save(dstStream, SaveFormat.Pdf);
|
79
|
return dstStream;
|
80
|
}
|
81
|
#endregion
|
82
|
}
|
83
|
}
|