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


C# XSSFWorkbook.GetSheetAt方法代碼示例

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


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

示例1: TestBug48936

        public void TestBug48936()
        {
            IWorkbook w = new XSSFWorkbook();
            ISheet s = w.CreateSheet();
            int i = 0;
            List<String> lst = ReadStrings("48936-strings.txt");
            foreach (String str in lst)
            {
                s.CreateRow(i++).CreateCell(0).SetCellValue(str);
            }

            try
            {
                w = XSSFTestDataSamples.WriteOutAndReadBack(w);
            }
            catch (POIXMLException)
            {
                Assert.Fail("Detected Bug #48936");
            }
            s = w.GetSheetAt(0);
            i = 0;
            foreach (String str in lst)
            {
                String val = s.GetRow(i++).GetCell(0).StringCellValue;
                Assert.AreEqual(str, val);
            }
        }
開發者ID:myblindy,項目名稱:npoi,代碼行數:27,代碼來源:TestSharedStringsTable.cs

示例2: LoadPatternList

 private LoadPatternList()
 {
     using (FileStream fs = new FileStream(path,FileMode.Open,FileAccess.Read))
     {
         IWorkbook workbook = new XSSFWorkbook(fs);
         int sheetnumber = workbook.NumberOfSheets;
         int [][][] sheetelements = new int[sheetnumber][][];
         for(int sheetindex = 0;sheetindex < sheetnumber;++sheetindex){
             ISheet _isheet = workbook.GetSheetAt(sheetindex);
             int lastrownum = _isheet.LastRowNum;
             int [][] rowelements = new int[lastrownum+1][];
             for(int rowindex = _isheet.FirstRowNum;rowindex <= lastrownum;++rowindex){
                 IRow row = _isheet.GetRow(rowindex);
                 if(row == null)continue;
                 int lastcellnum = row.LastCellNum;
                 int[] cellelements = new int[lastcellnum+1];
                 for(int cellindex = row.FirstCellNum;cellindex < lastcellnum;++cellindex){
                     ICell cell = row.GetCell(cellindex);
                     if(cell != null){
                         cellelements[cellindex] = Convert.ToInt32(cell.ToString());
                     }
                 }
                 rowelements[rowindex] = cellelements;
             }
             sheetelements[sheetindex] = rowelements;
         }
         data = sheetelements;
     }
     if(data.Length > 0){
         checksign = "No";
     }
 }
開發者ID:BlackKeiichiro,項目名稱:NewDensanProject,代碼行數:32,代碼來源:LoadPatternList.cs

示例3: Read

        public string Read(string inFile)
        {
            var stream = File.OpenRead(inFile);
            var book = new XSSFWorkbook(stream);
            stream.Close();

            var sb = new StringBuilder();
            var sheet = book.GetSheetAt(0);
            int lastRowNum = sheet.LastRowNum;
            for (int r = 0; r <= lastRowNum; r++)
            {
                var datarow = sheet.GetRow(r);
                {
                    foreach (var cell in datarow.Cells)
                    {
                        switch (cell.CellType)
                        {
                            case CellType.Numeric:
                                sb.Append(cell.NumericCellValue.ToString() + "\t");
                                break;
                            case CellType.String:
                                sb.Append(cell.StringCellValue.Replace("\n", "") + "\t");
                                break;
                            default:
                                throw new Exception("?");
                        }
                    }
                    sb.Append("\r\n");
                }
            }
            return sb.ToString();
        }
開發者ID:shimitei,項目名稱:DotnetExcelExample,代碼行數:32,代碼來源:NPOI.cs

示例4: ExportExcel

 public ActionResult ExportExcel()
 {
     var data = this.rptRepository.All();
     string path = Server.MapPath("~/Templates/客戶資訊.xlsx");
     FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read);
     IWorkbook wb = new XSSFWorkbook(stream);
     stream.Close();
     ISheet sheet = wb.GetSheetAt(0);
     ICellStyle cs = sheet.GetRow(1).Cells[0].CellStyle;
     int Index = 1;
     foreach (var item in data)
     {
         IRow row = sheet.CreateRow(Index);
         CreateCell(item.客戶名稱, row, 0, cs);
         CreateCell(item.聯絡人數量.ToString(), row, 1, cs);
         CreateCell(item.客戶帳戶數量.ToString(), row, 2, cs);
         Index++;
     }
     string serverPath = @"D:/repot.xlsx";
     using (FileStream file = new FileStream(serverPath, FileMode.Create))
     {
         wb.Write(file);
         file.Close();
     }
     return File(serverPath, "application/excel","Report.xlsx");
 }
