当前位置: 首页>>代码示例>>C#>>正文


C# HSSFSheet.CreateRow方法代码示例

本文整理汇总了C#中NPOI.HSSF.UserModel.HSSFSheet.CreateRow方法的典型用法代码示例。如果您正苦于以下问题:C# HSSFSheet.CreateRow方法的具体用法?C# HSSFSheet.CreateRow怎么用?C# HSSFSheet.CreateRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NPOI.HSSF.UserModel.HSSFSheet的用法示例。


在下文中一共展示了HSSFSheet.CreateRow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExcalHelper

        public ExcalHelper(String sheetName, String[] rowTitle, int[] rowWidth, int dataRowNum)
        {
            //创建标题行
            workbook = new HSSFWorkbook();
            sheet = (HSSFSheet)workbook.CreateSheet(sheetName);
            this.dataRowNum = dataRowNum;

            HSSFRow rowtitle = (HSSFRow)sheet.CreateRow(0);

            for (int i = 0; i < rowTitle.Length; i++)
            {
                //设置列宽
                sheet.SetColumnWidth(i, rowWidth[i] * 255);
                rowtitle.CreateCell(i).SetCellValue(rowTitle[i]);
            }
        }
开发者ID:freedomwork,项目名称:playground,代码行数:16,代码来源:ExcelHelper.cs

示例2: MyInsertRow

        /// <summary>
        /// 插入Excel行
        /// </summary>
        /// <param name="sheet"></param>
        /// <param name="rowIndex"></param>
        /// <param name="count"></param>
        /// <param name="row"></param>
        private static void MyInsertRow(HSSFSheet sheet, int rowIndex, int count, HSSFRow row)
        {
            #region 批量移动行
            sheet.ShiftRows(
                                rowIndex,                                 //--开始行
                                sheet
                                .LastRowNum,                            //--结束行
                                count,                             //--移动大小(行数)--往下移动
                                true,                                   //是否复制行高
                                false,                                  //是否重置行高
                                true                                    //是否移动批注
                            );
            #endregion

            #region 对批量移动后空出的空行插,创建相应的行,并以插入行的上一行为格式源(即:插入行-1的那一行)
            for (int i = rowIndex; i < rowIndex + count - 1; i++)
            {
                HSSFRow targetRow;
                HSSFCell sourceCell;
                HSSFCell targetCell;

                targetRow = sheet.CreateRow(i + 1);
                for (int m = row.FirstCellNum; m < row.LastCellNum; m++)
                {
                    sourceCell = row.GetCell(m);
                    if (sourceCell == null)
                        continue;
                    targetCell = targetRow.CreateCell(m);

                    targetCell.Encoding = sourceCell.Encoding;
                    targetCell.CellStyle = sourceCell.CellStyle;
                    targetCell.SetCellType(sourceCell.CellType);

                }
                //CopyRow(sourceRow, targetRow);

                //Util.CopyRow(sheet, sourceRow, targetRow);
            }

            HSSFRow firstTargetRow = sheet.GetRow(rowIndex);
            HSSFCell firstSourceCell;
            HSSFCell firstTargetCell = null;
            for (int m = row.FirstCellNum; m < row.LastCellNum; m++)
            {
                firstSourceCell = row.GetCell(m);
                if (firstSourceCell == null)
                    continue;
                firstTargetCell = firstTargetRow.CreateCell(m);
                firstTargetCell.Encoding = firstSourceCell.Encoding;
                firstTargetCell.CellStyle = firstSourceCell.CellStyle;
                firstTargetCell.SetCellType(firstSourceCell.CellType);
            }
            sheet.AddMergedRegion(new Region(firstTargetRow.RowNum, 3, firstTargetRow.RowNum, 4));
            #endregion
        }
开发者ID:alejsherion,项目名称:gggets,代码行数:62,代码来源:NPOIHelper.cs

