Hare 是一种使用 NPOI在 Excel 文档中创建双重格式的简单方法。
//make NUMERIC Format in Excel Document // Author: Akavrelishvili
var eRow = sheet.CreateRow(rowIndex); //create new Row , rowIndex - it's integer, like : 1,2,3
eRow.CreateCell(0).SetCellValue(row["ProvidName"].ToString()); //create cell and set string value
double Amount = Convert.ToDouble(row["Amount"].ToString()); //convert string to double
eRow.CreateCell(1).SetCellValue(Amount); // create cell and set double value.
这是工作版本,我已经使用了很多项目。
很难在 Excel 中插入 DateTime 格式,互联网上没有很好的例子,我认为它可以帮助人们以正确的方式做到这一点。我向您展示代码示例:
//make Date Time Format in Excel Document // Author: Akavrelishvili
var eRow = sheet.CreateRow(rowIndex); //创建新行 // rowIndex - 它是整数,例如:1,2,3
ICellStyle cellDateStyle = workBook.CreateCellStyle(); //create custom style
cellDateStyle.DataFormat = workBook.CreateDataFormat().GetFormat("dd/mm/yyyy"); //set day time Format
eRow.CreateCell(3).SetCellValue(Convert.ToDateTime(row["Date"])); //set DateTime value to cell
eRow.GetCell(6).CellStyle = cellDateStyle; // Restyle cell using "cellDateStyle"
I hope it helps