開發者ID:ken74114,項目名稱:homework,代碼行數:26,代碼來源:ReportController.cs

示例5: UpdateExcelData

        public static bool UpdateExcelData(string excelFilePath, string excelName)
        {
            XSSFWorkbook excelBook = new XSSFWorkbook(File.Open(excelFilePath, FileMode.Open));
            var sheet = excelBook.GetSheetAt(0);
            var headerRow = sheet.GetRow(0);
            //total columns
            int cellCount = headerRow.LastCellNum;
            //total rows
            int rowCount = sheet.LastRowNum;

            switch (excelName)
            {
                case Constant.Water:
                    UpdateWaterData(sheet, cellCount, rowCount);
                    break;
                case Constant.Air:
                    UpdateAirData(sheet, cellCount, rowCount);
                    break;
            }

            try
            {
                FileStream writefile = new FileStream("d:\\" + excelName + ".xlsx", FileMode.Create, FileAccess.Write);
                excelBook.Write(writefile);
                writefile.Close();
                return true;
            }
            catch
            {
                return false;
            }
        }
開發者ID:jasonLiu001,項目名稱:ExcelToJson,代碼行數:32,代碼來源:UpdateExcel.cs

示例6: GetFieldNames

        /// <summary>
        /// Gets the field names from a workbook and stores them in a list.
        /// </summary>
        /// <param name="fieldNames">list where field names will be stored</param>
        /// <param name="workbook">workbook from which field names will be extracted</param>
        public static void GetFieldNames(ImportData data, XSSFWorkbook workbook)
        {
            ISheet sheet = workbook.GetSheetAt(0);
            bool reading = true;
            int rindex = sheet.FirstRowNum;

            while (reading) {
                IRow row = sheet.GetRow(rindex);

                if (row != null) {
                    ICell cell = row.GetCell(0);

                    if (cell != null) {
                        string s = CellValueAsString(cell);

                        if (s != "" && s[0] == '[') {
                            for (int i = 0; i < row.LastCellNum; i++) {
                                s = CellValueAsString(row.GetCell(i)).TrimEnd(']').TrimStart('['); ;
                                data.fieldNames.Add(s);
                            }

                            // don't read more than one row of field names
                            reading = false;
                        }
                    }
                }

                rindex++;

                if (rindex > sheet.LastRowNum) {
                    reading = false;
                }
            }
        }
開發者ID:apsdsm,項目名稱:datahelpers,代碼行數:39,代碼來源:ExcelReader.cs

示例7: ImportFromSheet

        public Dictionary<DateTime, List<SaleParsed>> ImportFromSheet(string path, DateTime dateTime, IEnumerable<int> sheetNumbers, IEnumerable<GoodType> goodTypes, string producer)
        {
            this.goodTypes = goodTypes;
            this.producer = producer;
            var result = new Dictionary<DateTime, List<SaleParsed>>();

            using (var fs = File.OpenRead(path))
            {
                var workbook = new XSSFWorkbook(fs);

                foreach (var sNum in sheetNumbers)
                {
                    ISheet sheet = workbook.GetSheetAt(sNum);

                    var sales = ParseSales(sheet, dateTime);
                    foreach (var s in sales)
                    {
                        if (result.ContainsKey(s.Key))
                        {
                            result[s.Key].AddRange(s.Value);
                        }
                        else
                        {
                            result.Add(s.Key, s.Value);
                        }
                    }
                }
            }

            return result;
        }
開發者ID:rbilyi,項目名稱:InvoiceGenerator,代碼行數:31,代碼來源:ExcellImporter.cs

