本文整理汇总了C#中NPOI.HSSF.UserModel.HSSFWorkbook.SetCellValue方法的典型用法代码示例。如果您正苦于以下问题:C# HSSFWorkbook.SetCellValue方法的具体用法?C# HSSFWorkbook.SetCellValue怎么用?C# HSSFWorkbook.SetCellValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NPOI.HSSF.UserModel.HSSFWorkbook
的用法示例。
在下文中一共展示了HSSFWorkbook.SetCellValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Export
// TODO: Move to OOXML
public static void Export(this IEnumerable data, Stream stream, List<ExportColumnModel> colModel)
{
var workbook = new HSSFWorkbook();
////create a entry of DocumentSummaryInformation
var dsi = PropertySetFactory.CreateDocumentSummaryInformation();
dsi.Company = "Higgs RIA Framework";
workbook.DocumentSummaryInformation = dsi;
////create a entry of SummaryInformation
var si = PropertySetFactory.CreateSummaryInformation();
si.Subject = "JqGrid Export Data";
workbook.SummaryInformation = si;
var sheet = workbook.CreateSheet("Export-Data");
var count = 1;
var firstRow = sheet.CreateRow(0);
for(var i = 0;i < colModel.Count;i++)
{
firstRow
.CreateCell(i)
.SetCellValue(colModel[i].Title);
}
sheet.CreateFreezePane(0, 1);
Dictionary<string, PropertyInfo> properties = null;
foreach (var item in data)
{
if (properties == null)
{
properties = item.GetType()
.GetProperties()
.ToDictionary(pi => pi.Name);
}
var row = sheet.CreateRow(count++);
for (var i = 0; i < colModel.Count; i++)
{
var cell = row.CreateCell(i);
if(!properties.ContainsKey(colModel[i].Name)) continue;
var cellValue = properties[colModel[i].Name].GetValue(item, null);
workbook.SetCellValue(cell, cellValue);
}
}
for (var i = 0; i < colModel.Count; i++)
{
sheet.AutoSizeColumn(i);
}
workbook.Write(stream);
}