示例3: SetTeacherSalary

        private void SetTeacherSalary(HSSFSheet sheet, string teacherName, string termTag, int teacherType, int status)
        {
            Dictionary<string, int> inSalaryItemIndex = new Dictionary<string, int>();
            Dictionary<string, int> outSalaryItemIndex = new Dictionary<string, int>();
            int cIndex = 0;
            sheet.CreateRow(1).CreateCell(cIndex++).SetCellValue("姓名");
            sheet.CreateRow(1).CreateCell(cIndex++).SetCellValue("类型");
            if (teacherType != 1)
            {
                sheet.CreateRow(1).CreateCell(cIndex++).SetCellValue("课程");
            }
            sheet.CreateRow(1).CreateCell(cIndex++).SetCellValue("薪酬预算");
            sheet.CreateRow(1).CreateCell(cIndex++).SetCellValue("学期");
            sheet.CreateRow(1).CreateCell(cIndex++).SetCellValue("状态");

            List<SalaryItem> salaryItems = GetSalaryItem(teacherType);
            int count = salaryItems.Count;
            for (var i = 0; i < count; i++)
            {
                sheet.CreateRow(1).CreateCell(cIndex + i).SetCellValue(salaryItems[i].salaryItemName);
                inSalaryItemIndex.Add(salaryItems[i].salaryItemId.ToString(), cIndex + i);
            }

            sheet.CreateRow(0).CreateCell(0).SetCellValue("基本信息");
            sheet.CreateRow(0).CreateCell(cIndex).SetCellValue("薪酬预算");

            List<TeacherSalary> teacherSalaries = QueryTeacherSalaries(teacherName, termTag, teacherType, status);
            TeacherSalary teacherSalary;
            double totalTeachCost = 0;
            for (var i = 0; i < teacherSalaries.Count; i++)
            {
                cIndex = 0;
                teacherSalary = teacherSalaries[i];
                sheet.CreateRow(i + 2).CreateCell(cIndex++).SetCellValue(teacherSalary.teacher.teacherName);
                sheet.CreateRow(i + 2).CreateCell(cIndex++).SetCellValue(CommonUtility.ConvertTeacherType2String(teacherSalary.teacherType));
                if (teacherType != 1)
                {
                    sheet.CreateRow(i + 2).CreateCell(cIndex++).SetCellValue(teacherSalary.course == null ? "" : teacherSalary.course.courseName);
                }

                sheet.CreateRow(i + 2).CreateCell(cIndex++).SetCellValue(teacherSalary.totalTeachCost);
                totalTeachCost += teacherSalary.totalTeachCost;
                sheet.CreateRow(i + 2).CreateCell(cIndex++).SetCellValue(teacherSalary.termTag);
                sheet.CreateRow(i + 2).CreateCell(cIndex++).SetCellValue(teacherSalary.isConfirm ? "已确认" : "未确认");

                List<SalaryItemElement> inItemElements = teacherSalary.GetSalaryInItemElements();

                if (inItemElements != null)
                {
                    foreach (SalaryItemElement itemElement in inItemElements)
                    {
                        sheet.CreateRow(i + 2).CreateCell(inSalaryItemIndex[itemElement.salaryItemId.ToString()]).SetCellValue(itemElement.itemCost);
                    }
                }
            }
            cIndex = 2;
            sheet.CreateRow((cIndex++) + teacherSalaries.Count).CreateCell(0).SetCellValue("-----");
            sheet.CreateRow((cIndex++) + teacherSalaries.Count).CreateCell(0).SetCellValue("合计薪酬金额:" + totalTeachCost);
        }
开发者ID:skyaspnet,项目名称:usta,代码行数:59,代码来源:OutPutTeacherSalaryExcel.ashx.cs

