BOS运行时 - 引出 - 引出Excel支持币别
列表引出时,支持了引出币别符号功能。标准平台是通过设置NPOI相关格式实现支持,以下案例演示引出excel支持币别符号。实现效果如下:
参考代码实现(仅NPOI设置格式部分)
private string NPOIExport(DataTable tb) { var wb = new SXSSFWorkbook(); SXSSFSheet sheet = (SXSSFSheet)wb.CreateSheet("demo"); var tempXmlFile = sheet._writer.TemporaryFilePath(); string fileName = string.Format("NPOI-demo-{0}.xlsx", DateTime.Now.ToString("yyyyMMddhhmmss")); var filePath = PathUtils.GetPhysicalPath(KeyConst.TEMPFILEPATH, fileName); var fileUrl = PathUtils.GetServerPath(KeyConst.TEMPFILEPATH, PathUtils.UrlEncode(fileName)); try { for (int i = 0; i < tb.Rows.Count; i++) { IRow row = sheet.CreateRow(i); for (int colIndex = 0; colIndex < tb.Columns.Count; colIndex++) { ICell cell = row.CreateCell(colIndex); ICellStyle textCellStyle = wb.CreateCellStyle(); if (cell.ColumnIndex > 2 && i > 0) { var symbol = "$"; if(symbolDic.ContainsKey(i)) { symbol = symbolDic[i]; } textCellStyle.DataFormat = wb.CreateDataFormat().GetFormat(string.Format("{0}#,##0.00",symbol)); cell.SetCellValue(double.Parse(tb.Rows[i][colIndex].ToString())); } else { textCellStyle.DataFormat = wb.CreateDataFormat().GetFormat("@"); cell.SetCellValue(tb.Rows[i][colIndex].ToString()); } cell.CellStyle = textCellStyle; //设计公式 if (cell.ColumnIndex == 5 && i > 0) { cell.CellFormula = string.Format("D{0}*E{0}", i + 1); } if (i % 2 == 0) { textCellStyle.FillForegroundColor = HSSFColor.Grey25Percent.Index; textCellStyle.FillPattern = FillPattern.SolidForeground; } } } //增加汇总行 IRow rowSummary = sheet.CreateRow(tb.Rows.Count); for (int colIndex = 0; colIndex < tb.Columns.Count; colIndex++) { //第一列汇总 ICell cell = rowSummary.CreateCell(colIndex); ICellStyle textCellStyle = wb.CreateCellStyle(); if (colIndex == 0) { textCellStyle.DataFormat = wb.CreateDataFormat().GetFormat("@"); cell.SetCellValue("合计"); } else if (cell.ColumnIndex > 2) { textCellStyle.DataFormat = wb.CreateDataFormat().GetFormat("#,##0.00"); cell.CellFormula = string.Format("SUM({0}{1}:{0}{2})", excelDic[colIndex], 1, tb.Rows.Count); } } //写入Excel using (FileStream fs = File.OpenWrite(filePath)) { wb.Write(fs); } } finally { if (wb != null) { wb.Close(); } //清理中间临时xml文件 if (File.Exists(tempXmlFile)) { File.Delete(tempXmlFile); } } return fileUrl; } private Dictionary<int, string> symbolDic = new Dictionary<int, string>() { {0,"$" }, {1,"¥" }, {2,"[$NTY]" }, };
BOS运行时 - 引出 - 引出Excel支持币别
列表引出时,支持了引出币别符号功能。标准平台是通过设置NPOI相关格式实现支持,以下案例演示引出excel支持币别符号。实现效果如下:参考...
点击下载文档
本文2024-09-23 04:17:07发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-164319.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章