110,535
社区成员
发帖
与我相关
我的任务
分享
using GemBox.Spreadsheet;
........
...
public override void ExportDocumentProcess()
{
SpreadsheetInfo.SetLicense(BOSUtility.GetGemBoxExcelKey()); -->获取GemBox.Spreadsheet系列号
xlApp = new ExcelFile();
xlApp.LoadXls(this.ExportFileAppplicationPath);
ExcelWorksheet xlWorkSheet = xlApp.Worksheets[0];
int intTotalCount = DataSource.Count;
int starRows = 5;
ExcelRow row = xlWorkSheet.Rows[starRows];
var list = this.DataSource.GroupBy(t => t.IndvCourseName.Trim()).Select(g =>
{
return new
{
IndvCourseName = g.Key,
StudentCount = g.Count(),
Amount = g.Sum(t => t.Price)
};
});
int i = 0;
foreach (var item in list)
{
xlWorkSheet.Cells[starRows, 0].Value = item.IndvCourseName;
xlWorkSheet.Cells[starRows, 1].Value = item.StudentCount;
xlWorkSheet.Cells[starRows, 2].Value = "aaaaaaaaaaaaa";
xlWorkSheet.Cells[starRows, 3].Value = "bbbbbbbbbbbbbbbbb";
xlWorkSheet.Cells[starRows, 4].Value = item.Amount;
if (i < list.Count() - 1)
{
xlWorkSheet.Rows[starRows].InsertCopy(1, row);
starRows++;
}
i++;
}
xlApp.SaveXls(this.ExportFileAppplicationPath); -->保存文件
}
public override void ExportDocumentRelease()
{
releaseObject(xlApp);
}
private void releaseObject(object obj)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
obj = null;
}
catch
{
obj = null;
}
finally
{
GC.Collect();
}
}