當前位置: 首頁>>代碼示例>>C#>>正文


C# HSSFWorkbook.SetCellValue方法代碼示例

本文整理匯總了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);
        }
開發者ID:kirkpabk,項目名稱:higgs,代碼行數:58,代碼來源:ExcelHelper.cs


注:本文中的NPOI.HSSF.UserModel.HSSFWorkbook.SetCellValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。