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


C# HSSFWorkbook.SetActiveSheet方法代码示例

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


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

示例1: TestSelectedSheetshort

        public void TestSelectedSheetshort()
        {
            HSSFWorkbook wb = new HSSFWorkbook();
            HSSFSheet sheet1 = (HSSFSheet)wb.CreateSheet("Sheet1");
            HSSFSheet sheet2 = (HSSFSheet)wb.CreateSheet("Sheet2");
            HSSFSheet sheet3 = (HSSFSheet)wb.CreateSheet("Sheet3");
            HSSFSheet sheet4 = (HSSFSheet)wb.CreateSheet("Sheet4");

            ConfirmActiveSelected(sheet1, true);
            ConfirmActiveSelected(sheet2, false);
            ConfirmActiveSelected(sheet3, false);
            ConfirmActiveSelected(sheet4, false);

            wb.SetSelectedTab((short)1);

            // see Javadoc, in this case selected means "active"
            Assert.AreEqual(wb.ActiveSheetIndex, (short)wb.ActiveSheetIndex);

            // Demonstrate bug 44525:
            // Well... not quite, since isActive + isSelected were also Added in the same bug fix
            if (sheet1.IsSelected)
            {
                //throw new AssertionFailedError("Identified bug 44523 a");
                Assert.Fail("Identified bug 44523 a");
            }
            wb.SetActiveSheet(1);
            if (sheet1.IsActive)
            {
                //throw new AssertionFailedError("Identified bug 44523 b");
                Assert.Fail("Identified bug 44523 b");
            }

            ConfirmActiveSelected(sheet1, false);
            ConfirmActiveSelected(sheet2, true);
            ConfirmActiveSelected(sheet3, false);
            ConfirmActiveSelected(sheet4, false);

            Assert.AreEqual(0, wb.FirstVisibleTab);
            //wb.DisplayedTab=((short)2);
            //Assert.AreEqual(2, wb.FirstVisibleTab);
            //Assert.AreEqual(2, wb.DisplayedTab);
        }
开发者ID:mdjasim,项目名称:npoi,代码行数:42,代码来源:TestHSSFWorkbook.cs

示例2: TestActiveSheetAfterDelete_bug40414

        public void TestActiveSheetAfterDelete_bug40414()
        {
            HSSFWorkbook wb = new HSSFWorkbook();
            NPOI.SS.UserModel.ISheet sheet0 = wb.CreateSheet("Sheet0");
            NPOI.SS.UserModel.ISheet sheet1 = wb.CreateSheet("Sheet1");
            NPOI.SS.UserModel.ISheet sheet2 = wb.CreateSheet("Sheet2");
            NPOI.SS.UserModel.ISheet sheet3 = wb.CreateSheet("Sheet3");
            NPOI.SS.UserModel.ISheet sheet4 = wb.CreateSheet("Sheet4");

            // Confirm default activation/selection
            ConfirmActiveSelected(sheet0, true);
            ConfirmActiveSelected(sheet1, false);
            ConfirmActiveSelected(sheet2, false);
            ConfirmActiveSelected(sheet3, false);
            ConfirmActiveSelected(sheet4, false);

            wb.SetActiveSheet(3);
            wb.SetSelectedTab(3);

            ConfirmActiveSelected(sheet0, false);
            ConfirmActiveSelected(sheet1, false);
            ConfirmActiveSelected(sheet2, false);
            ConfirmActiveSelected(sheet3, true);
            ConfirmActiveSelected(sheet4, false);

            wb.RemoveSheetAt(3);
            // after removing the only active/selected sheet, another should be active/selected in its place
            if (!sheet4.IsSelected)
            {
                throw new AssertionException("identified bug 40414 a");
            }
            if (!sheet4.IsActive)
            {
                throw new AssertionException("identified bug 40414 b");
            }

            ConfirmActiveSelected(sheet0, false);
            ConfirmActiveSelected(sheet1, false);
            ConfirmActiveSelected(sheet2, false);
            ConfirmActiveSelected(sheet4, true);

            sheet3 = sheet4; // re-align local vars in this Test case

            // Some more cases of removing sheets

            // Starting with a multiple selection, and different active sheet
            wb.SetSelectedTabs(new int[] { 1, 3, });
            wb.SetActiveSheet(2);
            ConfirmActiveSelected(sheet0, false, false);
            ConfirmActiveSelected(sheet1, false, true);
            ConfirmActiveSelected(sheet2, true, false);
            ConfirmActiveSelected(sheet3, false, true);

            // removing a sheet that is not active, and not the only selected sheet
            wb.RemoveSheetAt(3);
            ConfirmActiveSelected(sheet0, false, false);
            ConfirmActiveSelected(sheet1, false, true);
            ConfirmActiveSelected(sheet2, true, false);

            // removing the only selected sheet
            wb.RemoveSheetAt(1);
            ConfirmActiveSelected(sheet0, false, false);
            ConfirmActiveSelected(sheet2, true, true);

            // The last remaining sheet should always be active+selected
            wb.RemoveSheetAt(1);
            ConfirmActiveSelected(sheet0, true, true);
        }
