GoldPrinter套用模板打印导出

string path = HttpContext.Current.Server.MapPath(项目中所包含的路径);//找到绝对项目下所包含的路径

GoldPrinter.ExcelAccess excel = new GoldPrinter.ExcelAccess();

excel.Open(path);//打开模板

List<T> list = 所要获得的数据

if (list != null && list.Count > 0)
{
int row = 4;
for (int i = 0; i < list.Count; i++)
{
excel.SetCellText(row, 1, list[i].XXX);
excel.SetCellText(row, 2, list[i].XXX);
row += 1;
}
}

excel.SetBordersEdge(4, 1, list.Count+4, 5, true);//加上边框

//excel.PrintPreview();--打印
//excel.Print();     --显示
string paths = HttpContext.Current.Server.MapPath("/ExportFile/" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");//存储于相对路径
excel.SaveAs(paths, false);//保存
excel.Close();//下载

return paths;//返回下载路径

posted @ 2022-02-25 15:36  森雾  阅读(52)  评论(0编辑  收藏  举报