예제 #1
0
        public ISheet CreateSheet(string sheetname)
        {
            if (sheetname == null)
            {
                throw new ArgumentException("sheetName must not be null");
            }
            if (this.ContainsSheet(sheetname, this.sheets.Count))
            {
                throw new ArgumentException("The workbook already contains a sheet of this name");
            }
            if (sheetname.Length > 31)
            {
                sheetname = sheetname.Substring(0, 31);
            }
            WorkbookUtil.ValidateSheetName(sheetname);
            CT_Sheet ctSheet = this.AddSheet(sheetname);
            int      idx     = 1;

            foreach (XSSFSheet sheet in this.sheets)
            {
                idx = (int)Math.Max((long)(sheet.sheet.sheetId + 1U), (long)idx);
            }
            XSSFSheet relationship = (XSSFSheet)this.CreateRelationship((POIXMLRelation)XSSFRelation.WORKSHEET, (POIXMLFactory)XSSFFactory.GetInstance(), idx);

            relationship.sheet = ctSheet;
            ctSheet.id         = relationship.GetPackageRelationship().Id;
            ctSheet.sheetId    = (uint)idx;
            if (this.sheets.Count == 0)
            {
                relationship.IsSelected = true;
            }
            this.sheets.Add(relationship);
            return((ISheet)relationship);
        }
예제 #2
0
 public void SetSheetName(int sheetIndex, string sheetname)
 {
     this.ValidateSheetIndex(sheetIndex);
     if (sheetname != null && sheetname.Length > 31)
     {
         sheetname = sheetname.Substring(0, 31);
     }
     WorkbookUtil.ValidateSheetName(sheetname);
     if (this.ContainsSheet(sheetname, sheetIndex))
     {
         throw new ArgumentException("The workbook already contains a sheet of this name");
     }
     new XSSFFormulaUtils(this).UpdateSheetName(sheetIndex, sheetname);
     this.workbook.sheets.GetSheetArray(sheetIndex).name = sheetname;
 }
예제 #3
0
        /// <summary>
        /// 创建工作表
        /// </summary>
        /// <param name="name">工作表名</param>
        /// <returns></returns>
        public IWorkSheet CreateSheet(string name)
        {
            if (name == null)
            {
                throw new ArgumentException("sheetName must not null");
            }

            if (ContainsSheet(name, Sheets.Count))
            {
                throw new ArgumentException("The workbook already contains a sheet of this name");
            }

            if (name.Length > 31)
            {
                name = name.Substring(0, MaxSensitveSheetNameLength);
            }
            WorkbookUtil.ValidateSheetName(name);

            IWorkSheet sheet = new WorkSheet();

            sheet.SheetName = name;
            Sheets.Add(sheet);
            return(sheet);
        }