示例8: ReadExcelPattern

 public static int[][][] ReadExcelPattern(string filepath)
 {
     using (FileStream fs = new FileStream(filepath,FileMode.Open,FileAccess.Read))
     {
         IWorkbook workbook = new XSSFWorkbook(fs);
         int sheetnumber = workbook.NumberOfSheets;
         int [][][] sheetelements = new int[sheetnumber][][];
         for(int sheetindex = 0;sheetindex < sheetnumber;++sheetindex){
             ISheet _isheet = workbook.GetSheetAt(sheetindex);
             int lastrownum = _isheet.LastRowNum;
             int [][] rowelements = new int[lastrownum+1][];
             for(int rowindex = _isheet.FirstRowNum;rowindex <= lastrownum;++rowindex){
                 IRow row = _isheet.GetRow(rowindex);
                 if(row == null)continue;
                 int lastcellnum = row.LastCellNum;
                 int[] cellelements = new int[lastcellnum+1];
                 for(int cellindex = row.FirstCellNum;cellindex < lastcellnum;++cellindex){
                     ICell cell = row.GetCell(cellindex);
                     if(cell != null){
                         cellelements[cellindex] = Convert.ToInt32(cell.ToString());
                         Debug.Log(cellelements[cellindex]);
                     }
                 }
                 rowelements[rowindex] = cellelements;
             }
             sheetelements[sheetindex] = rowelements;
         }
         return sheetelements;
     }
 }
開發者ID:BlackKeiichiro,項目名稱:NewDensanProject,代碼行數:30,代碼來源:PatternLoad.cs

示例9: TestLoadStyles

 public void TestLoadStyles()
 {
     XSSFWorkbook workbook = new XSSFWorkbook(_ssSampels.OpenResourceAsStream("styles.xlsx"));
     ISheet sheet = workbook.GetSheetAt(0);
     IRow row = sheet.GetRow(0);
     ICell cell = row.GetCell((short)0);
     ICellStyle style = cell.CellStyle;
     // assertNotNull(style);
 }
開發者ID:89sos98,項目名稱:npoi,代碼行數:9,代碼來源:TestLoadSaveXSSF.cs

示例10: GetParsableRows

    /// <summary>
    /// Get the parsable rows from a workbook
    /// </summary>
    /// <param name="rows">a reference to an object that will contain parsable rows</param>
    /// <param name="workbook">the workbook to extract rows from</param>
    public static void GetParsableRows(ref List<ParsableRow> rows, XSSFWorkbook workbook) {

        ISheet sheet = workbook.GetSheetAt(0);

        bool reading = true;
        int rindex = sheet.FirstRowNum;

        while (reading) {
            IRow row = sheet.GetRow(rindex);

            // if there is a row, and it's not empty
            if (row != null && row.Cells.Count > 0) {

                // check to see if the row is parsable by looking at the first value
                ICell firstCell = row.GetCell(0);

                if (firstCell != null) {

                    string firstCellVal = CellValueAsString(firstCell);
                                        
                    // treat the row as parsable if it is:
                    // - not a title
                    // - not metadata
                    // - not a variable
                    if (firstCellVal[0] != '[' && firstCellVal[0] != '#' && firstCellVal[0] != '$') {

                        // cells are stored in parsable row objects
                        ParsableRow pr = new ParsableRow();

                        // copy the line number to the parsable row object
                        pr.linenumber = rindex;

						// make an array which is as long as the last cell number - note that NPOI will show cells **up to** the last cell that
						// contains data, so if a row in the sheet only has a single value in the fourth column, that row will return null for all
						// indices up to 2, then a value for index 3.
                        pr.cells = new string[row.LastCellNum];

                        // for each cell in the row, convert it to a string and copy it to the parsable row object
                        for (int i = 0; i < row.LastCellNum; i++) {
                            pr.cells[i] = CellValueAsString(row.GetCell(i));                   
                        }
                        
                        // add the parsable row object we just set up to the list of rows that was passed to the method
                        rows.Add(pr);
                    }
                }
            }

            rindex++;

            // check to make sure we're not out of bounds
            if (rindex > sheet.LastRowNum) {

                reading = false;
            }
        }
    }
開發者ID:apsdsm,項目名稱:spacegame,代碼行數:62,代碼來源:ExcelReader.cs

