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


C# XSSFWorkbook.GetSheetName方法代碼示例

本文整理匯總了C#中NPOI.XSSF.UserModel.XSSFWorkbook.GetSheetName方法的典型用法代碼示例。如果您正苦於以下問題:C# XSSFWorkbook.GetSheetName方法的具體用法?C# XSSFWorkbook.GetSheetName怎麽用?C# XSSFWorkbook.GetSheetName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在NPOI.XSSF.UserModel.XSSFWorkbook的用法示例。


在下文中一共展示了XSSFWorkbook.GetSheetName方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: TestLoadSample

 public void TestLoadSample()
 {
     XSSFWorkbook workbook = new XSSFWorkbook(_ssSampels.OpenResourceAsStream("sample.xlsx"));
     Assert.AreEqual(3, workbook.NumberOfSheets);
     Assert.AreEqual("Sheet1", workbook.GetSheetName(0));
     ISheet sheet = workbook.GetSheetAt(0);
     IRow row = sheet.GetRow(0);
     ICell cell = row.GetCell((short)1);
     Assert.IsNotNull(cell);
     Assert.AreEqual(111.0, cell.NumericCellValue, 0.0);
     cell = row.GetCell((short)0);
     Assert.AreEqual("Lorem", cell.RichStringCellValue.String);
 }
開發者ID:89sos98,項目名稱:npoi,代碼行數:13,代碼來源:TestLoadSaveXSSF.cs

示例2: ImportStudentPointExcel

    private string ImportStudentPointExcel(HttpPostedFile postedFile, string schoolNo, string banjiName, string examTime, string examType, string examName, List<StudentPointModel> newstudentPoints)
    {
        try
        {
            var ext = Path.GetExtension(postedFile.FileName);
            ISheet sheet;
            if (ext == ".xls")
            {
                //office 97-2003
                HSSFWorkbook wk = new HSSFWorkbook(postedFile.InputStream);
                sheet = wk.GetSheet(wk.GetSheetName(0));
            }
            else if (ext == ".xlsx")
            {
                //office 2007-now
                XSSFWorkbook wk = new XSSFWorkbook(postedFile.InputStream);
                sheet = wk.GetSheet(wk.GetSheetName(0));
            }
            else
            {
                return "請使用xls或xlsx格式";
            }

            if (sheet.LastRowNum < 1)
            {
                return "表內容不能為空";
            }

            Dictionary<string, int> rowName = new Dictionary<string, int>();
            IList<QueryModel> qmList = new List<QueryModel>();
            qmList.Add(MakeUtil.getQueryModel("SchoolNo", "'", SqlWhere.WhereOperator.Equal, schoolNo));
            if (banjiName != "")
            {
                qmList.Add(MakeUtil.getQueryModel("D_Name", "'", SqlWhere.WhereOperator.Equal, banjiName));
            }
            var students = _departStaffEbi.getModelList(qmList, -1);
            qmList.Clear();
            qmList.Add(MakeUtil.getQueryModel("SchoolNo", "'", SqlWhere.WhereOperator.Equal, schoolNo));
            if (banjiName != "")
            {
                qmList.Add(MakeUtil.getQueryModel("BanjiName", "'", SqlWhere.WhereOperator.Equal, banjiName));
            }
            qmList.Add(MakeUtil.getQueryModel("ExamType", "'", SqlWhere.WhereOperator.Equal, examType));
            qmList.Add(MakeUtil.getQueryModel("ExamName", "'", SqlWhere.WhereOperator.Equal, examName));
            var studentpoints = _studentPointEbi.getModelList(qmList, -1);

        //            if (sheet.LastRowNum > students.Count)
        //            {
        //                return "Excel的導入內容比學生人數多";
        //            }
            for (int j = 0; j <= sheet.LastRowNum; j++)  //LastRowNum 是當前表的總行數
            {
                IRow row = sheet.GetRow(j);  //讀取當前行數據
                //先讀取表頭信息
                if (j == 0)
                {
                    if (row != null)
                    {
                        for (int k = 0; k <= row.LastCellNum; k++) //LastCellNum 是當前行的總列數
                        {
                            ICell cell = row.GetCell(k); //當前表格
                            if (cell != null && cell.ToString() != "")
                            {
                                //獲取表頭信息
                                rowName.Add(cell.ToString(), k);
                            }
                        }
                    }
                }
                else
                {
                    if (row != null)
                    {
                        var banji = row.GetCell(rowName["班級名稱"]).ToString();
                        var xinming = row.GetCell(rowName["姓名"]).ToString();
                        var bianhao = row.GetCell(rowName["編號"]).ToString();
                        if (banjiName != "" && banji != banjiName)
                        {
                            return string.Format("Excel中的班級名稱有誤,你選擇了 {0} 這個班級,Excel中不應該再出現別的班級", banjiName);
                        }
                        //根據前四項找出學生的成績資料
                        if (!students.Any(p => p.D_Name == banji && p.DS_Name == xinming && p.DS_JID == bianhao))
                        {
                            return string.Format("在班級{2}中找不到姓名為{0}編號為{1}的學生", xinming, bianhao, banji);
                        }

                        //然後在excel表中如果有相關資料的話便導入
                        var studentpointList = studentpoints.Where(p => p.BanjiName == banji && p.XinMing == xinming && p.BianHao == bianhao);
                        if (studentpointList.Any())
                        {
                            var studentpoint = studentpointList.FirstOrDefault();
                            if (studentpoint.TempIsOld)
                            {
                                continue;
                            }
                            SetCellToStudentPoint(studentpoint, row, rowName);
                            studentpoint.TempIsOld = true;
                            newstudentPoints.Add(studentpoint);
                        }
                        else
//.........這裏部分代碼省略.........
開發者ID:jongking,項目名稱:XueXiaoWeiXin,代碼行數:101,代碼來源:Easy-Ajax-Post.aspx.cs


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