示例4: CopyRow

        /// <summary>
        /// HSSFRow Copy Command
        ///
        /// Description:  Inserts a existing row into a new row, will automatically push down
        ///               any existing rows.  Copy is done cell by cell and supports, and the
        ///               command tries to copy all properties available (style, merged cells, values, etc...)
        /// </summary>
        /// <param name="workbook">Workbook containing the worksheet that will be changed</param>
        /// <param name="worksheet">WorkSheet containing rows to be copied</param>
        /// <param name="sourceRowNum">Source Row Number</param>
        /// <param name="destinationRowNum">Destination Row Number</param>
        private HSSFRow CopyRow(HSSFWorkbook workbook, HSSFSheet worksheet, int sourceRowNum, int destinationRowNum)
        {
            // Get the source / new row
            var newRow = (HSSFRow)worksheet.GetRow(destinationRowNum);
            var sourceRow = (HSSFRow)worksheet.GetRow(sourceRowNum);

            // If the row exist in destination, push down all rows by 1 else create a new row
            if (newRow != null)
            {
                worksheet.ShiftRows(destinationRowNum, worksheet.LastRowNum, 1);
            }
            else
            {
                newRow = (HSSFRow)worksheet.CreateRow(destinationRowNum);
            }

            // Loop through source columns to add to new row
            for (var i = 0; i < sourceRow.LastCellNum; i++)
            {
                // Grab a copy of the old/new cell
                var oldCell = (HSSFCell)sourceRow.GetCell(i);
                var newCell = (HSSFCell)newRow.CreateCell(i);

                // If the old cell is null jump to next cell
                if (oldCell == null) continue;

                // Copy style from old cell and apply to new cell
                var newCellStyle = (HSSFCellStyle)workbook.CreateCellStyle();
                newCellStyle.CloneStyleFrom(oldCell.CellStyle);
                newCell.CellStyle = newCellStyle;

                // If there is a cell comment, copy
                if (newCell.CellComment != null) newCell.CellComment = oldCell.CellComment;

                // If there is a cell hyperlink, copy
                if (oldCell.Hyperlink != null) newCell.Hyperlink = oldCell.Hyperlink;

                // Set the cell data type
                newCell.SetCellType(oldCell.CellType);

                // Set the cell data value
                switch (oldCell.CellType)
                {
                    case CellType.BLANK:
                        newCell.SetCellValue(oldCell.StringCellValue);
                        break;
                    case CellType.BOOLEAN:
                        newCell.SetCellValue(oldCell.BooleanCellValue);
                        break;
                    case CellType.ERROR:
                        newCell.SetCellErrorValue(oldCell.ErrorCellValue);
                        break;
                    case CellType.FORMULA:
                        newCell.CellFormula = oldCell.CellFormula;
                        break;
                    case CellType.NUMERIC:
                        newCell.SetCellValue(oldCell.NumericCellValue);
                        break;
                    case CellType.STRING:
                        newCell.SetCellValue(oldCell.RichStringCellValue);
                        break;
                    case CellType.Unknown:
                        newCell.SetCellValue(oldCell.StringCellValue);
                        break;
                }
            }

            // If there are are any merged regions in the source row, copy to new row
            for (var i = 0; i < worksheet.NumMergedRegions; i++)
            {
                var cellRangeAddress = worksheet.GetMergedRegion(i);
                if (cellRangeAddress.FirstRow != sourceRow.RowNum) continue;
                var newCellRangeAddress = new CellRangeAddress(newRow.RowNum,
                                                               (newRow.RowNum +
                                                                (cellRangeAddress.FirstRow -
                                                                 cellRangeAddress.LastRow)),
                                                               cellRangeAddress.FirstColumn,
                                                               cellRangeAddress.LastColumn);
                worksheet.AddMergedRegion(newCellRangeAddress);
            }

            return newRow;
        }
开发者ID:kapolb,项目名称:Test,代码行数:94,代码来源:ExcelManager.cs