开发者ID:mdjasim,项目名称:npoi,代码行数:68,代码来源:TestHSSFWorkbook.cs

示例3: TestSheetSelection

 public new void TestSheetSelection()
 {
     HSSFWorkbook b = new HSSFWorkbook();
     b.CreateSheet("Sheet One");
     b.CreateSheet("Sheet Two");
     b.SetActiveSheet(1);
     b.SetSelectedTab(1);
     b.FirstVisibleTab = (1);
     Assert.AreEqual(1, b.ActiveSheetIndex);
     Assert.AreEqual(1, b.FirstVisibleTab);
 }
开发者ID:mdjasim,项目名称:npoi,代码行数:11,代码来源:TestHSSFWorkbook.cs

示例4: TestSelectedSheet_bug44523

        public void TestSelectedSheet_bug44523()
        {
            HSSFWorkbook wb = new HSSFWorkbook();
            NPOI.SS.UserModel.ISheet sheet1 = wb.CreateSheet("Sheet1");
            NPOI.SS.UserModel.ISheet sheet2 = wb.CreateSheet("Sheet2");
            NPOI.SS.UserModel.ISheet sheet3 = wb.CreateSheet("Sheet3");
            NPOI.SS.UserModel.ISheet sheet4 = wb.CreateSheet("Sheet4");

            ConfirmActiveSelected(sheet1, true);
            ConfirmActiveSelected(sheet2, false);
            ConfirmActiveSelected(sheet3, false);
            ConfirmActiveSelected(sheet4, false);

            wb.SetSelectedTab(1);
            // see Javadoc, in this case selected means "active"
            Assert.AreEqual(wb.ActiveSheetIndex, (short)wb.ActiveSheetIndex);


            // Demonstrate bug 44525:
            // Well... not quite, since isActive + isSelected were also Added in the same bug fix
            if (sheet1.IsSelected)
            {
                throw new AssertionException("Identified bug 44523 a");
            }
            wb.SetActiveSheet(1);
            if (sheet1.IsActive)
            {
                throw new AssertionException("Identified bug 44523 b");
            }

            ConfirmActiveSelected(sheet1, false);
            ConfirmActiveSelected(sheet2, true);
            ConfirmActiveSelected(sheet3, false);
            ConfirmActiveSelected(sheet4, false);
        }
开发者ID:mdjasim,项目名称:npoi,代码行数:35,代码来源:TestHSSFWorkbook.cs

示例5: Template