示例11: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {

           // LoadTemplate();


            //FileStream file = new FileStream(@"template/Astro2_Sys WHCK Status - 0712-SA2.xlsx", FileMode.Open, FileAccess.ReadWrite);
            FileStream file = new FileStream(@"template/Astro2_Sys WHCK Status - 0712-SA2.xlsx", FileMode.Open, FileAccess.ReadWrite);
            IWorkbook wb = new XSSFWorkbook(file);


            MessageBox.Show(wb.NumberOfSheets+"", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            if (wb.NumberOfSheets >= 2)
            {
                ISheet sheet1 = wb.GetSheetAt(1);

                sheet1.GetRow(7).GetCell(6).SetCellValue("Failed");

                //Write the stream data of workbook to the root directory
                //FileStream sw = new FileStream(@"test.xls", FileMode.Create);                
                FileStream sw = new FileStream(@"test.xls", FileMode.OpenOrCreate);
                wb.Write(file);
                sw.Close();

            }
            //create cell on rows, since rows do already exist,it's not necessary to create rows again.
         //   sheet1.GetRow(8).GetCell(7).SetCellValue("Failed");
            /*
            sheet1.GetRow(2).GetCell(1).SetCellValue(300);
            sheet1.GetRow(3).GetCell(1).SetCellValue(500050);
            sheet1.GetRow(4).GetCell(1).SetCellValue(8000);
            sheet1.GetRow(5).GetCell(1).SetCellValue(110);
            sheet1.GetRow(6).GetCell(1).SetCellValue(100);
            sheet1.GetRow(7).GetCell(1).SetCellValue(200);
            sheet1.GetRow(8).GetCell(1).SetCellValue(210);
            sheet1.GetRow(9).GetCell(1).SetCellValue(2300);
            sheet1.GetRow(10).GetCell(1).SetCellValue(240);
            sheet1.GetRow(11).GetCell(1).SetCellValue(180123);
            sheet1.GetRow(12).GetCell(1).SetCellValue(150);
             * */

            //Force excel to recalculate all the formula while open
            //sheet1.ForceFormulaRecalculation = true;

            
            //Response.AddHeader("Content-Disposition", string.Format("attachment; filename=EmptyWorkbook.xls"));
            //Response.BinaryWrite(ms.ToArray());
           // WriteToFile();
          


          //  wb = null;
            //ms.Close();
            //ms.Dispose();
        }
開發者ID:jhpeng,項目名稱:ExcelSample,代碼行數:55,代碼來源:Form1.cs

示例12: CreateLoadScriptableObject

    public static void CreateLoadScriptableObject()
    {
        string filepath = AssetDatabase.GetAssetPath(Selection.activeObject);
        string createpath = AssetDatabase.GenerateUniqueAssetPath("Assets/PartA/Resources/Pattern/" + Selection.activeObject.name +".asset");
        ExcelData exceldata = ScriptableObject.CreateInstance<ExcelData>();
        //List<_Row> _sheet_list = new List<_Row>();
        using (FileStream fs = new FileStream(filepath,FileMode.Open,FileAccess.Read))
        {
            IWorkbook workbook = new XSSFWorkbook(fs);
            int sheetnumber = workbook.NumberOfSheets;
            int [][][] sheetelements = new int[sheetnumber][][];
            exceldata.data = new int[sheetnumber][][];
            for(int sheetindex = 0;sheetindex < sheetnumber;++sheetindex){
                ISheet _isheet = workbook.GetSheetAt(sheetindex);
                int lastrownum = _isheet.LastRowNum;
                int [][] rowelements = new int[lastrownum + 1][];
                _Row localrow = new _Row();
                for(int rowindex = _isheet.FirstRowNum;rowindex <= lastrownum;++rowindex){
                    IRow row = _isheet.GetRow(rowindex);
                    if(row == null)continue;
                    int lastcellnum = row.LastCellNum;
                    int[] cellelements = new int[lastcellnum + 1];
                    _Cell localcell = new _Cell();
                    for(int cellindex = row.FirstCellNum;cellindex < lastcellnum;++cellindex){
                        ICell cell = row.GetCell(cellindex);
                        if(cell != null){
                            //cellelements[cellindex] = Convert.ToInt32(cell.ToString());
                            localcell.cell[cellindex] = Convert.ToInt32(cell.ToString());
                        }
                    }
                    localrow.row.Add(localcell);
                    rowelements[rowindex] = cellelements;
                }
                exceldata.sheet.Add(localrow);
                sheetelements[sheetindex] = rowelements;
            }

            //exceldata.data.CopyTo(sheetelements,0);
            //exceldata.data = (int[][][])sheetelements.Clone();
            foreach(_Row cells in  exceldata.sheet){
                foreach(_Cell test in cells.row){
                    for(int i = 0;i < 5;i++)
                    Debug.Log(test.cell[i]);
                }
            }
            //exceldata.data = sheetelements;
            exceldata.check = "Exist";
            exceldata.hideFlags = HideFlags.NotEditable;
            EditorUtility.SetDirty(exceldata);
            AssetDatabase.CreateAsset(exceldata,createpath);
            AssetDatabase.SaveAssets();
            EditorUtility.FocusProjectWindow();
        }
    }
開發者ID:BlackKeiichiro,項目名稱:NewDensanProject,代碼行數:54,代碼來源:LoadScriptableObject.cs

示例13: 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

示例14: TestCreate

        public void TestCreate()
        {
            XSSFWorkbook workbook = new XSSFWorkbook();
            XSSFSheet sheet = workbook.CreateSheet() as XSSFSheet;
            XSSFRow row = sheet.CreateRow(0) as XSSFRow;
            XSSFCreationHelper CreateHelper = workbook.GetCreationHelper() as XSSFCreationHelper;

            String[] urls = {
                "http://apache.org/",
                "www.apache.org",
                "/temp",
                "file:///c:/temp",
                "http://apache.org/default.php?s=isTramsformed&submit=Search&la=*&li=*"};
            for (int i = 0; i < urls.Length; i++)
            {
                String s = urls[i];
                XSSFHyperlink link = CreateHelper.CreateHyperlink(HyperlinkType.Url) as XSSFHyperlink;
                link.Address=(s);

                XSSFCell cell = row.CreateCell(i) as XSSFCell;
                cell.Hyperlink=(link);
            }
            workbook = XSSFTestDataSamples.WriteOutAndReadBack(workbook) as XSSFWorkbook;
            sheet = workbook.GetSheetAt(0) as XSSFSheet;
            PackageRelationshipCollection rels = sheet.GetPackagePart().Relationships;
            Assert.AreEqual(urls.Length, rels.Size);
            for (int i = 0; i < rels.Size; i++)
            {
                PackageRelationship rel = rels.GetRelationship(i);
                if (rel.TargetUri.IsAbsoluteUri&&rel.TargetUri.IsFile)
                    Assert.AreEqual(urls[i].Replace("file:///","").Replace("/","\\"),rel.TargetUri.LocalPath);
                else
                    // there should be a relationship for each URL
                    Assert.AreEqual(urls[i], rel.TargetUri.ToString());
            }

            // Bugzilla 53041: Hyperlink relations are duplicated when saving XSSF file
            workbook = XSSFTestDataSamples.WriteOutAndReadBack(workbook) as XSSFWorkbook;
            sheet = workbook.GetSheetAt(0) as XSSFSheet;
            rels = sheet.GetPackagePart().Relationships;
            Assert.AreEqual(urls.Length, rels.Size);
            for (int i = 0; i < rels.Size; i++)
            {
                PackageRelationship rel = rels.GetRelationship(i);
                if (rel.TargetUri.IsAbsoluteUri && rel.TargetUri.IsFile)
                    Assert.AreEqual(urls[i].Replace("file:///", "").Replace("/", "\\"), rel.TargetUri.LocalPath);
                else
                    // there should be a relationship for each URL
                    Assert.AreEqual(urls[i], rel.TargetUri.ToString());
            }
        }
開發者ID:Reinakumiko,項目名稱:npoi,代碼行數:51,代碼來源:TestXSSFHyperlink.cs

示例15: SetUp

 public void SetUp()
 {
     if (workbook == null)
     {
         Stream is1 = HSSFTestDataSamples.OpenSampleFileStream(SS.FILENAME);
         OPCPackage pkg = OPCPackage.Open(is1);
         workbook = new XSSFWorkbook(pkg);
         sheet = workbook.GetSheetAt(0);
     }
     _functionFailureCount = 0;
     _functionSuccessCount = 0;
     _EvaluationFailureCount = 0;
     _EvaluationSuccessCount = 0;
 }
開發者ID:89sos98,項目名稱:npoi,代碼行數:14,代碼來源:TestFormulaEvaluatorOnXSSF.cs


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