示例5: InsertRows

        private void InsertRows(HSSFSheet sheet1, int fromRowIndex, int rowCount)
        {
            sheet1.ShiftRows(fromRowIndex, sheet1.LastRowNum, rowCount, true, false, true);

            for (int rowIndex = fromRowIndex; rowIndex < fromRowIndex + rowCount; rowIndex++)
            {
                IRow rowSource = sheet1.GetRow(rowIndex + rowCount);
                IRow rowInsert = sheet1.CreateRow(rowIndex);
                rowInsert.Height = rowSource.Height;
                for (int colIndex = 0; colIndex < rowSource.LastCellNum; colIndex++)
                {
                    ICell cellSource = rowSource.GetCell(colIndex);
                    ICell cellInsert = rowInsert.CreateCell(colIndex);
                    if (cellSource != null)
                    {
                        cellInsert.CellStyle = cellSource.CellStyle;
                    }
                }
            }
        }
开发者ID:jcingroup,项目名称:C481511_TGPF,代码行数:20,代码来源:XlsController.cs

示例6: ImportDt

        /// <summary>
        /// 将制定sheet中的数据导出到datatable中
        /// </summary>
        /// <param name="sheet">需要导出的sheet</param>
        /// <param name="HeaderRowIndex">列头所在行号,-1表示没有列头</param>
        /// <returns></returns>
        static DataTable ImportDt(HSSFSheet sheet, int HeaderRowIndex, bool needHeader)
        {
            DataTable table = new DataTable();
            HSSFRow headerRow;
            int cellCount;
            try
            {
                if (HeaderRowIndex < 0 || !needHeader)
                {
                    headerRow = sheet.GetRow(0) as HSSFRow;
                    cellCount = headerRow.LastCellNum;

                    for (int i = headerRow.FirstCellNum; i <= cellCount; i++)
                    {
                        DataColumn column = new DataColumn(Convert.ToString(i));
                        table.Columns.Add(column);
                    }
                }
                else
                {
                    headerRow = sheet.GetRow(HeaderRowIndex) as HSSFRow;
                    cellCount = headerRow.LastCellNum;

                    for (int i = headerRow.FirstCellNum; i <= cellCount; i++)
                    {
                        if (headerRow.GetCell(i) == null)
                        {
                            if (table.Columns.IndexOf(Convert.ToString(i)) > 0)
                            {
                                DataColumn column = new DataColumn(Convert.ToString("重复列名" + i));
                                table.Columns.Add(column);
                            }
                            else
                            {
                                DataColumn column = new DataColumn(Convert.ToString(i));
                                table.Columns.Add(column);
                            }

                        }
                        else if (table.Columns.IndexOf(headerRow.GetCell(i).ToString()) > 0)
                        {
                            DataColumn column = new DataColumn(Convert.ToString("重复列名" + i));
                            table.Columns.Add(column);
                        }
                        else
                        {
                            DataColumn column = new DataColumn(headerRow.GetCell(i).ToString());
                            table.Columns.Add(column);
                        }
                    }
                }
                int rowCount = sheet.LastRowNum;
                for (int i = (HeaderRowIndex + 1); i <= sheet.LastRowNum; i++)
                {
                    try
                    {
                        HSSFRow row;
                        if (sheet.GetRow(i) == null)
                        {
                            row = sheet.CreateRow(i) as HSSFRow;
                        }
                        else
                        {
                            row = sheet.GetRow(i) as HSSFRow;
                        }

                        DataRow dataRow = table.NewRow();

                        for (int j = row.FirstCellNum; j <= cellCount; j++)
                        {
                            try
                            {
                                if (row.GetCell(j) != null)
                                {
                                    switch (row.GetCell(j).CellType)
                                    {
                                        case CellType.STRING:
                                            string str = row.GetCell(j).StringCellValue;
                                            if (str != null && str.Length > 0)
                                            {
                                                dataRow[j] = str.ToString();
                                            }
                                            else
                                            {
                                                dataRow[j] = null;
                                            }
                                            break;
                                        case CellType.NUMERIC:
                                            if (DateUtil.IsCellDateFormatted(row.GetCell(j)))
                                            {
                                                dataRow[j] = DateTime.FromOADate(row.GetCell(j).NumericCellValue);
                                            }
                                            else
                                            {
//.........这里部分代码省略.........
开发者ID:aNd1coder,项目名称:Wojoz,代码行数:101,代码来源:ExcelHelper.cs

示例7: populateStrategyDetailData

        public static void populateStrategyDetailData(HSSFWorkbook wb, HSSFSheet sheet, IEnumerable<ArchitecturalStrategy> data)
        {
            #region workbookStyles
            //add Styles to workbook
            HSSFCellStyle styleMiddle = wb.CreateCellStyle();
            styleMiddle.Alignment = CellHorizontalAlignment.CENTER;
            HSSFCellStyle styleLeftWrap = wb.CreateCellStyle();
            styleLeftWrap.Alignment = CellHorizontalAlignment.LEFT;
            styleMiddle.VerticalAlignment = CellVerticalAlignment.CENTER;
            styleLeftWrap.WrapText = true;    //wrap the text in the cell
            //----------------------------------------------------------

            //font style1:  italic, blue color, fontsize=20
            HSSFFont font1 = wb.CreateFont();
            font1.Color = HSSFColor.BLUE.index;
            font1.IsItalic = true;
            font1.Boldweight = HSSFFont.BOLDWEIGHT_BOLD;
            font1.Underline = (byte)HSSFBorderFormatting.BORDER_THIN;
               // font1.Underline = (byte)FontUnderlineType.DOUBLE;
               // font1.FontHeightInPoints = 20;

            //bind font with styleItalicBold
            HSSFCellStyle italicBold = wb.CreateCellStyle();
            italicBold.SetFont(font1);
            //----------------------------------------------------------

            //bind font with styleItalicBold
            HSSFCellStyle underline = wb.CreateCellStyle();
            underline.BorderBottom = CellBorderType.THIN;
            underline.BottomBorderColor = HSSFColor.BLUE_GREY.index;

            HSSFCellStyle topline = wb.CreateCellStyle();
            topline.BorderTop = CellBorderType.THIN;
            topline.TopBorderColor = HSSFColor.BLUE_GREY.index;

            #endregion
            //set headerRow and 1st column
            const int maxRows = 65536; //npoi uses excel 2003
            int hRowNum = 4; //row starts at 0.
            int startCol = 0;
            int errorRow = 2; //note errors
            int errorCol = 6; //note errors

            HSSFRow headerRow = sheet.GetRow(hRowNum);
            int colIndex = startCol;

            #region Headers
            //date
            sheet.GetRow(0).GetCell(1).SetCellValue(DateTime.Now);

            //Title
            sheet.GetRow(1).GetCell(1).SetCellValue(data.FirstOrDefault().Project.Name);

            // handling headers.
            headerRow.GetCell(colIndex).SetCellValue("Strategy");
            colIndex++;
            headerRow.GetCell(colIndex).SetCellValue("Name");
            colIndex++;
            headerRow.GetCell(colIndex).SetCellValue("Description");
            colIndex++;
            headerRow.GetCell(colIndex).SetCellValue("Scenarios Affected");
            colIndex++;
            headerRow.GetCell(colIndex).SetCellValue("Current Response");
            colIndex++;
            headerRow.GetCell(colIndex).SetCellValue("Expected Response");
            colIndex++;
            headerRow.GetCell(colIndex).SetCellValue("Current Utility");
            colIndex++;
            headerRow.GetCell(colIndex).SetCellValue("Expected Utility");
            colIndex++;
            #endregion //headers

            #region populateData
            // foreach (DataColumn column in propertyInfos)
            //     headerRow.CreateCell(column.Ordinal).SetCellValue(column.ColumnName);

            // handling value.
            int rowIndex = hRowNum + 1;
            HSSFRow dataRow = sheet.CreateRow(rowIndex);
            Boolean newStrategyRow = true;
            var i = 0; //index for loops
            try
            {
                foreach (var item in data)
                {
                    dataRow = sheet.CreateRow(rowIndex);
                    if (rowIndex < maxRows - 1)
                    {
                        //write each field
                        newStrategyRow = true;
                        colIndex = startCol;
                        dataRow.CreateCell(colIndex).SetCellValue(item.ID);
                        dataRow.GetCell(colIndex).CellStyle = topline;
                        colIndex++;
                        dataRow.CreateCell(colIndex).SetCellValue(item.Name.ToString());
                        dataRow.GetCell(colIndex).CellStyle = topline;
                        colIndex++;
                        dataRow.CreateCell(colIndex).SetCellValue(item.Description.ToString());
                        dataRow.GetCell(colIndex).CellStyle = topline;
                        colIndex++;
//.........这里部分代码省略.........
开发者ID:LMDarville,项目名称:CBAM,代码行数:101,代码来源:ReportController.cs

示例8: GetRow

        /// <summary>
        /// Get a row from the spreadsheet, and Create it if it doesn't exist.
        /// </summary>
        /// <param name="rowCounter">The 0 based row number</param>
        /// <param name="sheet">The sheet that the row is part of.</param>
        /// <returns>The row indicated by the rowCounter</returns>
        public static NPOI.SS.UserModel.IRow GetRow(int rowCounter, HSSFSheet sheet)
        {
            NPOI.SS.UserModel.IRow row = sheet.GetRow(rowCounter);
            if (row == null)
            {
                row = sheet.CreateRow(rowCounter);
            }

            return row;
        }
开发者ID:WPG,项目名称:npoi,代码行数:16,代码来源:HSSFCellUtil.cs

示例9: SetProjectSummarySheet

        private void SetProjectSummarySheet(HSSFSheet projectSummarySheet, List<ReimItem> projectReimSummaryList)
        {
            int cIndex = 0;
            projectSummarySheet.CreateRow(0).CreateCell(cIndex++).SetCellValue("项目名称");
            projectSummarySheet.CreateRow(0).CreateCell(cIndex++).SetCellValue("报销金额");

            if (projectReimSummaryList != null)
            {
                for (int rIndex = 0; rIndex < projectReimSummaryList.Count; rIndex++)
                {
                    cIndex = 0;
                    projectSummarySheet.CreateRow(rIndex + 1).CreateCell(cIndex++).SetCellValue(projectReimSummaryList[rIndex].project.name);
                   projectSummarySheet.CreateRow(rIndex + 1).CreateCell(cIndex++).SetCellValue(projectReimSummaryList[rIndex].value);
                }
            }
        }
开发者ID:skyaspnet,项目名称:usta,代码行数:16,代码来源:OutPutProjectReimExcel.ashx.cs

示例10: WriteCell

 /// <summary>
 /// 往单元格写数据
 /// </summary>
 /// <param name="sheet"></param>
 /// <param name="columnIndex"></param>
 /// <param name="rowIndex"></param>
 /// <param name="obj"></param>
 /// <returns></returns>
 public static HSSFCell WriteCell(HSSFSheet sheet, int columnIndex, int rowIndex, object obj)
 {
     HSSFRow row = sheet.GetRow(rowIndex);
     if (row == null)
     {
         row = sheet.CreateRow(rowIndex);
     }
     return WriteCell(row, obj, columnIndex);
 }
开发者ID:XiaoQiJun,项目名称:BPS,代码行数:17,代码来源:ExcelHelper.cs

示例11: WriteRow

 /// <summary>
 /// 写入行
 /// </summary>
 public static HSSFRow WriteRow(HSSFSheet sheet, object[] dr, int rowIndex, int columnIndex)
 {
     HSSFRow row = sheet.CreateRow(rowIndex);
     int i = 0;
     while (i < dr.Length)
     {
         WriteCell(row, dr[i], i);
         i++;
         columnIndex++;
     }
     return row;
 }
开发者ID:XiaoQiJun,项目名称:BPS,代码行数:15,代码来源:ExcelHelper.cs

示例12: SetProjectSheet

        private void SetProjectSheet(HSSFSheet projectSheet, List<Project> projectList)
        {
            int cIndex = 0;
            projectSheet.CreateRow(0).CreateCell(cIndex++).SetCellValue("项目名称");
            projectSheet.CreateRow(0).CreateCell(cIndex++).SetCellValue("项目负责人");
            projectSheet.CreateRow(0).CreateCell(cIndex++).SetCellValue("项目类别");
            projectSheet.CreateRow(0).CreateCell(cIndex++).SetCellValue("登记时间");

            for (int rIndex = 0; rIndex < projectList.Count; rIndex++)
            {
                cIndex = 0;
                projectSheet.CreateRow(rIndex + 1).CreateCell(cIndex++).SetCellValue(projectList[rIndex].name);
                projectSheet.CreateRow(rIndex + 1).CreateCell(cIndex++).SetCellValue(projectList[rIndex].userName);
                projectSheet.CreateRow(rIndex + 1).CreateCell(cIndex++).SetCellValue(projectList[rIndex].category.name);
                projectSheet.CreateRow(rIndex + 1).CreateCell(cIndex++).SetCellValue(projectList[rIndex].createdTime.ToString());

            }
        }
开发者ID:skyaspnet,项目名称:usta,代码行数:18,代码来源:OutPutProjectExcel.ashx.cs

示例13: populateResponseGoalData

        // IEnumerable<TestData> data = db.TestDatas;
        public static void populateResponseGoalData(HSSFWorkbook wb, HSSFSheet sheet, IEnumerable<Scenario> data)
        {
            //set headerRow and 1st column
            const int maxRows = 65536; //npoi uses excel 2003
            int hRowNum = 4; //row starts at 0.
            int startCol = 0;
            HSSFRow headerRow = sheet.GetRow(hRowNum);
            int colIndex = startCol;
            int errorRow = 2; //note errors
            int errorCol = 6; //note errors

            #region headers
            //date
            sheet.GetRow(0).GetCell(1).SetCellValue(DateTime.Now);
            //Title
            sheet.GetRow(1).GetCell(1).SetCellValue(data.FirstOrDefault().Project.Name);

            // handling headers.
            headerRow.GetCell(colIndex).SetCellValue("Priority");
            colIndex++;
            headerRow.GetCell(colIndex).SetCellValue("Name");
            colIndex++;
            headerRow.GetCell(colIndex).SetCellValue("Votes");
            colIndex++;
            foreach (var utilityitem in data.FirstOrDefault().Utilities)
            {
                //write each field

                headerRow.GetCell(colIndex).SetCellValue(utilityitem.QualityAttributeResponseType.Type.ToString() + " Response Goal");
                colIndex++;

                headerRow.GetCell(colIndex).SetCellValue(utilityitem.QualityAttributeResponseType.Type.ToString()+ " Utility");
                colIndex++;

            //    if (utilityitem.Utility1.HasValue)//only top 1/6 have utility value
            //    {
            //        headerRow.GetCell(colIndex).SetCellValue(utilityitem.Description.ToString());
            //    }
            //    colIndex++;
            }// end utility item loop
            #endregion

            #region populateData
            // foreach (DataColumn column in propertyInfos)
            //     headerRow.CreateCell(column.Ordinal).SetCellValue(column.ColumnName);

            // handling value.
            int rowIndex = hRowNum + 1;
            try{

                foreach (var item in data)
                {
                    HSSFRow dataRow = sheet.CreateRow(rowIndex);
                    if (rowIndex < maxRows - 1)
                        {
                            colIndex = startCol;

                            dataRow.CreateCell(colIndex).SetCellValue(item.Priority.ToString());
                            colIndex++;

                            dataRow.CreateCell(colIndex).SetCellValue(item.Name.ToString());
                            colIndex++;

                            dataRow.CreateCell(colIndex).SetCellValue(item.Votes.Value);
                            colIndex++;

                            foreach (var utilityitem in item.Utilities)
                            {
                                    //write each field

                                    dataRow.CreateCell(colIndex).SetCellValue(utilityitem.Description.ToString());
                                    colIndex++;

                                    if (utilityitem.Utility1.HasValue)//only top 1/6 have utility value
                                    {
                                        dataRow.CreateCell(colIndex).SetCellValue(utilityitem.Utility1.Value);
                                    }
                                    colIndex++;
                            }// end utility item loop
                                rowIndex++;
                            }//end if check max rows
            #endregion
            #region populateErrors
                     else
                    {
                        colIndex = startCol;
                        dataRow.CreateCell(colIndex).SetCellValue("Dataset exceeds maximum number of rows");
                        sheet.GetRow(errorRow).CreateCell(errorCol).SetCellValue("Data Exceeds max records");
                    }

                }//end data loop
            }// end try
            catch
            {
                colIndex = startCol;
                if (sheet.GetRow(errorRow).LastCellNum >= errorCol) //error cell exists
                {
                    sheet.GetRow(errorRow).GetCell(errorCol).SetCellValue("Error Occured");
                }
//.........这里部分代码省略.........
开发者ID:LMDarville,项目名称:CBAM,代码行数:101,代码来源:ReportController.cs

示例14: GetRow

        /// <summary>
        /// Get a row from the spreadsheet, and Create it if it doesn't exist.
        /// </summary>
        /// <param name="rowCounter">The 0 based row number</param>
        /// <param name="sheet">The sheet that the row is part of.</param>
        /// <returns>The row indicated by the rowCounter</returns>
        public static HSSFRow GetRow(int rowCounter, HSSFSheet sheet)
        {
            HSSFRow row = sheet.GetRow(rowCounter);
            if (row == null)
            {
                row = sheet.CreateRow(rowCounter);
            }

            return row;
        }
开发者ID:ChiangHanLung,项目名称:PIC_VDS,代码行数:16,代码来源:HSSFCellUtil.cs

示例15: SetProjectReimSheet

        private void SetProjectReimSheet(HSSFSheet projectSheet, List<ReimItem> reimItemList)
        {
            int cIndex = 0;
            projectSheet.CreateRow(0).CreateCell(cIndex++).SetCellValue("项目名称");
            projectSheet.CreateRow(0).CreateCell(cIndex++).SetCellValue("报销项名称");
            projectSheet.CreateRow(0).CreateCell(cIndex++).SetCellValue("报销金额");
            projectSheet.CreateRow(0).CreateCell(cIndex++).SetCellValue("报销时间");
            if (reimItemList != null) {
                for (int rIndex = 0; rIndex < reimItemList.Count; rIndex++)
                {
                    cIndex = 0;
                    projectSheet.CreateRow(rIndex + 1).CreateCell(cIndex++).SetCellValue(reimItemList[rIndex].project.name);
                    projectSheet.CreateRow(rIndex + 1).CreateCell(cIndex++).SetCellValue(reimItemList[rIndex].reim.name);
                    projectSheet.CreateRow(rIndex + 1).CreateCell(cIndex++).SetCellValue(reimItemList[rIndex].value);
                    projectSheet.CreateRow(rIndex + 1).CreateCell(cIndex++).SetCellValue(reimItemList[rIndex].createdTime.ToString());

                }
            }
        }
开发者ID:skyaspnet,项目名称:usta,代码行数:19,代码来源:OutPutProjectReimExcel.ashx.cs


注:本文中的NPOI.HSSF.UserModel.HSSFSheet.CreateRow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。