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.FillPatteBOS运行时 - 引出 - 引出Excel支持币别
列表引出时,支持了引出币别符号功能。标准平台是通过设置NPOI相关格式实现支持,以下案例演示引出excel支持币别符号。实现效果如下:参考...
点击下载文档文档为doc格式
声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。如若本站内容侵犯了原著者的合法权益,可联系本站删除。
上一篇
已经是第一篇