//.........这里部分代码省略.........
                }
                if (propertyRowIndex > propertyFromIndex)
                {
                    var rName = workbook.CreateName();
                    rName.RefersToFormula = string.Format("'{0}'!$B${1}:$B${2}", supportSheetName, propertyFromIndex + 1, propertyRowIndex);
                    rName.NameName = tag.Name;
                }
                foreach (var property in propertyLinq.Where(p => p.C.Id == tag.Id))
                {
                    int valueFromIndex = propertyRowIndex;
                    foreach (var pvalue in _valueRepo.Get(b => b.Status != (int)DataStatus.Deleted && b.PropertyId == property.P.Id).Select(p => new { Id = p.Id, Name = p.ValueDesc }))
                    {
                        propertyRowIndex = supportFill(propertyRowIndex, pvalue);
                    }
                    if (propertyRowIndex > valueFromIndex)
                    {
                        var rName = workbook.CreateName();
                        rName.RefersToFormula = string.Format("'{0}'!$B${1}:$B${2}", supportSheetName, valueFromIndex + 1, propertyRowIndex);
                        rName.NameName = string.Format("{0}_{1}", property.C.Name, property.P.PropertyDesc);
                    }
                }
            }

            var moreheaderLabels = new Dictionary<string, dynamic>() { 
                {"商品代码",new {dataformat=0,width=10}},
                 {"属性名",new {dataformat=0,width=20}},
                 {"属性值",new {dataformat=0,width=10}}
                };
            var sheet2 = workbook.CreateSheet(moreInfoSheetName);
            var morerowFirst = sheet2.CreateRow(0);
            int moreCellIndex = 0;
            foreach (var key in moreheaderLabels.Keys)
            {
                var cell = morerowFirst.CreateCell(moreCellIndex);
                cell.SetCellType(CellType.STRING);
                cell.SetCellValue(key);
                cell.CellStyle = headerLabelCellStyle;
                sheet2.SetColumnWidth(moreCellIndex, moreheaderLabels[key].width * 255);

                var currentCellStyle = workbook.CreateCellStyle();
                currentCellStyle.DataFormat = (short)moreheaderLabels[key].dataformat;
                sheet2.SetDefaultColumnStyle(moreCellIndex, currentCellStyle);
                moreCellIndex++;

            }
            for (int i = 3; i <= 11; i++)
            {
                var cell = morerowFirst.CreateCell(i);
                cell.SetCellType(CellType.STRING);
                cell.SetCellValue(string.Empty);
                cell.CellStyle = headerLabelCellStyle;
                sheet2.SetColumnWidth(i, 10 * 255);
            
            }


            //set merge cell for last cell
            sheet2.AddMergedRegion(new CellRangeAddress(0, 0, 2, 11));
            //set constraint
            DVConstraint codeConstaint = DVConstraint.CreateFormulaListConstraint(string.Format("'{0}'!$A${1}:$A${2}", basicInfoSheetName, 2, 1000));
            CellRangeAddressList codeaddressList = new CellRangeAddressList(1, 1000, 0, 0);
            HSSFDataValidation codedataValidation = new HSSFDataValidation(codeaddressList, codeConstaint);
            codedataValidation.SuppressDropDownArrow = false;
            sheet2.AddValidationData(codedataValidation);



            for (int i = 1; i < 1000; i++)
            {
                //create hide helper cell
                sheet2.SetArrayFormula(string.Format("VLOOKUP($A${0},'{1}'!$A$1:$L$1000,7,FALSE)&\"_\"&$B${0}",i+1,basicInfoSheetName),
                            new CellRangeAddress(i,i,12,12));
                //create hide helper cell
                sheet2.SetArrayFormula(string.Format("VLOOKUP($A${0},'{1}'!$A$1:$L$1000,7,FALSE)", i + 1, basicInfoSheetName),
                            new CellRangeAddress(i, i, 13, 13));
                sheet2.SetColumnHidden(12, true);
                sheet2.SetColumnHidden(13, true);
                DVConstraint pConstaint = DVConstraint.CreateFormulaListConstraint(string.Format("INDIRECT($N${0})", i + 1)); // DVConstraint.CreateFormulaListConstraint(string.Format("'{0}'!$B${1}:$B${2}", supportSheetName, storeRowIndex + 1, propertyRowIndex));
                CellRangeAddressList paddressList = new CellRangeAddressList(i,i, 1, 1);
                HSSFDataValidation pdataValidation = new HSSFDataValidation(paddressList, pConstaint);
                pdataValidation.SuppressDropDownArrow = false;
                sheet2.AddValidationData(pdataValidation);
                //set constraint
                DVConstraint pvConstaint = DVConstraint.CreateFormulaListConstraint(string.Format("INDIRECT($M${0})", i + 1));
                CellRangeAddressList pvaddressList = new CellRangeAddressList(i, i, 2, 11);
                HSSFDataValidation pvdataValidation = new HSSFDataValidation(pvaddressList, pvConstaint);
                pvdataValidation.SuppressDropDownArrow = false;
                sheet2.AddValidationData(pvdataValidation);
            }


            workbook.SetActiveSheet(workbook.GetSheetIndex(sheet1));

            var ms = new MemoryStream();
            workbook.Write(ms);
            ms.Position = 0;
            var downloadName = tagId.HasValue ? string.Format("商品上传模版-{0}.xls", tagId.Value) : "商品上传模块.xls";
            return File(ms, "application/vnd.ms-excel", downloadName);

        }
开发者ID:huayumeng,项目名称:ytoo.service,代码行数:101,代码来源:ProBulkUploadController.cs


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