本文整理匯總了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);
}